hashicorp/terraform · error

%s%s: all nested blocks within computed blocks must also be

Error message

%s%s: all nested blocks within computed blocks must also be computed

What it means

When a parent Block is Computed, every nested child block (BlockTypes entry) must also be Computed (checked at lines 69-70) - the mirror of rule 810 for nested blocks. A computed (provider-supplied) block cannot embed user-editable sub-blocks.

Source

Thrown at internal/configs/configschema/internal_validate.go:70

			continue
		}

		if _, isAttr := b.Attributes[name]; isAttr {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: name defined as both attribute and child block type", prefix, name))
		} else if !validName.MatchString(name) {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: name may contain only lowercase letters, digits and underscores", prefix, name))
		}
		if !blockS.Deprecated && blockS.DeprecationMessage != "" {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: DeprecationMessage must not be set when Deprecated is false", prefix, name))
		}

		if blockS.MinItems < 0 || blockS.MaxItems < 0 {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems must both be greater than zero", prefix, name))
		}

		// any nested blocks within a computed block must also be computed
		if b.Computed && !blockS.Computed {
			multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: all nested blocks within computed blocks must also be computed", prefix, name))
		}

		switch blockS.Nesting {
		case NestingSingle:
			switch {
			case blockS.MinItems != blockS.MaxItems:
				multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems must match in NestingSingle mode", prefix, name))
			case blockS.MinItems < 0 || blockS.MinItems > 1:
				multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems must be set to either 0 or 1 in NestingSingle mode", prefix, name))
			}
		case NestingGroup:
			if blockS.MinItems != 0 || blockS.MaxItems != 0 {
				multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: MinItems and MaxItems cannot be used in NestingGroup mode", prefix, name))
			}
			if blockS.Computed {
				multiErr = errors.Join(multiErr, fmt.Errorf("%s%s: NestingGroup blocks cannot be computed", prefix, name))
			}
		case NestingList, NestingSet:

View on GitHub (pinned to c9def3e214)

Solutions

  1. Set Computed=true on every nested block within a computed block.
  2. If the nested block must be user-editable, the parent cannot be Computed.

Example fix

// before
&configschema.Block{
    Computed: true,
    BlockTypes: map[string]*configschema.NestedBlock{
        "spec": {Nesting: configschema.NestingSingle, Block: configschema.Block{Computed: false}},
    },
}

// after
&configschema.Block{
    Computed: true,
    BlockTypes: map[string]*configschema.NestedBlock{
        "spec": {Nesting: configschema.NestingSingle, Block: configschema.Block{Computed: true}},
    },
}
Defensive patterns

Strategy: validation

Validate before calling

if block.Computed {
    for n, nb := range block.BlockTypes {
        if nb != nil && !nb.Computed { return fmt.Errorf("%s: nested block must be computed", n) }
    }
}

Prevention

When it happens

Trigger: Marking an outer block Computed=true while a nested block inside it stays Computed=false.

Common situations: Migrating a config object to a computed output, framework schema rewrites where inner blocks weren't updated.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/ada0526df9492848. Report an issue: GitHub.