diff --git a/api/typeinfo/type_info.go b/api/typeinfo/type_info.go new file mode 100644 index 00000000..c3385314 --- /dev/null +++ b/api/typeinfo/type_info.go @@ -0,0 +1,3 @@ +package typeinfo + +const Suffix = "__type" diff --git a/controllers/tf_controller_outputs.go b/controllers/tf_controller_outputs.go index b0c96935..cca9af55 100644 --- a/controllers/tf_controller_outputs.go +++ b/controllers/tf_controller_outputs.go @@ -7,8 +7,8 @@ import ( "strings" eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1" - "github.com/hashicorp/terraform-exec/tfexec" + "github.com/weaveworks/tf-controller/api/typeinfo" infrav1 "github.com/weaveworks/tf-controller/api/v1alpha2" "github.com/weaveworks/tf-controller/runner" "github.com/zclconf/go-cty/cty" @@ -166,7 +166,7 @@ func (r *TerraformReconciler) writeOutput(ctx context.Context, terraform infrav1 data[outputOrAlias] = []byte(cv.AsString()) } else { data[outputOrAlias] = outputMeta.Value - data[outputOrAlias+"__type"] = outputMeta.Type + data[outputOrAlias+typeinfo.Suffix] = outputMeta.Type } } diff --git a/runner/read_inputs_test.go b/runner/read_inputs_test.go index a5439389..de4c0942 100644 --- a/runner/read_inputs_test.go +++ b/runner/read_inputs_test.go @@ -8,6 +8,7 @@ import ( "github.com/go-logr/logr" "github.com/hashicorp/hcl2/hcldec" "github.com/hashicorp/hcl2/hclparse" + "github.com/weaveworks/tf-controller/api/typeinfo" infrav1 "github.com/weaveworks/tf-controller/api/v1alpha2" "github.com/zclconf/go-cty/cty" ctyjson "github.com/zclconf/go-cty/cty/json" @@ -72,7 +73,7 @@ j = { a = 1, b = 2, c = 3 } tt, err := ctyjson.MarshalType(vv.Type()) g.Expect(err).To(BeNil()) - data[k+".type"] = tt + data[k+typeinfo.Suffix] = tt raw, err := ctyjson.Marshal(vv, vv.Type()) g.Expect(err).To(BeNil()) data[k] = raw diff --git a/runner/server_generate_tf_vars.go b/runner/server_generate_tf_vars.go index 50844a06..50c0d90e 100644 --- a/runner/server_generate_tf_vars.go +++ b/runner/server_generate_tf_vars.go @@ -11,6 +11,7 @@ import ( "text/template" "github.com/go-logr/logr" + "github.com/weaveworks/tf-controller/api/typeinfo" infrav1 "github.com/weaveworks/tf-controller/api/v1alpha2" "github.com/weaveworks/tf-controller/utils" "github.com/zclconf/go-cty/cty" @@ -141,7 +142,7 @@ func ctyValueToGoValue(ctyValue cty.Value) (interface{}, error) { func convertSecretDataToInputs(log logr.Logger, secret *v1.Secret) (map[string]interface{}, error) { var keys []string for k := range secret.Data { - if strings.HasSuffix(k, ".type") { + if strings.HasSuffix(k, typeinfo.Suffix) { continue } keys = append(keys, k) @@ -149,7 +150,7 @@ func convertSecretDataToInputs(log logr.Logger, secret *v1.Secret) (map[string]i data := map[string]interface{}{} for _, key := range keys { - typeInfo, exist := secret.Data[key+".type"] + typeInfo, exist := secret.Data[key+typeinfo.Suffix] if exist { raw := secret.Data[key] ct, err := json.UnmarshalType(typeInfo)