hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions

Home Page:https://developer.hashicorp.com/terraform/plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`schema.ResourceData.GetRaw<whatever>()` not populated during provider configuration

gdavison opened this issue · comments

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0

Relevant provider source code

provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
  	// ...
  	rawConfig := d.GetRawConfig()
	if rawConfig.IsKnown() {
		if rawConfig.IsNull() {
			fmt.Println("null config")
		}
	}

	rawPlan := d.GetRawPlan()
	if rawPlan.IsKnown() {
		if rawPlan.IsNull() {
			fmt.Println("null plan")
		}
	}

	rawState := d.GetRawState()
	if rawState.IsKnown() {
		if rawState.IsNull() {
			fmt.Println("null state")
		}
	}

}

Expected Behavior

The use case for using the Raw functions is to allow an empty string parameter in provider configs. To allow fallback behaviour to prevent a breaking change.

The traditional d.Get, d.GetOk, and d.GetOkExists functions do not make a distinction between an empty string and the value not being set.

Actual Behavior

The cty.Values returned by the GetRaw<whatever> functions are all Null

Looks like this RPC was never setup for those GetRaw* methods when that was originally added. Taking a quick peek it looks like it should be feasible, but it might be a little awkward implementation-wise in the SDK code.

Proposed fix: #1271 -- please give that a try and let us know if it resolves this issue. If so, we'll cut a bug fix release with it. Thanks!

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.