Skip to content

feat(terraform): honor const values on array and map properties - #132

Open
AshGodfrey wants to merge 3 commits into
mainfrom
ash/const-container-properties
Open

AshGodfrey wants to merge 3 commits into
mainfrom
ash/const-container-properties

Conversation

@AshGodfrey

@AshGodfrey AshGodfrey commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Array and map properties that declare a const value were parsed as ordinary fields: the schema parser only attached const/default metadata to containers when a default was present. Terraform therefore exposed them as configurable attributes and sent whatever was in state instead of the const value. Scalar consts were already handled correctly.

  • Parser: attach const metadata to arrays, sets and maps behind two new Experimental features, constArrays and constObjects (declared for the Terraform target). Consts whose elements are not scalars, or consts on objects with properties, are dropped with a validation warning.
  • Go models: emit a const struct tag carrying the JSON encoding for container fields, render Go literals for their getters, and compare received const values structurally when unmarshaling so whitespace differences from the server do not fail decoding.
  • Terraform: no template change needed. The existing const handling already removes the field from the resource/data-source schema and skips it when building requests, so the SDK model injects the value.

Behavior change

For providers whose spec has const on an array or map property, the attribute is removed from the resource schema. Configs that set it will need the line removed. Prior state is unaffected: the plugin framework drops attributes the schema no longer has.

Testing

  • Parser unit tests for array and map consts, including feature-off and element-type-mismatch cases.
  • New ConstContainer entity in the review spec with an acceptance test asserting the request body carries [], ["read","write"], {} and {"max":10} while the config sets only name.
  • Full Terraform acceptance suite, make lint, and template type checks pass. Review Go, CLI and Terraform fixtures regenerated.

Summary by cubic

Fixes const values on array and map properties being parsed as configurable attributes, so Terraform sent whatever was in state instead of the const value. Consts on arrays, sets, and maps are now attached behind two new Experimental features, constArrays and constObjects, hidden from the resource schema, and injected into request bodies. Scalar consts were already handled correctly.

Behavior change

  • Attributes with container consts are removed from the resource schema; configs that set them must remove those lines.
  • Prior state is unaffected; the plugin framework drops attributes the schema no longer has.
  • Consts are dropped with a validation warning when their elements are non-scalar, items are nullable, or the container is an object with properties; uuid and duration items are now accepted.
  • Received const values are compared structurally with exact JSON number equality, so whitespace differences from the server do not fail decoding.
  • Container default and const metadata are gated independently, so a const cannot ride along on a target that only supports container defaults.

Written for commit 5bd87c0. Summary will update on new commits.

View guided diff Turn on auto-fix

Array and map properties that declare a const value were parsed as
ordinary fields: the schema parser only attached const/default
metadata to containers when a default was present. Terraform therefore
exposed them as configurable attributes and sent whatever was in state
instead of the const value.

- Parser: attach const metadata to arrays, sets and maps behind the new
  constArrays and constObjects features, and drop consts whose elements
  are not scalars with a validation warning.
- Go models: emit a const struct tag carrying the JSON encoding for
  container fields, render Go literals for their getters, and compare
  received const values structurally when unmarshaling.
- Terraform: declare the new features; the existing const handling
  already hides the fields from the resource schema and skips them when
  building requests, so the SDK model injects the value.

Regenerates the review Go, CLI and Terraform fixtures and adds a
ConstContainer entity with an acceptance test asserting the request
body.
@AshGodfrey
AshGodfrey requested a review from a team as a code owner October 22, 2026 10:02
@github-actions github-actions Bot added go Trigger (90) snapshot tests for go terraform Trigger (12) snapshot tests for terraform labels Oct 22, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 39 files

Confidence score: 4/5

  • In const_container.md, id is documented as read-only even though the schema requires it, which could lead users to omit a required field. Move id to Required and leave only name under Read-Only.
  • In handle_array_test.go, ArrayWithConstItemTypeMismatch would still pass if the required validation warning disappeared. Capture and assert the mismatch warning.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="zSDKs/terraform-provider-testing/docs/data-sources/const_container.md">

<violation number="1" location="zSDKs/terraform-provider-testing/docs/data-sources/const_container.md:24">
P2: `id` is required by `ConstContainerDataSource.Schema`, but this page documents it as read-only. Move `id` into a Required section and leave only `name` under Read-Only; otherwise users following the schema may omit an argument that Terraform rejects.</violation>
</file>

<file name="internal/schemas/handle_array_test.go">

<violation number="1" location="internal/schemas/handle_array_test.go:148">
P2: `ArrayWithConstItemTypeMismatch` verifies only that the const is omitted, so it would still pass if the required validation warning were removed or suppressed. Capture warnings for this case and assert the mismatch warning as well as the AST result.</violation>
</file>

Shadow auto-approve: would not auto-approve because issues were found.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread templates/templates/common/go/sanitization.ts
Comment thread internal/schemas/schemas.go Outdated
Comment thread internal/schemas/schemas.go Outdated
Comment thread zSDKs/terraform-provider-testing/internal/sdk/internal/utils/json.go Outdated
Comment thread internal/schemas/handle_array_test.go
Comment thread zSDKs/sdk-cli/internal/sdk/sdkinternal/utils/json.go Outdated
Comment thread .changesets/1792662097-2435dcc7.yaml
- Gate container default and const metadata independently so a const
  cannot ride along on a target that only supports container defaults.
- Reject consts on containers with nullable items, whose Go element
  type is a pointer the const renderer does not produce.
- Accept uuid and duration items in container consts.
- Compare received const values with exact JSON numbers instead of
  float64.
- Record the cli target on the Go runtime changeset.
@speakeasy-generator-bot

speakeasy-generator-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Generator Snapshot Testing

Selector(s) Result Summary
snapshot-go, snapshot-terraform ✅ Snapshot run completed

Snapshot results: https://github.com/speakeasy-api/openapi-generation-snapshots/issues/129#issuecomment-6345678600

Snapshot results are summarized above. Additional run context is linked for maintainers with access.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 10 files (changes from recent commits).

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Container consts for arrays/maps are now honored behind new experimental constArrays/constObjects feature gates, with guards for unsupported cases and acceptance tests covering emitted schemas and request bodies. Focused, tested bug fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Trigger (90) snapshot tests for go terraform Trigger (12) snapshot tests for terraform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant