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

Inconsistencies between ResourceData.GetRaw...() and ResourceDiff.GetRaw...() #1023

Closed
gdavison opened this issue Aug 9, 2022 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@gdavison
Copy link
Contributor

gdavison commented Aug 9, 2022

SDK version

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

Relevant provider source code

func ResourceEntityRecognizer() *schema.Resource {
	return &schema.Resource{
		...

		Schema: map[string]*schema.Schema{
			...
			"version_name": {
				Type:     schema.TypeString,
				Optional: true,
				Computed: true,
				DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
					...
				},
			},
			...
		},

		CustomizeDiff: customdiff.All(
			...
			func(_ context.Context, diff *schema.ResourceDiff, _ interface{}) error {
				...
			},
		),
	}
}

Terraform Configuration Files

Before:

resource "aws_comprehend_entity_recognizer" "example" {
  version_name = "value"
  ...
}

After:

resource "aws_comprehend_entity_recognizer" "example" {
  version_name = ""
  ...
}

Expected Behavior

Setting version_name = "" will cause both ResourceData.GetRawConfig().GetAttr("version_name") and ResourceDiff.GetRawConfig().GetAttr("version_name") to have the value ""

Actual Behavior

In the CustomizeDiffFunc, ResourceDiff.GetRawConfig().GetAttr("version_name") has the value "value".

In the Update function, ResourceData.GetRawConfig().GetAttr("version_name") has the value "".

References

I assume this is related to how Optional & Computed do not show a diff.

@bflad
Copy link
Member

bflad commented Aug 10, 2022

My understanding with the old internals of the sdk is that the cty value handling (Raw* fields) is more of a resource-level thing than affected by any attributes. Those cty values are fetched early on when an RPC is received and just need to be appropriately propagated through the internal logic to where they get surfaced to provider developers.

In my quick initial investigation, I was able to find one place where the cty values were not being copied as expected: #1024 -- can you see if that branch helps resolve your issue?

@bflad
Copy link
Member

bflad commented Aug 26, 2022

Hey @gdavison 👋 Is there any improvement with using v2.21.0? If not, we'll need to figure out other potential places where the data is not being appropriately copied.

@bflad bflad added the waiting-response An issue/pull request is waiting for a response from the community label Aug 26, 2022
@bflad bflad self-assigned this Aug 26, 2022
@bflad
Copy link
Member

bflad commented Nov 2, 2023

Closing due to lack of response. Please reach out if this is still an issue.

@bflad bflad closed this as completed Nov 2, 2023
@github-actions github-actions bot removed the waiting-response An issue/pull request is waiting for a response from the community label Nov 2, 2023
Copy link

github-actions bot commented Dec 3, 2023

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 Dec 3, 2023
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

No branches or pull requests

2 participants