-
Notifications
You must be signed in to change notification settings - Fork 808
Description
Bug Description
The builds block in cloudflare_worker resource (and similar blocks like observability, subdomain) are rejected by terraform with error:
Blocks of type 'builds' are not expected here. Did you mean to define argument 'builds'?
Root Cause
The OpenAPI spec → Stainless codegen generates SingleNestedAttribute (in Attributes: map) for these nested structures, but terraform-plugin-framework requires SingleNestedBlock (in Blocks: map) for block syntax.
When SingleNestedAttribute has Computed: true, Optional: true, terraform rejects block syntax and suggests using = assignment instead.
Affected Blocks
All of these have the same issue in cloudflare_worker:
buildsobservabilitysubdomain
Also affected in other resources (e.g., cloudflare_magic_wan_gre_tunnel):
bgpgre_tunnelmodified_gre_tunnel
Schema Comparison
Working example (cloudflare_magic_wan_gre_tunnel bgp block - though actually also broken):
// Current (broken): uses Attributes map
Attributes: map[string]schema.Attribute{
"bgp": schema.SingleNestedAttribute{
Optional: true,
Attributes: map[string]schema.Attribute{...},
},
}Expected fix (what it should be):
// Fixed: uses Blocks map with SingleNestedBlock
Blocks: map[string]schema.Block{
"bgp": schema.SingleNestedBlock{
Optional: true,
NestedBlockObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{...},
},
},
}Terraform Error Details
Error: Unsupported block type
on main.tf line 15, in resource "cloudflare_worker" "test":
15: builds {
Blocks of type "builds" are not expected here. Did you mean to define argument "builds"?
Expected Behavior
Users should be able to define builds using block syntax:
resource "cloudflare_worker" "example" {
builds {
enabled = true
main = "./src/index.ts"
}
}Suggested Fix
The OpenAPI spec or Stainless codegen should generate SingleNestedBlock with Blocks: map instead of SingleNestedAttribute with Attributes: map for these nested structures.
Alternatively, the schema could be manually corrected in the provider, but changes would need to be maintained alongside the codegen.
References
- terraform-plugin-framework issue Cloudflare Terraform provider crash: incorrect include rule type "github" (API returns "github-organization") #1075: "Optional SingleNestedAttribute not treated as optional if nested attributes are required"
- terraform-plugin-framework issue cache_key_fields not working as expected #740: "Allow Optional SingleNestedBlocks and Required Attributes within"
- Hashicorp docs suggest using
SingleNestedBlockfor blocks: https://developer.hashicorp.com/terraform/plugin/framework/handling-data/blocks/single-nested
Affected Version: v1.0.59 (and likely all versions)
Provider Source: trafgals/cloudflare (community fork)
Original Provider: cloudflare/terraform-provider-cloudflare