Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error diagnostics are not surfaced in the CLI when default is used for non-computed attribute #176

Closed
bendbennett opened this issue Jul 12, 2023 · 1 comment · Fixed by #177
Labels
bug Something isn't working

Comments

@bendbennett
Copy link
Contributor

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+0100

Specifically, 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
@bendbennett bendbennett added the bug Something isn't working label Jul 12, 2023
@bendbennett bendbennett transferred this issue from hashicorp/terraform-plugin-framework Jul 13, 2023
bendbennett added a commit that referenced this issue Jul 13, 2023
bendbennett added a commit that referenced this issue Jul 13, 2023
bendbennett added a commit that referenced this issue Jul 14, 2023
…177)

* Adding diagnostics returned from server.GetProviderSchema() to the diagnostics in the GetProviderSchemaResponse (#176)

* Adding changelog entries (#176)

* Refactoring to use TestServer.GetProviderSchemaResponse field (#176)
bendbennett added a commit that referenced this issue Jul 14, 2023
bendbennett added a commit that referenced this issue Jul 14, 2023
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant