-
Notifications
You must be signed in to change notification settings - Fork 43
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 TF Diff Attributes to set diff response changes when SkipDetailedDiffForChanges feature flag is set #1502
Conversation
…DiffForChanges feature flag is set
Codecov Report
@@ Coverage Diff @@
## master #1502 +/- ##
==========================================
- Coverage 61.93% 57.91% -4.02%
==========================================
Files 184 285 +101
Lines 32836 39629 +6793
==========================================
+ Hits 20336 22953 +2617
- Misses 11362 15339 +3977
- Partials 1138 1337 +199
... and 102 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
pkg/tfbridge/provider.go
Outdated
@@ -661,6 +661,15 @@ func (p *Provider) Diff(ctx context.Context, req *pulumirpc.DiffRequest) (*pulum | |||
doIgnoreChanges(ctx, res.TF.Schema(), res.Schema.Fields, olds, news, req.GetIgnoreChanges(), diff) | |||
detailedDiff, changes := makeDetailedDiff(ctx, res.TF.Schema(), res.Schema.Fields, olds, news, diff) | |||
|
|||
// There are some providers/situations which `makeDetailedDiff` distorts the expected changes, leading | |||
// to changes being dropped by Pulumi. | |||
// Until we address https://github.com/pulumi/pulumi-terraform-bridge/issues/1501, it is safer to refer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change literally addresses 1501
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does; but I'm under the impression we'll want to keep it open so we can fix the bugs in makeDetailedDiff
"for real".
I'll amend the wording to reflect more nuance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, I'm happy to close. We can open new issues for makeDetailedDiff referencing the closed issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like at least 1 synthetic test case to make sure this is hooked up (and to prevent regressions).
pkg/tfbridge/info.go
Outdated
// Disables using detailed diff to determine diff changes and falls back on the length of TF Diff Attributes. | ||
// | ||
// See https://github.com/pulumi/pulumi-terraform-bridge/issues/1501 | ||
SkipDetailedDiffForChanges bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want to support this feature until v4.0.0. When we close #1501 for real, we will want to remove this flag.
// Disables using detailed diff to determine diff changes and falls back on the length of TF Diff Attributes. | |
// | |
// See https://github.com/pulumi/pulumi-terraform-bridge/issues/1501 | |
SkipDetailedDiffForChanges bool | |
// Disables using detailed diff to determine diff changes and falls back on the length of TF Diff Attributes. | |
// | |
// See https://github.com/pulumi/pulumi-terraform-bridge/issues/1501 | |
// | |
// This flag is experimental and may be removed in a future bridge release. | |
XSkipDetailedDiffForChanges bool |
pkg/tfbridge/provider.go
Outdated
// There are some providers/situations which `makeDetailedDiff` distorts the expected changes, leading | ||
// to changes being dropped by Pulumi. | ||
// Until we address https://github.com/pulumi/pulumi-terraform-bridge/issues/1501, it is safer to refer | ||
// to the Terraform Diff attribute length for setting the DiffResponse. | ||
// We will still use `detailedDiff` for diff display purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate the comment explaining what is going on!
// to the Terraform Diff attribute length for setting the DiffResponse. | ||
// We will still use `detailedDiff` for diff display purposes. | ||
if p.info.SkipDetailedDiffForChanges && len(diff.Attributes()) > 0 { | ||
changes = pulumirpc.DiffResponse_DIFF_SOME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noting that it doesn't do the inverse, that is if len(diff.Attributes()) == 0 but makeDetailedDiff returned CHANGES, it does not override it back to NO_CHANGES. Is that perhaps a degenerate/ non-existent situation? Reading the code seems to be the case, so we're probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have not verified such a situation as of today to the best of my knowledge.
Also fixes AWS P1.. LGTM once tested, consider #1498 test cases I believe this change makes them pass, adding empty tags to map at least certainly should pass. |
…ction and when XSkipDetailedDiff is set Adds a new test provider that has a CuztomizeDiff field This change does NOT add a test for the False() -> DIFF_NONE case which occurs today but is a bug we need to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 nit on the test, but LGTM!
internal/testprovider/schema.go
Outdated
@@ -880,3 +880,54 @@ func AssertProvider(f func(data *schemav2.ResourceData)) *schemav2.Provider { | |||
}, | |||
} | |||
} | |||
|
|||
func AssertCustomizedDiffProvider(f func(data *schemav2.ResourceData)) *schemav2.Provider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't care about calling f
here, we can just remove it.
func AssertCustomizedDiffProvider(f func(data *schemav2.ResourceData)) *schemav2.Provider { | |
func CustomizedDiffProvider() *schemav2.Provider { |
Schema: map[string]*schemav2.Schema{}, | ||
ResourcesMap: map[string]*schemav2.Resource{ | ||
"test_resource": { | ||
Schema: map[string]*schemav2.Schema{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably delete a lot here the test will only exercise CustomizeDiff
Adds a `DiffEqualDecisionOverride` to the shim layer which allows provider implementations to specify a diff decision instead of relying on the shim layer to do that. Also adds a `DiffEqualDecisionOverride` to the PRC sdkv2 implementation which opentofu does. Also adds a feature flag `EnableAccurateBridgePreview` which guards this feature. will fix once rolled out: #2293 will fix once rolled out: #1501 will undo once rolled out: #1502 as the underlying issue was fixed during the PRC work. Stacked on #2380
This PR presents an alternative fix for #1491.
Because
makeDetailedDiff
can distort the expected changes for a diff set via custom diffs in the upstream provider logic, we should not, in all cases, rely on it to provide us with an accuratepulumirpc.DiffResponse.Changes
result. This PR does two things:SkipDetailedDiffForChanges
.This code will continue to rely on
makeDetailedDiff
for setting theDetailedDiff
field in all cases.I have verified that this succeeds against these test cases when the GCP provider sets
SkipDetailedDiffForChanges
to True, and fails when set to False.Fixes #1491 in the context of unblocking the GCP release.