Skip to content

feat: add dynamic attribute support for self-referential schemas - #3

Draft
claude[bot] wants to merge 1 commit into
mainfrom
bb/add-dynamic-attribute-support
Draft

feat: add dynamic attribute support for self-referential schemas#3
claude[bot] wants to merge 1 commit into
mainfrom
bb/add-dynamic-attribute-support

Conversation

@claude

@claude claude Bot commented Jul 29, 2026

Copy link
Copy Markdown

Requested by Brady Burke · Slack thread

Before / After

Before: This fork of terraform-plugin-codegen-framework had no support for the dynamic attribute type. Feeding it a provider-code-spec that contained a dynamic attribute would fail with attribute type not defined, because there was no generator wired up for it.

After: The framework recognizes dynamic attributes in the spec and generates the corresponding schema.DynamicAttribute{...} plus the matching types.Dynamic model field, for resources, data sources, and providers. This lets the generator consume specs that represent a self-referential schema edge as a dynamic attribute (see the companion OpenAPI-codegen PR linked below) and emit compiling Go provider code.

How

  • New GeneratorDynamicAttribute in internal/resource, internal/datasource, and internal/provider, mirroring the existing scalar (bool) generators: Schema() emits schema.DynamicAttribute{...}, ModelField() emits a types.Dynamic field, plus Imports, Equal, AttrType/AttrValue.
  • Dispatch: added an a.Dynamic != nil case to NewAttribute in each of the three convert.go files.
  • Supporting wiring: GeneratorDynamicAttribute value added to the schema.Type enum, DynamicValueType = "types.Dynamic" added to internal/model, and Dynamic entries added to the PlanModifierType / ValidatorType enums so custom plan modifiers/validators for dynamic attributes resolve correctly.
  • Regression tests for the resource generator (New, Schema, ModelField).

Known scope limit: AssociatedExternalType/custom-type rendering and spec-level default for dynamic attributes are not emitted (the upstream self-referential use case never sets them); this can be extended later if needed.

Cross-dependency

This PR pairs with the OpenAPI-codegen change that first emits dynamic attributes for self-referential schemas — companion PR: starburstdata/terraform-plugin-codegen-openapi#2. Both are required for the end-to-end codegen pipeline to succeed on the recursive ingest_column schema.

go build ./... and go test ./internal/... pass (including the new dynamic tests; the existing golden-file internal/cmd tests are unaffected).


Generated by Claude Code

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.

1 participant