-
Notifications
You must be signed in to change notification settings - Fork 50
Fix required properties with default in TF projecting as non-optional in Pulumi #3035
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4e5a602
repro
VenelinMartinov 756b203
have tfgen check defaults when determining required inputs
VenelinMartinov 18351d6
wip
VenelinMartinov 284dedc
add HasDefault method
VenelinMartinov 302c5ce
fix pf, re-record tests
VenelinMartinov 2d8f21d
skip test on windows
VenelinMartinov 6509eea
refactor test
VenelinMartinov 08fa149
add a flag, disable on windows
VenelinMartinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| package pfutils | ||
|
|
||
| import ( | ||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults" | ||
| ) | ||
|
|
||
| // These interfaces are re-implemented here from "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" | ||
| // as we can not link to them directly. | ||
|
|
||
| type attributeLikeWithBoolDefaultValue interface { | ||
| AttrLike | ||
| BoolDefaultValue() defaults.Bool | ||
| } | ||
|
|
||
| type attributeLikeWithFloat32DefaultValue interface { | ||
| AttrLike | ||
| Float32DefaultValue() defaults.Float32 | ||
| } | ||
|
|
||
| type attributeLikeWithFloat64DefaultValue interface { | ||
| AttrLike | ||
| Float64DefaultValue() defaults.Float64 | ||
| } | ||
|
|
||
| type attributeLikeWithInt32DefaultValue interface { | ||
| AttrLike | ||
| Int32DefaultValue() defaults.Int32 | ||
| } | ||
|
|
||
| type attributeLikeWithInt64DefaultValue interface { | ||
| AttrLike | ||
| Int64DefaultValue() defaults.Int64 | ||
| } | ||
|
|
||
| type attributeLikeWithListDefaultValue interface { | ||
| AttrLike | ||
| ListDefaultValue() defaults.List | ||
| } | ||
|
|
||
| type attributeLikeWithMapDefaultValue interface { | ||
| AttrLike | ||
| MapDefaultValue() defaults.Map | ||
| } | ||
|
|
||
| type attributeLikeWithNumberDefaultValue interface { | ||
| AttrLike | ||
| NumberDefaultValue() defaults.Number | ||
| } | ||
|
|
||
| type attributeLikeWithObjectDefaultValue interface { | ||
| AttrLike | ||
| ObjectDefaultValue() defaults.Object | ||
| } | ||
|
|
||
| type attributeLikeWithSetDefaultValue interface { | ||
| AttrLike | ||
| SetDefaultValue() defaults.Set | ||
| } | ||
|
|
||
| type attributeLikeWithStringDefaultValue interface { | ||
| AttrLike | ||
| StringDefaultValue() defaults.String | ||
| } | ||
|
|
||
| type attributeLikeWithDynamicDefaultValue interface { | ||
| AttrLike | ||
| DynamicDefaultValue() defaults.Dynamic | ||
| } | ||
|
|
||
| func hasDefault(attr AttrLike) bool { | ||
| switch a := attr.(type) { | ||
| case attributeLikeWithBoolDefaultValue: | ||
| return a.BoolDefaultValue() != nil | ||
| case attributeLikeWithFloat32DefaultValue: | ||
| return a.Float32DefaultValue() != nil | ||
| case attributeLikeWithFloat64DefaultValue: | ||
| return a.Float64DefaultValue() != nil | ||
| case attributeLikeWithInt32DefaultValue: | ||
| return a.Int32DefaultValue() != nil | ||
| case attributeLikeWithInt64DefaultValue: | ||
| return a.Int64DefaultValue() != nil | ||
| case attributeLikeWithListDefaultValue: | ||
| return a.ListDefaultValue() != nil | ||
| case attributeLikeWithMapDefaultValue: | ||
| return a.MapDefaultValue() != nil | ||
| case attributeLikeWithNumberDefaultValue: | ||
| return a.NumberDefaultValue() != nil | ||
| case attributeLikeWithObjectDefaultValue: | ||
| return a.ObjectDefaultValue() != nil | ||
| case attributeLikeWithSetDefaultValue: | ||
| return a.SetDefaultValue() != nil | ||
| case attributeLikeWithStringDefaultValue: | ||
| return a.StringDefaultValue() != nil | ||
| case attributeLikeWithDynamicDefaultValue: | ||
| return a.DynamicDefaultValue() != nil | ||
| default: | ||
| return false | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
pkg/pf/tfgen/testdata/TestPFRequiredInputWithDefault.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| { | ||
| "name": "testprovider", | ||
| "attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).", | ||
| "meta": { | ||
| "moduleFormat": "(.*)(?:/[^/]*)" | ||
| }, | ||
| "language": { | ||
| "nodejs": { | ||
| "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", | ||
| "compatibility": "tfbridge20", | ||
| "disableUnionOutputTypes": true | ||
| }, | ||
| "python": { | ||
| "readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).", | ||
| "compatibility": "tfbridge20", | ||
| "pyproject": {} | ||
| } | ||
| }, | ||
| "config": {}, | ||
| "provider": { | ||
| "description": "The provider type for the testprovider package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n", | ||
| "methods": { | ||
| "terraformConfig": "pulumi:providers:testprovider/terraformConfig" | ||
| } | ||
| }, | ||
| "resources": { | ||
| "testprovider:index:Res": { | ||
| "properties": { | ||
| "a1": { | ||
| "type": "string" | ||
| }, | ||
| "a2": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "a1", | ||
| "a2" | ||
| ], | ||
| "inputProperties": { | ||
| "a1": { | ||
| "type": "string" | ||
| }, | ||
| "a2": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "requiredInputs": [ | ||
| "a2" | ||
| ], | ||
| "stateInputs": { | ||
| "description": "Input properties used for looking up and filtering Res resources.\n", | ||
| "properties": { | ||
| "a1": { | ||
| "type": "string" | ||
| }, | ||
| "a2": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "type": "object" | ||
| } | ||
| } | ||
| }, | ||
| "functions": { | ||
| "pulumi:providers:testprovider/terraformConfig": { | ||
| "description": "This function returns a Terraform config object with terraform-namecased keys,to be used with the Terraform Module Provider.", | ||
| "inputs": { | ||
| "properties": { | ||
| "__self__": { | ||
| "type": "ref", | ||
| "$ref": "#/resources/pulumi:providers:testprovider" | ||
| } | ||
| }, | ||
| "type": "pulumi:providers:testprovider/terraformConfig", | ||
| "required": [ | ||
| "__self__" | ||
| ] | ||
| }, | ||
| "outputs": { | ||
| "properties": { | ||
| "result": { | ||
| "additionalProperties": { | ||
| "$ref": "pulumi.json#/Any" | ||
| }, | ||
| "type": "object" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "result" | ||
| ], | ||
| "type": "object" | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.