From bf83b435e11be2d48d62595391849fd01121cee4 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 4 Aug 2016 11:16:35 -0400 Subject: [PATCH] numeric variables aren't always interpreted as str If we have a number value in our config variables, format it as a string, and send it with the HCL=true flag just in case. Also use %g for for float encoding, as the output is a generally a little friendlier. --- command/hcl_printer.go | 2 +- command/push.go | 26 ++++++++------------------ 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/command/hcl_printer.go b/command/hcl_printer.go index 1537fff14..dbf1797f5 100644 --- a/command/hcl_printer.go +++ b/command/hcl_printer.go @@ -107,7 +107,7 @@ func (e *encodeState) encodeInt(i interface{}) error { } func (e *encodeState) encodeFloat(f interface{}) error { - _, err := fmt.Fprintf(e, "%f", f) + _, err := fmt.Fprintf(e, "%g", f) return err } diff --git a/command/push.go b/command/push.go index d7845ddb4..0a6290594 100644 --- a/command/push.go +++ b/command/push.go @@ -327,25 +327,15 @@ RANGE: case string: tfv.Value = v - case []interface{}: - hcl, err = encodeHCL(v) - if err != nil { - break RANGE - } - - tfv.Value = string(hcl) - tfv.IsHCL = true - - case map[string]interface{}: - hcl, err = encodeHCL(v) - if err != nil { - break RANGE - } - - tfv.Value = string(hcl) - tfv.IsHCL = true default: - err = fmt.Errorf("unknown type %T for variable %s", v, k) + // everything that's not a string is now HCL encoded + hcl, err = encodeHCL(v) + if err != nil { + break RANGE + } + + tfv.Value = string(hcl) + tfv.IsHCL = true } tfVars = append(tfVars, tfv)