Skip to content

fix(cd): send correct DTO envelope for service/environment/infrastructure -f uploads/create#58

Merged
sawka-harness merged 2 commits into
mainfrom
fix/getting-started
Jul 17, 2026
Merged

fix(cd): send correct DTO envelope for service/environment/infrastructure -f uploads/create#58
sawka-harness merged 2 commits into
mainfrom
fix/getting-started

Conversation

@BlueLabelscotch

Copy link
Copy Markdown
Collaborator
image image

Problem

harness create/update service|environment|infrastructure -f <file>.yaml failed with:
API error 400: identifier: cannot be empty

The Harness servicesV2, environmentsV2, and infrastructures APIs don't accept
the plain resource YAML you'd export from Harness Studio (e.g. a bare service:
block). They require a DTO envelope instead: identity fields
(identifier, name, orgIdentifier, projectIdentifier, ...) at the top level,
plus the full resource YAML embedded as a string under a yaml key. The CLI's
-f file-body path was JSON-encoding the raw YAML and sending it as-is, so the API
saw no top-level identifier and rejected it.
Separately, create/update connector (and other nouns using
create_body_wrap/update_body_wrap, e.g. organization/project/secret) had a
latent double-wrap bug: if -f was given a file already wrapped in its top-level
key (e.g. a Studio export shaped as {"connector": {...}}), the CLI would wrap it
again into {"connector": {"connector": {...}}}.

Fix

  • Added a new spec option, file_body_yaml_envelope: <key>, and a buildYamlEnvelope
    helper in pkg/registry/endpoint.go that builds the API's required envelope from
    the -f file, handling all three shapes seen in real sample files: already an
    envelope (has yaml:), wrapped (e.g. service: block), or flat (no wrapper).
  • Wired file_body_yaml_envelope onto the six create/update endpoints for
    service, environment, and infrastructure in pkg/spec/cd.spec.yaml.
  • Added an unwrapIfAlreadyWrapped guard to the generic create_body_wrap/
    update_body_wrap file-body path so it detects an already-wrapped -f file and
    avoids double-wrapping (fixes the connector edge case and any other noun sharing
    this code path).

Testing

Verified live against a real Harness account:

  • harness update service <id> -f service.yml — previously 400, now succeeds.
  • harness update environment <id> -f environment.yml (flat shape) — succeeds.
  • harness update infrastructure <id> -f infrastructure-definition.yml (already
    envelope shape) — succeeds.
  • harness update connector <id> --set description=... — sanity-checked unaffected.

@sawka-harness
sawka-harness merged commit f8a1a39 into main Jul 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants