{"record":{"id":"51522a69f8ba4fb1","repo":"hashicorp/terraform","slug":"q-attribute-is-read-only","errorCode":null,"errorMessage":"%q attribute is read-only","messagePattern":"%q attribute is read-only","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/builtin/providers/terraform/resource_data.go","lineNumber":89,"sourceCode":"\t\t\t\t\tDescription: \"The unique identifier for the data store.\",\n\t\t\t\t\tRequired:    true,\n\t\t\t\t},\n\t\t\t},\n\t\t\tNesting: configschema.NestingSingle,\n\t\t},\n\t}\n}\n\nfunc validateDataStoreResourceConfig(req providers.ValidateResourceConfigRequest) (resp providers.ValidateResourceConfigResponse) {\n\tif req.Config.IsNull() {\n\t\treturn resp\n\t}\n\n\t// Core does not currently validate computed values are not set in the\n\t// configuration.\n\tfor _, attr := range []string{\"id\", \"output\"} {\n\t\tif !req.Config.GetAttr(attr).IsNull() {\n\t\t\tresp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf(`%q attribute is read-only`, attr))\n\t\t}\n\t}\n\treturn resp\n}\n\nfunc upgradeDataStoreResourceState(req providers.UpgradeResourceStateRequest) (resp providers.UpgradeResourceStateResponse) {\n\t// We've only added new nullable block attributes, so unmarshaling from json\n\t// will complete the data structure correctly.\n\tval, err := ctyjson.Unmarshal(req.RawStateJSON, dataStoreResourceSchema().Body.ImpliedType())\n\tif err != nil {\n\t\tresp.Diagnostics = resp.Diagnostics.Append(err)\n\t\treturn resp\n\t}\n\n\tresp.UpgradedState = val\n\treturn resp\n}\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/builtin/providers/terraform/resource_data.go#L71-L107","documentation":"The terraform_data resource's config validator rejects any attempt to set the 'id' or 'output' attributes in HCL configuration. Both attributes are declared Computed in the schema (resource_data.go:22,30), meaning they are provider-managed outputs, not user inputs. Because Terraform Core does not currently enforce 'do not set computed attributes in config', this provider performs the check manually.","triggerScenarios":"Calling validateDataStoreResourceConfig (resource_data.go:80-93) when req.Config has a non-null value for either 'id' or 'output'. This happens when a user writes `resource \"terraform_data\" \"x\" { id = \"...\" }` or `output = \"...\"` in their HCL.","commonSituations":"Copying an imported resource's ID back into the configuration block. Attempting to pre-set the output value of a terraform_data resource. Misunderstanding the Computed semantics and trying to supply these as inputs.","solutions":["Remove the 'id' and 'output' attributes from your terraform_data resource configuration blocks.","Use the 'input' attribute for providing values to terraform_data; 'output' will reflect 'input' after apply.","If you need to import a terraform_data resource, use `terraform import` and let the provider manage the ID."],"exampleFix":"# before\nresource \"terraform_data\" \"example\" {\n  id     = \"my-id\"\n  output = \"some-value\"\n  input  = \"hello\"\n}\n\n# after — id and output are read-only\nresource \"terraform_data\" \"example\" {\n  input = \"hello\"\n}","handlingStrategy":"validation","validationCode":"# In HCL, do not set computed attributes:\n// Before applying, verify no computed attributes are in config\nfor _, attr := range []string{\"id\", \"output\"} {\n    if !config.GetAttr(attr).IsNull() {\n        return fmt.Errorf(\"%q is computed and cannot be set in configuration\", attr)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set 'id' or 'output' in a terraform_data resource block — both are Computed.","Use 'terraform import' to bring existing terraform_data resources under management rather than hardcoding IDs.","Rely on the 'input' attribute for providing values; 'output' is automatically derived."],"tags":["terraform","terraform-data","computed-attributes","validation","hcl"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}