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

[dynamic] send an empty config on destroy calls #2815

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

iwahbe
Copy link
Member

@iwahbe iwahbe commented Jan 7, 2025

Similar to pulumi/pulumi-terraform-provider#36, older versions of terraform-plugin-sdk/v2 require an empty (non-nil) req.Config field to avoid crashing.

	configVal, err := msgpack.Unmarshal(req.Config.MsgPack, schemaBlock.ImpliedType())
	if err != nil {
		resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, err)
		return resp, nil
	}

(src)

Newer versions of SDKv2 add a guard before this line is reached.

Fixes pulumi/pulumi-terraform-provider#55

@iwahbe iwahbe requested review from VenelinMartinov and a team January 7, 2025 15:45
Copy link
Contributor

@VenelinMartinov VenelinMartinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Would be great if we can turn the test into an integration test with pulumiTest but I do not know if we have logs for that.

// TestConfigInDestroy asserts that a nil config is passed to SDKv2 providers on destroy.
//
// This acts as a regression test for https://github.com/pulumi/pulumi-terraform-provider/issues/55.
func TestConfigInDestroy(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we turn this into an integration test using pulumiTest?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably possible to turn this into an integration test with our existing logs, but it would require a lot of messaging of log data. I took a crack at it, and it's a pretty painful process.

I don't think this will get us to a more flexible test here, since we are still log dependent.

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.65%. Comparing base (2150faf) to head (1ef41e9).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2815      +/-   ##
==========================================
+ Coverage   68.63%   68.65%   +0.02%     
==========================================
  Files         325      325              
  Lines       41536    41537       +1     
==========================================
+ Hits        28507    28516       +9     
+ Misses      11423    11418       -5     
+ Partials     1606     1603       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Similar to pulumi/pulumi-terraform-provider#36, older versions
of terraform-plugin-sdk/v2 require an empty (non-nil) `config` field to avoid crashing.

```go
	configVal, err := msgpack.Unmarshal(req.Config.MsgPack, schemaBlock.ImpliedType())
	if err != nil {
		resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, err)
		return resp, nil
	}
```

([src](https://github.com/pulumi/terraform-plugin-sdk/blob/1798ae4ae71f7ffff29312a07c92d41205aff03b/helper/schema/grpc_provider.go#L926-L930))

Newer versions of SDKv2 add a
[guard](https://github.com/pulumi/terraform-plugin-sdk/blob/da29621efae69dd03dfdc540aa5f63beab1b764c/helper/schema/grpc_provider.go#L810-L822)
before this line is reached.

Fixes #55
@iwahbe iwahbe force-pushed the iwahbe/dynamic-send-empty-config-on-destroy branch from 1e779b3 to 1ef41e9 Compare January 7, 2025 16:03
@iwahbe iwahbe merged commit a0d0562 into master Jan 8, 2025
17 checks passed
@iwahbe iwahbe deleted the iwahbe/dynamic-send-empty-config-on-destroy branch January 8, 2025 11:50
iwahbe added a commit that referenced this pull request Jan 8, 2025
This was motivated while trying to add a test for
#2815. Beyond adding comments, the
major change is how the failure for differences in nested fields looks. It used to look
like this:

```console
go test -test.run \^TestConfigInDestroy\$
panic: fatal: An assertion has failed: field config does not match logged field \
	&{{} [] [] 0x14000410008} != &{{} [] [] 0x14000410008}
```

Observe that both sides of the `!=` are identical.

It now looks like this:

```console
$ go test -test.run \^TestConfigInDestroy\$
panic: fatal: An assertion has failed: field "terraformv6_pulumi config msgpack" does not match logged field \
	[134 83 71 ...] != [134 82 69 ...]
```

The path to the nested field is specified (`"terraformv6_pulumi config msgpack"`) and we
see a difference in the value displayed.
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.100.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provider crashing on resource destroy
3 participants