diff --git a/upup/pkg/fi/cloudup/terraform/hcl2.go b/upup/pkg/fi/cloudup/terraform/hcl2.go index 1c606d709b2a4..8656132176870 100644 --- a/upup/pkg/fi/cloudup/terraform/hcl2.go +++ b/upup/pkg/fi/cloudup/terraform/hcl2.go @@ -106,7 +106,7 @@ func writeLiteral(body *hclwrite.Body, key string, literal *Literal) { tokens := hclwrite.Tokens{ { Type: hclsyntax.TokenIdent, - Bytes: []byte(fmt.Sprintf("file(%q)", literal.FilePath)), + Bytes: []byte(fmt.Sprintf("%v(%q)", literal.FileFn, literal.FilePath)), }, } body.SetAttributeRaw(key, tokens) @@ -193,7 +193,7 @@ func writeMap(body *hclwrite.Body, key string, values map[string]cty.Value) { // For maps of literals we currently only support file references // If we ever need to support a map of strings to resource property references that can be added here if literal.FilePath != "" { - tokens = append(tokens, &hclwrite.Token{Type: hclsyntax.TokenIdent, Bytes: []byte(fmt.Sprintf("file(%q)", literal.FilePath))}) + tokens = append(tokens, &hclwrite.Token{Type: hclsyntax.TokenIdent, Bytes: []byte(fmt.Sprintf("%v(%q)", literal.FileFn, literal.FilePath))}) } else if literal.Value != "" { tokens = append(tokens, []*hclwrite.Token{ {Type: hclsyntax.TokenOQuote, Bytes: []byte{'"'}, SpacesBefore: 1}, diff --git a/upup/pkg/fi/cloudup/terraform/literal.go b/upup/pkg/fi/cloudup/terraform/literal.go index 75dae890d1b1d..7c49083c432c2 100644 --- a/upup/pkg/fi/cloudup/terraform/literal.go +++ b/upup/pkg/fi/cloudup/terraform/literal.go @@ -24,6 +24,13 @@ import ( "k8s.io/klog" ) +type fileFn string + +const ( + fileFnFile fileFn = "file" + fileFnFileBase64 fileFn = "filebase64" +) + // Literal represents a literal in terraform syntax type Literal struct { // Value is only used in terraform 0.11 and represents the literal string to use as a value. @@ -37,8 +44,10 @@ type Literal struct { ResourceName string `cty:"resource_name"` // ResourceProp represents the property of a resource in a literal reference ResourceProp string `cty:"resource_prop"` - // FilePath represents the path for a file() reference + // FilePath represents the path for a file reference FilePath string `cty:"file_path"` + // FileFn represents the function used to reference the file + FileFn fileFn `cty:"file_fn"` } var _ json.Marshaler = &Literal{} @@ -48,13 +57,16 @@ func (l *Literal) MarshalJSON() ([]byte, error) { } func LiteralFileExpression(modulePath string, base64 bool) *Literal { - fn := "file" + fn := fileFnFile if base64 { - fn = "filebase64" + fn = fileFnFileBase64 } return &Literal{ - Value: fmt.Sprintf("${%v(%q)}", fn, modulePath), + // file() is hardcoded here because this field is + // used for Terraform 0.11 which does not have filebase64() + Value: fmt.Sprintf("${file(%q)}", modulePath), FilePath: modulePath, + FileFn: fn, } }