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

Use OpenTofu planner with Plugin Framework providers #2188

Merged
merged 31 commits into from
Jul 26, 2024

Conversation

t0yv0
Copy link
Member

@t0yv0 t0yv0 commented Jul 16, 2024

OpenTofu planner code is now used with Plugin Framework providers to emulate Terraform CLI behavior for objchange.ProposedNew. Note that this code was already in use for SDKv2-based resources prior to the change. The vendored code replaces a custom implementation that is now removed.

Fixes #2172

Observable changes: Plugin Framework based resources may now reorder outputs for Set collections.

This change is known to fix bugs such as #2192 - to be confirmed with a regression test in a follow-up PR.

@t0yv0
Copy link
Member Author

t0yv0 commented Jul 24, 2024

So looks like I was misled on this change https://github.com/pulumi/pulumi-terraform-bridge/pull/2060/files#diff-4f84cec74d4ce22a6ead8a99011c4a9d47bbed3b56a5e7382b12aeda28cf05e6R78 @VenelinMartinov - the branching is not present in OpenTOFU sources. So re-vendoring the code from OpenTOFU now leads to failing tests. That's not a good state to be in.

@t0yv0 t0yv0 force-pushed the t0yv0/remove-custom-objchange branch from 8a39d89 to 15dbda0 Compare July 25, 2024 16:58
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

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

I'd feel more comfortable if the vendored code lived in a pkg/vendor directory, just so it's clearer which code is vendored.

Can you add to the README.mds why each package is vendored? In general, I'm not super comfortable dropping down to vendored code unless we absolutely need to. I'd like to make sure that if we do need to do so, we have the reasons clearly listed so we know what we need to do to go back to standard go modules.

@t0yv0
Copy link
Member Author

t0yv0 commented Jul 25, 2024

vendor has a special meaning in Go tooling and activates that handling which I couldn't quite figure out. I can look into renaming it to vendored or something similar.

@iwahbe
Copy link
Member

iwahbe commented Jul 25, 2024

vendor has a special meaning in Go tooling and activates that handling which I couldn't quite figure out. I can look into renaming it to vendored or something similar.

🤦 Of course it does. vendored works just as well for my purposes.

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 15.71429% with 354 lines in your changes missing coverage. Please review.

Project coverage is 56.66%. Comparing base (59fe4bf) to head (3f907fb).
Report is 1 commits behind head on master.

Files Patch % Lines
pkg/vendored/opentofu/convert/schema.go 0.00% 212 Missing ⚠️
...ed/terraform-plugin-go/tfprotov6/toproto/schema.go 0.00% 83 Missing ⚠️
pf/internal/pfutils/convert_rschema_to_proto.go 57.77% 15 Missing and 4 partials ⚠️
...aform-plugin-go/tfprotov6/toproto/dynamic_value.go 0.00% 17 Missing ⚠️
pf/internal/pfutils/proposed_new.go 70.00% 7 Missing and 5 partials ⚠️
pf/internal/pfutils/schema.go 66.66% 6 Missing ⚠️
pf/proto/runtypes.go 0.00% 3 Missing ⚠️
...rraform-plugin-go/tfprotov6/toproto/string_kind.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2188      +/-   ##
==========================================
- Coverage   60.68%   56.66%   -4.03%     
==========================================
  Files         356      361       +5     
  Lines       46451    49443    +2992     
==========================================
- Hits        28189    28015     -174     
- Misses      16704    19891    +3187     
+ Partials     1558     1537      -21     

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

@@ -2,6 +2,7 @@
"changes": "DIFF_SOME",
"diffs": [
"attrNumberComputed",
"attrNumberRequired",
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a correct result, this used to be a bug. Likely a degenerate case because a required property cannot be not specified in the program.

)

// Assist converting Plugin framework schemata to proto schemata for a resource.
func convertResourceSchemaToProto(ctx context.Context, s *rschema.Schema) (*tfprotov6.Schema, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a slightly convoluted way to convert rschema.Schema to protos. Perhaps could be avoided by vendoring internal code from the Plugin framework.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is indeed quite roundabout - could we add a comment with a TODO here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I don't intend revisiting though, I think alternatives are worse.

},
Optional: true,
},
"list": rschema.ListNestedAttribute{
NestedObject: rschema.NestedAttributeObject{
Attributes: map[string]rschema.Attribute{
"bar": rschema.StringAttribute{},
"bar": rschema.StringAttribute{Optional: true},
Copy link
Member Author

Choose a reason for hiding this comment

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

These cases started failing because the schema was not valid.

@t0yv0 t0yv0 changed the title Toward removing custom objchange implementation Use OpenTofu planner with Plugin Framework providers Jul 25, 2024
@t0yv0 t0yv0 marked this pull request as ready for review July 25, 2024 20:10
@t0yv0 t0yv0 requested review from iwahbe and corymhall July 25, 2024 20:10
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.

Thanks for updating the dependencies here!

)

// Assist converting Plugin framework schemata to proto schemata for a resource.
func convertResourceSchemaToProto(ctx context.Context, s *rschema.Schema) (*tfprotov6.Schema, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is indeed quite roundabout - could we add a comment with a TODO here?

// TODO[pulumi/pulumi-terraform-bridge#2247]: patching objchange.ProposedNew changed behavior
//
// Want: object(map[string]valueBuilder{"foo": prim(nil)}),
Want: unk(),
Copy link
Contributor

Choose a reason for hiding this comment

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

These all look "more correct" here in the absence of a planmodifier. Good to see we don't have any regressions with the objchange patch in pf

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah well maybe, these tests are a bit too low level to call which one we want.

@@ -0,0 +1,3 @@
# opentofu

Code vendored from [opentofu](https://github.com/opentofu/opentofu). Do not edit, use `go generate` to update.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a CI check for vendored code to avoid any accidents here? Run go generate, check repo is clean. Fine as a follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

@t0yv0 t0yv0 merged commit 7f2e4c0 into master Jul 26, 2024
13 checks passed
@t0yv0 t0yv0 deleted the t0yv0/remove-custom-objchange branch July 26, 2024 13:16
t0yv0 added a commit that referenced this pull request Aug 14, 2024
Rebased and tidied up
#2168

Fixes #2170

This change confirms that the bug discovered in
pulumi/pulumi-meraki#97 is now fixed in the
latest bridge via
#2188

---------

Co-authored-by: Venelin <[email protected]>
@mjeffryes mjeffryes added this to the 0.108 milestone Aug 16, 2024
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.

PF update proposed new to pull recent upstream changes
4 participants