Skip to content

cloudflare_worker builds block rejected: OpenAPI spec generates SingleNestedAttribute instead of SingleNestedBlock #6974

@trafgals

Description

@trafgals

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:

  • builds
  • observability
  • subdomain

Also affected in other resources (e.g., cloudflare_magic_wan_gre_tunnel):

  • bgp
  • gre_tunnel
  • modified_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


Affected Version: v1.0.59 (and likely all versions)
Provider Source: trafgals/cloudflare (community fork)
Original Provider: cloudflare/terraform-provider-cloudflare

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions