From cd9ad00a72ac00e3f62c24431cd5b9c53ee6db2b Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Wed, 2 Aug 2023 16:20:05 +0200 Subject: [PATCH 1/2] Translate bool->string explicitly when they don't match 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. --- pkg/tfbridge/schema.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index 0314ecc863..fe7600acd2 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -365,6 +365,12 @@ func (ctx *conversionContext) MakeTerraformInput(name string, old, v resource.Pr case v.IsNull(): return nil, nil case v.IsBool(): + if tfs != nil && tfs.Type() == shim.TypeString { + if v.BoolValue() { + return "true", nil + } + return "false", nil + } return v.BoolValue(), nil case v.IsNumber(): if tfs != nil && tfs.Type() == shim.TypeFloat { From 9d270bf8ad3b819b4cf15f7a99596450f52485c8 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Wed, 2 Aug 2023 16:22:51 +0200 Subject: [PATCH 2/2] Call MakeTerraformInput on default values 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. --- pkg/tfbridge/schema.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/tfbridge/schema.go b/pkg/tfbridge/schema.go index fe7600acd2..759d01d4fd 100644 --- a/pkg/tfbridge/schema.go +++ b/pkg/tfbridge/schema.go @@ -724,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) + tv, err := ctx.MakeTerraformInput(name, resource.PropertyValue{}, pValue, tfi, psi, rawNames) + if err != nil { + return err + } + result[name] = tv newDefaults = append(newDefaults, key) // Expand the conflicts and exactlyOneOf map