-
Couldn't load subscription status.
- Fork 11
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Module version
github.com/hashicorp/terraform-plugin-framework v1.3.2 Relevant provider source code
The attr_settings attribute has been incorrectly defined as it is using a Default, but it has not been specified as Computed.
func (r *exampleResource) Schema(ctx context.Context, request resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ "attr_settings": schema.BoolAttribute{ Optional: true, Default: booldefault.StaticBool(true), }, "id": schema.StringAttribute{ Computed: true, PlanModifiers: []planmodifier.String{ stringplanmodifier.UseStateForUnknown(), }, }, }, } }Terraform Configuration Files
resource "playground_example" "example" { } Debug Output
https://gist.github.com/bendbennett/8df62591b5f7d83a3b60ba2414b7cc26
The lines of interest are:
2023-07-12T14:21:44.225+0100 [TRACE] provider.terraform-provider-playground: Getting provider schema: tf_mux_provider=*schema.GRPCProviderServer tf_req_id=9ac1ac91-3f8a-68a7-0919-7bc2d9ea80de tf_rpc=GetProviderSchema @caller=/Users/bdb/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.26.1/helper/schema/grpc_provider.go:70 @module=sdk.helper_schema tf_provider_addr=registry.terraform.io/bendbennett/playground timestamp=2023-07-12T14:21:44.225+0100 2023-07-12T14:21:44.225+0100 [TRACE] provider.terraform-provider-playground: Received downstream response: tf_provider_addr=registry.terraform.io/bendbennett/playground tf_rpc=GetProviderSchema @module=sdk.proto diagnostic_warning_count=0 tf_proto_version=5.3 tf_req_duration_ms=1 tf_req_id=9ac1ac91-3f8a-68a7-0919-7bc2d9ea80de @caller=/Users/bdb/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.17.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 diagnostic_error_count=0 timestamp=2023-07-12T14:21:44.225+0100Specifically, diagnostic_error_count=0 .
Running a debugger, it can be seen that the relevant diagnostic is added in (*Server).ResourceSchemas().
Expected Behavior
CLI surfaces diagnostic relating to a default being using on an attribute that is not computed:
Schema Using Attribute Default For Non-Computed Attribute Actual Behavior
The CLI displays the following message:
│ Error: Invalid resource type │ │ on resource.tf line 9, in resource "playground_example" "example": │ 9: resource "playground_example" "example" { Steps to Reproduce
- Define a default on a non-computed attribute
- Run terraform apply
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working