Skip to content

Commit

Permalink
fix typeinfo suffix regression
Browse files Browse the repository at this point in the history
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
  • Loading branch information
chanwit committed Jul 6, 2023
1 parent 881afcc commit 00c39a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/typeinfo/type_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package typeinfo

const Suffix = "__type"
4 changes: 2 additions & 2 deletions controllers/tf_controller_outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand Down
3 changes: 2 additions & 1 deletion runner/read_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions runner/server_generate_tf_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -141,15 +142,15 @@ 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)
}

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)
Expand Down

0 comments on commit 00c39a9

Please sign in to comment.