Merge pull request #1712 from justinsb/ff_tf_fmt

Feature flag for tf fmt
This commit is contained in:
Justin Santa Barbara 2017-01-31 02:38:13 -05:00 committed by GitHub
commit 0963204be2
2 changed files with 9 additions and 1 deletions

View File

@ -41,6 +41,9 @@ var DNSPreCreate = New("DNSPreCreate", Bool(true))
// VPCSkipEnableDNSSupport if set will make that a VPC does not need DNSSupport enabled
var VPCSkipEnableDNSSupport = New("VPCSkipEnableDNSSupport", Bool(false))
// SkipTerraformFormat if set will mean that we will not `tf fmt` the generated terraform
var SkipTerraformFormat = New("SkipTerraformFormat", Bool(false))
var flags = make(map[string]*FeatureFlag)
var flagsMutex sync.Mutex

View File

@ -22,6 +22,7 @@ import (
"github.com/golang/glog"
"github.com/hashicorp/hcl/hcl/ast"
hcl_printer "github.com/hashicorp/hcl/hcl/printer"
"k8s.io/kops/pkg/featureflag"
"strings"
)
@ -108,9 +109,13 @@ func hclPrint(node ast.Node) ([]byte, error) {
s = strings.Replace(s, "(\\\"", "(\"", -1)
s = strings.Replace(s, "\\\")", "\")", -1)
if featureflag.SkipTerraformFormat.Enabled() {
glog.Infof("feature-flag SkipTerraformFormat was set; skipping terraform format")
return []byte(s), nil
}
// Apply Terraform style (alignment etc.)
formatted, err := hcl_printer.Format([]byte(s))
if err != nil {
return nil, fmt.Errorf("error formatting HCL: %v", err)
}