mirror of https://github.com/kubernetes/kops.git
Remove TerraformJSON feature flag and functionality
This commit is contained in:
parent
e95e359e3a
commit
e31dd982ac
|
@ -72,8 +72,6 @@ var (
|
|||
VPCSkipEnableDNSSupport = new("VPCSkipEnableDNSSupport", Bool(false))
|
||||
// SkipEtcdVersionCheck will bypass the check that etcd-manager is using a supported etcd version
|
||||
SkipEtcdVersionCheck = new("SkipEtcdVersionCheck", Bool(false))
|
||||
// TerraformJSON outputs terraform in JSON instead of hcl output. JSON output can be also parsed by terraform 0.12
|
||||
TerraformJSON = new("TerraformJSON", Bool(false))
|
||||
// ClusterAddons activates experimental cluster-addons support
|
||||
ClusterAddons = new("ClusterAddons", Bool(false))
|
||||
// Azure toggles the Azure support.
|
||||
|
|
|
@ -7,7 +7,6 @@ go_library(
|
|||
"lifecycle.go",
|
||||
"target.go",
|
||||
"target_hcl2.go",
|
||||
"target_json.go",
|
||||
],
|
||||
importpath = "k8s.io/kops/upup/pkg/fi/cloudup/terraform",
|
||||
visibility = ["//visibility:public"],
|
||||
|
|
|
@ -17,14 +17,12 @@ limitations under the License.
|
|||
package terraform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/featureflag"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
|
@ -94,24 +92,14 @@ func tfGetFilesProviderExtraConfig(c *kops.TargetSpec) map[string]string {
|
|||
}
|
||||
|
||||
func (t *TerraformTarget) Finish(taskMap map[string]fi.Task) error {
|
||||
var err error
|
||||
if featureflag.TerraformJSON.Enabled() {
|
||||
if featureflag.TerraformManagedFiles.Enabled() {
|
||||
// Terraform's JSON representation doesn't support provider aliases which are required for managed files
|
||||
return errors.New("TerraformJSON cannot be used with TerraformManagedFiles")
|
||||
}
|
||||
err = t.finishJSON()
|
||||
} else {
|
||||
err = t.finishHCL2()
|
||||
}
|
||||
if err != nil {
|
||||
if err := t.finishHCL2(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for relativePath, contents := range t.Files {
|
||||
p := path.Join(t.outDir, relativePath)
|
||||
|
||||
err = os.MkdirAll(path.Dir(p), os.FileMode(0o755))
|
||||
err := os.MkdirAll(path.Dir(p), os.FileMode(0o755))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating output directory %q: %v", path.Dir(p), err)
|
||||
}
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
)
|
||||
|
||||
func (t *TerraformTarget) finishJSON() error {
|
||||
resourcesByType, err := t.GetResourcesByType()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
providersByName := make(map[string]map[string]interface{})
|
||||
if t.Cloud.ProviderID() == kops.CloudProviderGCE {
|
||||
providerGoogle := make(map[string]interface{})
|
||||
providerGoogle["project"] = t.Project
|
||||
providerGoogle["region"] = t.Cloud.Region()
|
||||
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
|
||||
providerGoogle[k] = v
|
||||
}
|
||||
providersByName["google"] = providerGoogle
|
||||
} else if t.Cloud.ProviderID() == kops.CloudProviderAWS {
|
||||
providerAWS := make(map[string]interface{})
|
||||
providerAWS["region"] = t.Cloud.Region()
|
||||
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
|
||||
providerAWS[k] = v
|
||||
}
|
||||
providersByName["aws"] = providerAWS
|
||||
}
|
||||
|
||||
outputs, err := t.GetOutputs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outputVariables := make(map[string]interface{})
|
||||
localVariables := make(map[string]interface{})
|
||||
for tfName, v := range outputs {
|
||||
var tfVar interface{}
|
||||
if v.Value != nil {
|
||||
tfVar = v.Value
|
||||
} else {
|
||||
tfVar = v.ValueArray
|
||||
}
|
||||
outputVariables[tfName] = map[string]interface{}{"value": tfVar}
|
||||
localVariables[tfName] = tfVar
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
data["resource"] = resourcesByType
|
||||
if len(providersByName) != 0 {
|
||||
data["provider"] = providersByName
|
||||
}
|
||||
if len(outputVariables) != 0 {
|
||||
data["output"] = outputVariables
|
||||
}
|
||||
if len(localVariables) != 0 {
|
||||
data["locals"] = localVariables
|
||||
}
|
||||
|
||||
terraformConfiguration := make(map[string]interface{})
|
||||
terraformConfiguration["required_version"] = ">= 0.12.26"
|
||||
|
||||
requiredProvidersByName := make(map[string]interface{})
|
||||
if t.Cloud.ProviderID() == kops.CloudProviderGCE {
|
||||
requiredProviderGoogle := make(map[string]interface{})
|
||||
requiredProviderGoogle["source"] = "hashicorp/google"
|
||||
requiredProviderGoogle["version"] = ">= 2.19.0"
|
||||
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
|
||||
requiredProviderGoogle[k] = v
|
||||
}
|
||||
requiredProvidersByName["google"] = requiredProviderGoogle
|
||||
} else if t.Cloud.ProviderID() == kops.CloudProviderAWS {
|
||||
requiredProviderAWS := make(map[string]interface{})
|
||||
requiredProviderAWS["source"] = "hashicorp/aws"
|
||||
requiredProviderAWS["version"] = ">= 3.59.0"
|
||||
for k, v := range tfGetProviderExtraConfig(t.clusterSpecTarget) {
|
||||
requiredProviderAWS[k] = v
|
||||
}
|
||||
requiredProvidersByName["aws"] = requiredProviderAWS
|
||||
}
|
||||
|
||||
if len(requiredProvidersByName) != 0 {
|
||||
terraformConfiguration["required_providers"] = requiredProvidersByName
|
||||
}
|
||||
|
||||
data["terraform"] = terraformConfiguration
|
||||
|
||||
jsonBytes, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error marshaling terraform data to json: %v", err)
|
||||
}
|
||||
|
||||
t.Files["kubernetes.tf.json"] = jsonBytes
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue