-
Notifications
You must be signed in to change notification settings - Fork 44
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
Introduce InstanceStateStrategy CtyInstanceState flag to fix pulumi-aws#1423 #887
Conversation
Diff for pulumi-random with merge commit f09578e |
Diff for pulumi-azuread with merge commit f09578e |
Diff for pulumi-azuread with merge commit 514ba39 |
Diff for pulumi-gcp with merge commit f09578e |
Diff for pulumi-random with merge commit 514ba39 |
Diff for pulumi-azure with merge commit f09578e |
Diff for pulumi-gcp with merge commit 514ba39 |
Diff for pulumi-random with merge commit 970e172 |
Diff for pulumi-azuread with merge commit 970e172 |
Diff for pulumi-azure with merge commit 514ba39 |
Diff for pulumi-gcp with merge commit 970e172 |
From tracing SetHash
|
If I replace Set Hash function with a constant value, we get the desired diff None, so I think this is a bug about set element hashing, especially influenced by the override_action parameter in the schema, that affects the hash. This parameter is a little weird. A list of objects of emptySchema. I'm guessing there's a discrepancy in how TF vs Pulumi computes set hashes for these. |
Diff for pulumi-azure with merge commit 970e172 |
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.
A test is a great start - any reason it's a draft PR?
I thought maybe we can find a quick fix! But it's not so easy :) |
8c62f41
to
9d104b0
Compare
Diff for pulumi-random with merge commit 76d8da3 |
Diff for pulumi-azuread with merge commit 76d8da3 |
Diff for pulumi-gcp with merge commit 76d8da3 |
Diff for pulumi-azure with merge commit 76d8da3 |
Debugging this a little further. @danielrbradley if you're interested. This till reproduces. I think the bug is actually in Create method. We send this to create
But it sends this back:
That's different. That's as if count property wasn't set. My program is import * as aws from "@pulumi/aws";
const args: aws.wafv2.WebAclArgs = {
scope: "REGIONAL",
rules: [
{
name: "rule-1",
priority: 1,
overrideAction: {
count: {},
},
statement: {
managedRuleGroupStatement: {
name: "AWSManagedRulesCommonRuleSet",
vendorName: "AWS",
}
},
visibilityConfig: {
cloudwatchMetricsEnabled: false,
metricName: "friendly-rule-metric-name",
sampledRequestsEnabled: false,
},
}
],
defaultAction: {
allow: {},
},
visibilityConfig: {
cloudwatchMetricsEnabled: false,
metricName: "friendly-rule-metric-name",
sampledRequestsEnabled: false,
},
};
const acl = new aws.wafv2.WebAcl("aclw", args);
export const arn = acl.arn; |
@@ -36,68 +37,41 @@ func (s v2InstanceState) ID() string { | |||
} | |||
|
|||
func (s v2InstanceState) Object(sch shim.SchemaMap) (map[string]interface{}, error) { |
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 method wan't doing quite the right thing. The empty object value ended up parsed as nil
. This caused problems because a List[EmptyObj]
value under MaxItems=1 flattening got translated to nil
which is indistinguishable from a nil
list.
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.
The new implementation leans into TF primitives. I wonder how to ramp up testing to know we can make this replacement.
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.
The new implementation trips up some tests because it now generates "foo": nil
entries in maps instead of eliding them.
Diff for pulumi-random with merge commit a69f697 |
Diff for pulumi-azuread with merge commit a69f697 |
Diff for pulumi-gcp with merge commit a69f697 |
Diff for pulumi-azure with merge commit a69f697 |
Diff for pulumi-azuread with merge commit 93dabc7 |
9ff0379
to
09822b0
Compare
Diff for pulumi-azuread with merge commit 9436cec |
Diff for pulumi-random with merge commit 9436cec |
Diff for pulumi-azuread with merge commit b8875b7 |
Diff for pulumi-random with merge commit b8875b7 |
Opting to flag it so we can deploy the fix for the motivating issue, without taking the risk wholesale. |
https://gist.github.com/t0yv0/3c25627a43e5326ccfd176f7e481f02c temp investigation of TF expected behavior in a unit test. |
Diff for pulumi-azuread with merge commit d5cbecb |
return ClassicInstanceState, false, nil | ||
} | ||
p, err := ParseInstanceStateStrategy(s) | ||
return p, err == nil, err |
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 feels weird to have all 3 values returned here. Why is (InstanceStateStrategy, error)
not enough?
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.
There's a difference between env var not being set and env var being set to a value that can't be parsed. Copied from ParseDiffStrategyFromEnv.
Diff for pulumi-azuread with merge commit d0e38f6 |
Diff for pulumi-azuread with merge commit af3a979 |
@iwahbe addressed the comments, ready for another look. |
Diff for pulumi-azuread with merge commit 7afb6ab |
@@ -107,6 +107,8 @@ func TestRegressAws1423(t *testing.T) { | |||
[]byte{}, /* pulumiSchema */ | |||
) | |||
|
|||
shimv2.SetInstanceStateStrategy(p.ResourcesMap().Get("aws_wafv2_web_acl"), shimv2.CtyInstanceState) |
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.
Do we need to regenerate the test case, or should we not expect a diff below this line?
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.
The test case does discriminate the functionality. It fails the test once the changes to undo the previous non-fix made to pulumi-terraform-diff-reader are made. It's incomplete in a sense that it couldn't discriminate the pulumi-terraform-diff-reader non-fix from a real 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.
I see
Fixes pulumi/pulumi-aws#1423
It appears that
func (s v2InstanceState) Object
is using customized github.com/pulumi/terraform-diff-reader/sdk-v2 code that is behind upstream TF source edits, and is causing pulumi-aws to misbehave. In particular when it reads and applies a diff like the following:it incorrectly decides to populate
count
with anil
value instead of the expected value of an empty object{}
. This cause confusion. Switching to more higher-level API from TF SDKv2 resolves the problem.However, using this API seems to break some other tests in the repo and causes several observable differences. For example, Pulumi starts returning explicit
"foo": null
fields for objects (distinct from maps) when it previously elided them. It also causes some set element ordering issues.Given that it is not a clean replacement, opting to be conservative and feature-flagging the change in a way that it can be activated for a single resource only.
I've tested pulumi/pulumi-aws#1423 on top of this change plus a one-line configuration in
resources.go
and verified that the problem is resoled, moreover the resource responds correctly to further edits. Configuration line:Previous attempt to fix 1423 by editing terraform-diff-reader/sdk-v2 did not work end to end and is reverted here.