-
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
Encode default values #1322
Encode default values #1322
Conversation
9cca651
to
9d270bf
Compare
Diff for pulumi-azuread with merge commit ebf2220 |
Diff for pulumi-azuread with merge commit 09fe9f9 |
pkg/tfbridge/schema.go
Outdated
@@ -718,7 +724,12 @@ func (ctx *conversionContext) applyDefaults(result map[string]interface{}, olds, | |||
} | |||
if defaultValue != nil { | |||
glog.V(9).Infof("Created Terraform input: %v = %v (from %s)", name, defaultValue, source) | |||
result[name] = defaultValue | |||
pValue := resource.NewPropertyValue(defaultValue) |
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.
Well this is a massive transformation introduced here! We need to be careful. We're losing track of what the actual type is of defaultValue because it all collapses to any. There's two options it's either "any" representation of pulumi.PropertyValue or it's the "any" representation of TF value (hcty.Value).
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.
Your right. This transformation should have been applied earlier. Fixed in 796df14.
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.
Eh! I'm not sure! That depends on what we expect users to put in defaultValue. Just need to be careful if we're changing it need to call it out... change management..
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 stick Default.Value
in the pulumi schema, which is then bundled into our SDKs. It must match the pulumi type or we get compile errors.
If the pulumi value is the same as the TF value, then MakeTerraformInput
won't do anything. If it isn't then the default value will be of the pulumi kind and we need the conversion.
9d270bf
to
796df14
Compare
Diff for pulumi-azuread with merge commit 3f8fa20 |
This is necessary since implicit conversions cast to int, true->1, false->0 instead of to string: true->"true", false->"false". The latter is what Terraform providers expect.
796df14
to
7f3f93a
Compare
Diff for pulumi-azuread with merge commit c12bbf8 |
This ensures that default values have the correct shape. This takes advantage of the previous change to ensure that a default value such as `true` is translated to `"true"` when Terraform expects a value of type string.
7f3f93a
to
144204d
Compare
Diff for pulumi-azuread with merge commit 24b1045 |
Eh, I don't love this change. We started from a spurious warning in pulumi-aws that defines a SchemaInfo like this:
And actually models this filed as a String in TF land. It sounds like Pulumi->TF conversion wasn't coalescing The tricker bit is this:
This has far more scope than simply coalescing bools to a desired string slot. The function is interesting, it can do things like rename object fields from Pulumi to TF spelling (although maybe it tolerates both spellings?), it can expand While logically it would make sense that we ask the users to write in values as Pulumi understands them into DefaultInfo.Value, it's not obvious to me that the change wouldn't break some providers that did decide to write in values as Terraform understands them to make things work, and perhaps those providers would break now, at runtime. At the very least this needs to be called out very obviously in release notes. I'd also love to understand why perhaps this is not a concern, are we scanning existing providers for DefaultInfo.Value, or we believe that the change can't in principle break (and can demonstrate in tests). Note that it is possible to solve the skip_metadata_api_check weakening the change to conservatively only do type coalesce operation when the type mismatches Bool != String. This opens up the possibility of taking the other improvement in a separate enhancement PR. |
So far so good: this change prevents the warning when the user explicitly sets I'm not aware of a concrete use case for
User's are required to write in Pulumi types, since schema validation enforces that
We will call this out in the changelog. This change, like any bug fix, can break a provider that requires the old behavior. I don't expect to find this scenario in the wild. TF's frameworks expect that a stringly typed bool is represented as {"true", "false"} instead of {"1", "0"}. If we have any providers that require {"1", "0"}, they can provide a custom transformation here, but it will be nonstandard. This part of the bridge should work in the common case.
That is a more conservative approach, and we could do that. In the absence of evidence2 that this will break providers, I don't think the caution is necessary. Doing the general conversion is the more "correct" semantic, giving TF providers the types they have specified. It provides a cleaner separation between Pulumi types and TF types, which is what we want since TF providers are not aware of Pulumi types. Footnotes |
Ok, I filed #1325 because it's not obvious why compound values are not supported. This was not obvious to me why that wouldn't work. Note that emitting default values into the Pulumi Package Schema seems to be an entirely optional feature to uncover more information about the provider in the documentation and generated language SDKs, as the bridge code still consults default values for runtime application. In that sense it could be possible to support compound default values just fine, which I assumed was the case. Anyway that can wait it's time as a feature request. For now let's merge this, the state space is a lot more constrained if compound objects are not allowed. |
Fixes pulumi/pulumi-aws#2646
This PR makes two distinct changes:
"true"
and"false"
instead oftrue
andfalse
.MakeTerraformInput
on values drawn fromSchemaInfo.DefaultInfo.Value
. This uses the machinery introduced in the previous commit.WIP: Still needs tests for both features.