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

PF defaults not applied #2218

Closed
VenelinMartinov opened this issue Jul 21, 2024 · 14 comments
Closed

PF defaults not applied #2218

VenelinMartinov opened this issue Jul 21, 2024 · 14 comments
Assignees
Labels
customer/feedback Feedback from customers kind/bug Some behavior is incorrect or out of spec p1 A bug severe enough to be the next item assigned to an engineer resolution/no-repro This issue wasn't able to be reproduced
Milestone

Comments

@VenelinMartinov
Copy link
Contributor

What happened?

It seems like for some cases defaults in PF schema are not applied to resource properties.

Quite surprising, happy to be pointed to any errors in the test here.

Found during an attempt at reproing a customer issue with a private PF provider.

Example

#2217

Output of pulumi about

.

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@VenelinMartinov VenelinMartinov added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team and removed needs-triage Needs attention from the triage team labels Jul 21, 2024
@VenelinMartinov
Copy link
Contributor Author

here are some details from the GRPC calls: change_reason is not mentioned at all:

/pulumirpc.ResourceProvider/Check
{"urn":"urn:pulumi:test::test::prov:index/test:Test::mainRes","olds":{},"news":{"otherProp":"val"},"randomSeed":"JiYdqeul7IEPc4bsh2+Nf751Pg+yyMa/lcUf1A06Obk="}
{"inputs":{"otherProp":"val"}}

/pulumirpc.ResourceProvider/Create
{"urn":"urn:pulumi:test::test::prov:index/test:Test::mainRes","properties":{"otherProp":"val"}}
{"id":"test-id","properties":{"id":"test-id","otherProp":"val"}}

@VenelinMartinov
Copy link
Contributor Author

@t0yv0 provided some possible context here - PF initially did not support Defaults at all at the time when the PF bridge was initially developed. It relied entirely on PlanModifiers.

Defaults were added later so it is possible something on the TF side changed in the meantime.

@guineveresaenger guineveresaenger added customer/feedback Feedback from customers and removed needs-triage Needs attention from the triage team labels Jul 22, 2024
@t0yv0
Copy link
Member

t0yv0 commented Jul 22, 2024

Still the expectation is that this is handled by PlanResourceChange call to the PF itself, so curious to see where the bug is here.

@VenelinMartinov
Copy link
Contributor Author

#2225 adds tests for input extraction which is also affected by this issue.

We seem to generate inputs for properties which are using their default values, which is not the intention of the code and is not what the SDKv2 does. We should address as part of this issue.

VenelinMartinov added a commit that referenced this issue Jul 23, 2024
This adds adds missing test coverage for `ExtractInputsFromOutputs` for
various PF schemas. `ExtractInputsFromOutputs` is a shared function so
we should have coverage on both sides to make sure we don't cause
regressions when fixing one.

Similar to #2224
but on the PF side.

This is in preparation for
#2181 for
#2180.

Seeing some more evidence of
#2218 here.
@t0yv0
Copy link
Member

t0yv0 commented Jul 23, 2024

Could you please break out the input extraction interaction with PF Defaults into a separate issue, thanks.

@VenelinMartinov
Copy link
Contributor Author

Yup, #2238

@VenelinMartinov
Copy link
Contributor Author

VenelinMartinov commented Jul 24, 2024

Did a bunch of digging here. The default values are present during planning but go missing after ApplyResourceChange:

resp, err := p.tfServer.ApplyResourceChange(ctx, &req)

I did some comparison with OpenTofu, here's where the equivalent thing is happening on their side:
https://github.com/opentofu/opentofu/blob/cb2e9119aa75eeb8e1fa175e2b7a205a4fef129f/internal/tofu/node_resource_apply_instance.go#L311

and

https://github.com/opentofu/opentofu/blob/864aa9d1d629090cfc4ddf9fdd344d34dee9793e/internal/tofu/node_resource_abstract_instance.go#L2345

It seems like they always pass cty.Null values in the ConfigValue for the properties in question and Apply sets them.

I have been unable to find a TF PF resource which has a Default and is not Computed, so not certain how much of this is due to Computed.

Either way, we still don't pass Null for Computed properties either, which is a clear discrepency.

@VenelinMartinov
Copy link
Contributor Author

Opened #2244 for cross testing PF inputs, that would have likely caught this.

@t0yv0
Copy link
Member

t0yv0 commented Jul 24, 2024

I don't quite follow.

  1. is the behavior under OpenTofu/TF different from the bridged provider behavior?
  2. if we were to isolate the place where the discrepancy first starts manifesting, where would it be?

@t0yv0
Copy link
Member

t0yv0 commented Jul 24, 2024

I'm wondering if objchange refactor is going to affect this as well.

@mjeffryes mjeffryes added this to the 0.108 milestone Jul 24, 2024
@VenelinMartinov
Copy link
Contributor Author

I don't think objchange would affect this as the plan for the property in question is correct.

The problem only happens during apply

@VenelinMartinov
Copy link
Contributor Author

OpenTofu sets defaults, we don't. This is a clear difference in behaviour.

The default does not get return from Apply in the bridge, while in opentofu it does. However, I believe the issue is happening earlier as we pass different values to Apply for the Config - they set Nulls, we don't.

@t0yv0 t0yv0 added the p1 A bug severe enough to be the next item assigned to an engineer label Jul 25, 2024
@t0yv0
Copy link
Member

t0yv0 commented Jul 25, 2024

While it's possible to workaround this it sounds like this is highly unexpected and the impact can be quite significant. Marking as P1.

@VenelinMartinov VenelinMartinov added the resolution/no-repro This issue wasn't able to be reproduced label Jul 26, 2024
@VenelinMartinov
Copy link
Contributor Author

VenelinMartinov commented Jul 26, 2024

This turned out to be a red herring - the test was set up wrong - defaults are applied fine as long as the provider is implemented correctly to apply the plan, not the config:

#2217 will add a regression test here.

VenelinMartinov added a commit that referenced this issue Aug 21, 2024
Adds PF integration tests for defaults and plan modifiers.

Regression tests for
#2171 and
#2218

stacked on #2254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer/feedback Feedback from customers kind/bug Some behavior is incorrect or out of spec p1 A bug severe enough to be the next item assigned to an engineer resolution/no-repro This issue wasn't able to be reproduced
Projects
None yet
Development

No branches or pull requests

4 participants