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

Refactor makeTerraformInputs and friends #1725

Merged
merged 44 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9e3982a
Revert "Revert "Make sure no nil lists are passed to TF (#1688)""
VenelinMartinov Mar 4, 2024
1c1e320
regression tests
VenelinMartinov Mar 5, 2024
2720970
lint
VenelinMartinov Mar 5, 2024
f963008
apply max items one defaults only when tf defaults are applied
VenelinMartinov Mar 5, 2024
393cc55
expand makeTerraformInputs tests
VenelinMartinov Mar 5, 2024
2904cfc
remove unrelated tests
VenelinMartinov Mar 5, 2024
e14a9b9
unrelated tests
VenelinMartinov Mar 5, 2024
be3609c
Don't apply TF defaults in CheckConfig
VenelinMartinov Mar 6, 2024
1c84883
address review comments
VenelinMartinov Mar 6, 2024
29893e2
Update pkg/tfbridge/provider.go
VenelinMartinov Mar 6, 2024
cfe0eb1
fix syntax
VenelinMartinov Mar 6, 2024
100d649
lint
VenelinMartinov Mar 6, 2024
d415796
Merge branch 'master' into vvm/nil_lists_max_items_one
VenelinMartinov Mar 6, 2024
d35b543
add makeTerraformInputsWithoutMaxItemsOneDefaults variant
VenelinMartinov Mar 6, 2024
a04a8c6
change function names in tests to match producion ones
VenelinMartinov Mar 6, 2024
3b19061
scope down the changes to affect ONLY Create
VenelinMartinov Mar 7, 2024
359b5f0
clarify test names, add back comment
VenelinMartinov Mar 7, 2024
2440d3e
clarify test name
VenelinMartinov Mar 7, 2024
9778a11
remove todo, not doable
VenelinMartinov Mar 7, 2024
29d9870
clean up make terraform inputs entrypoints in test
VenelinMartinov Mar 7, 2024
6ebd873
add todo
VenelinMartinov Mar 7, 2024
3b2ccaf
clarify todo
VenelinMartinov Mar 7, 2024
e8c7962
refactor to use makeTFInputsHelper
VenelinMartinov Mar 9, 2024
2bed79b
lint, clarify docs
VenelinMartinov Mar 9, 2024
3de7a6c
Merge branch 'master' into vvm/nil_lists_max_items_one
VenelinMartinov Mar 9, 2024
5b0e708
Merge branch 'master' into vvm/nil_lists_max_items_one
VenelinMartinov Mar 9, 2024
7ddf14c
lint
VenelinMartinov Mar 9, 2024
5f0fad4
Merge branch 'vvm/nil_lists_max_items_one' of github.com:pulumi/pulum…
VenelinMartinov Mar 9, 2024
ae1be26
lint
VenelinMartinov Mar 9, 2024
71b1f5d
refactor makeTerraformInputs entrypoints
VenelinMartinov Mar 11, 2024
345fa0a
Merge branch 'master' into vvm/nil_lists_max_items_one
VenelinMartinov Mar 11, 2024
0ba5289
rename test variables to match new function names
VenelinMartinov Mar 11, 2024
b67c9e9
lint
VenelinMartinov Mar 11, 2024
c7651cb
Revert "Update pkg/tfbridge/provider.go"
VenelinMartinov Mar 11, 2024
8b7c5e9
switch makeTerraformInputsOptions parity and change to non-pointers
VenelinMartinov Mar 12, 2024
d2a9122
Merge branch 'master' into vvm/nil_lists_max_items_one
VenelinMartinov Mar 12, 2024
fcc0f4d
swap back MakeTerraformConfig parameters
VenelinMartinov Mar 12, 2024
548e905
max items one defaults in update
VenelinMartinov Mar 13, 2024
38d6e0d
make terraform state variant
VenelinMartinov Mar 18, 2024
09bcd44
revert behaviour changes
VenelinMartinov Mar 18, 2024
9b5e899
fix tests
VenelinMartinov Mar 18, 2024
a3ef018
lint
VenelinMartinov Mar 18, 2024
2ab7929
re-add public methods, remove unneccessary changes
VenelinMartinov Mar 19, 2024
09de622
remove more unneccessary changes
VenelinMartinov Mar 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions pkg/tests/regress_940_test.go
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

35 changes: 23 additions & 12 deletions pkg/tfbridge/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,11 @@ func (p *Provider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (*pul
}
}

// Now fetch the default values so that (a) we can return them to the caller and (b) so that validation
// includes the default values. Otherwise, the provider wouldn't be presented with its own defaults.
tfname := res.TFName
inputs, _, err := makeTerraformInputsWithoutTFDefaults(ctx,
inputs, _, err := makeTerraformInputsWithOptions(ctx,
&PulumiResource{URN: urn, Properties: news, Seed: req.RandomSeed},
p.configValues, olds, news, res.TF.Schema(), res.Schema.Fields)
p.configValues, olds, news, res.TF.Schema(), res.Schema.Fields,
makeTerraformInputsOptions{DisableTFDefaults: true})
if err != nil {
return nil, err
}
Expand All @@ -780,8 +779,15 @@ func (p *Provider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (*pul
rescfg := MakeTerraformConfigFromInputs(ctx, p.tf, inputs)
warns, errs := p.tf.ValidateResource(ctx, tfname, rescfg)
for _, warn := range warns {
if err = p.host.Log(ctx, diag.Warning, urn, fmt.Sprintf("%v verification warning: %v", urn, warn)); err != nil {
return nil, err
warning := fmt.Sprintf("%v verification warning: %v", urn, warn)
// TODO: This is needed for tests, since tests don't have a host defined.
// We should clean this up once we fix that.
if p.host == nil {
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
glog.Warning(warning)
} else {
if err = p.host.Log(ctx, diag.Warning, urn, warning); err != nil {
return nil, err
}
}
}

Expand Down Expand Up @@ -1013,15 +1019,20 @@ func (p *Provider) Create(ctx context.Context, req *pulumirpc.CreateRequest) (*p
label := fmt.Sprintf("%s.Create(%s/%s)", p.label(), urn, res.TFName)
glog.V(9).Infof("%s executing", label)

props, err := plugin.UnmarshalProperties(req.GetProperties(),
plugin.MarshalOptions{Label: label, KeepUnknowns: true, SkipNulls: true})
if err != nil {
return nil, errors.Wrapf(err, "unmarshaling %s's new property state", urn)
}
// To get Terraform to create a new resource, the ID must be blank and existing state must be empty (since the
// resource does not exist yet), and the diff object should have no old state and all of the new state.
config, assets, err := UnmarshalTerraformConfig(ctx,
p, req.GetProperties(), res.TF.Schema(), res.Schema.Fields,
fmt.Sprintf("%s.news", label))
config, assets, err := makeTerraformConfigWithOpts(
ctx, p, props, res.TF.Schema(), res.Schema.Fields,
makeTerraformConfigOpts{},
)
if err != nil {
return nil, errors.Wrapf(err, "preparing %s's new property state", urn)
return nil, errors.Wrapf(err, "preparing %s's new property inputs", urn)
VenelinMartinov marked this conversation as resolved.
Show resolved Hide resolved
}

// To populate default timeouts, we take the timeouts from the resource schema and insert them into the diff
timeouts, err := res.TF.DecodeTimeouts(config)
if err != nil {
Expand Down Expand Up @@ -1063,7 +1074,7 @@ func (p *Provider) Create(ctx context.Context, req *pulumirpc.CreateRequest) (*p
}

// Create the ID and property maps and return them.
props, err := MakeTerraformResult(ctx, p.tf, newstate, res.TF.Schema(), res.Schema.Fields, assets, p.supportsSecrets)
props, err = MakeTerraformResult(ctx, p.tf, newstate, res.TF.Schema(), res.Schema.Fields, assets, p.supportsSecrets)
if err != nil {
reasons = append(reasons, errors.Wrapf(err, "converting result for %s", urn).Error())
}
Expand Down
Loading