hashicorp/terraform · error
%q attribute is read-only
Error message
%q attribute is read-only
What it means
Returned by validateDataStoreResourceConfig at resource_data.go:89 when validating a terraform_data data resource. Core does not currently reject computed attributes set in config, so this provider explicitly checks the 'id' and 'output' attributes and reports each as read-only. 'output' is the computed result of terraform_data and 'id' is its computed identity; neither may be supplied by the user.
Source
Thrown at internal/builtin/providers/terraform/resource_data.go:89
Description: "The unique identifier for the data store.",
Required: true,
},
},
Nesting: configschema.NestingSingle,
},
}
}
func validateDataStoreResourceConfig(req providers.ValidateResourceConfigRequest) (resp providers.ValidateResourceConfigResponse) {
if req.Config.IsNull() {
return resp
}
// Core does not currently validate computed values are not set in the
// configuration.
for _, attr := range []string{"id", "output"} {
if !req.Config.GetAttr(attr).IsNull() {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf(`%q attribute is read-only`, attr))
}
}
return resp
}
func upgradeDataStoreResourceState(req providers.UpgradeResourceStateRequest) (resp providers.UpgradeResourceStateResponse) {
// We've only added new nullable block attributes, so unmarshaling from json
// will complete the data structure correctly.
val, err := ctyjson.Unmarshal(req.RawStateJSON, dataStoreResourceSchema().Body.ImpliedType())
if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err)
return resp
}
resp.UpgradedState = val
return resp
}
View on GitHub (pinned to c9def3e214)
Solutions
- Remove the id and/or output attributes from the data "terraform_data" block; both are computed.
- If you need to pass input, use the input attribute (arbitrary value) of terraform_data.
Example fix
// before
data "terraform_data" "example" {
input = local.value
id = "fixed-id"
}
// after
data "terraform_data" "example" {
input = local.value
} Defensive patterns
Strategy: validation
Validate before calling
// Before applying, lint terraform_data blocks for settable computed attrs.
var dataBlocks []cty.Value // parsed config blocks of terraform_data
readOnly := map[string]bool{"id": true, "output": true}
for _, b := range dataBlocks {
for attr := range readOnly {
if v := b.GetAttr(attr); !v.IsNull() {
return fmt.Errorf("terraform_data: %q is read-only", attr)
}
}
} Prevention
- Treat terraform_data like a passthrough: only set 'input'.
- Add a terraform validate step to CI to catch read-only attribute errors before apply.
When it happens
Trigger: A terraform_data block whose body sets output = ... or id = ... (e.g. data "terraform_data" "x" { id = "abc" }).
Common situations: Copy-pasting a managed-resource pattern into terraform_data; trying to feed a known output back in; assuming id is settable like on some resources.
Related errors
- Cannot set both 'source' and 'content'
- Must provide one of 'source' or 'content'
- source and content cannot both be null
- invalid null string in 'scripts'
- invalid empty string in 'scripts'
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/51522a69f8ba4fb1.
Report an issue: GitHub.