mirror of https://github.com/kubernetes/kops.git
Split out TerraformWriter
This commit is contained in:
parent
4e53018cf8
commit
57dec35f68
|
|
@ -70,6 +70,7 @@ go_library(
|
||||||
"//upup/pkg/fi/cloudup/gce:go_default_library",
|
"//upup/pkg/fi/cloudup/gce:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/openstack:go_default_library",
|
"//upup/pkg/fi/cloudup/openstack:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//upup/pkg/fi/loader:go_default_library",
|
"//upup/pkg/fi/loader:go_default_library",
|
||||||
"//util/pkg/architectures:go_default_library",
|
"//util/pkg/architectures:go_default_library",
|
||||||
"//util/pkg/env:go_default_library",
|
"//util/pkg/env:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ go_library(
|
||||||
"//upup/pkg/fi:go_default_library",
|
"//upup/pkg/fi:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/aliup:go_default_library",
|
"//upup/pkg/fi/cloudup/aliup:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests:go_default_library",
|
"//vendor/github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests:go_default_library",
|
||||||
"//vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/slb:go_default_library",
|
"//vendor/github.com/aliyun/alibaba-cloud-sdk-go/services/slb:go_default_library",
|
||||||
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
|
"//vendor/github.com/denverdino/aliyungo/common:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -141,8 +142,8 @@ type terraformEip struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformEipAssociation struct {
|
type terraformEipAssociation struct {
|
||||||
InstanceID *terraform.Literal `json:"instance_id,omitempty" cty:"instance_id"`
|
InstanceID *terraformWriter.Literal `json:"instance_id,omitempty" cty:"instance_id"`
|
||||||
AllocationID *terraform.Literal `json:"allocation_id,omitempty" cty:"allocation_id"`
|
AllocationID *terraformWriter.Literal `json:"allocation_id,omitempty" cty:"allocation_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *EIP) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EIP) error {
|
func (_ *EIP) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EIP) error {
|
||||||
|
|
@ -160,6 +161,6 @@ func (_ *EIP) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EIP)
|
||||||
return t.RenderResource("alicloud_eip_association", *e.Name+"_asso", associationtf)
|
return t.RenderResource("alicloud_eip_association", *e.Name+"_asso", associationtf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EIP) TerraformLink() *terraform.Literal {
|
func (e *EIP) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_eip", *e.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_eip", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ess"
|
"github.com/denverdino/aliyungo/ess"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/kops/pkg/featureflag"
|
"k8s.io/kops/pkg/featureflag"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
|
@ -307,10 +308,10 @@ type terraformLaunchConfiguration struct {
|
||||||
SystemDiskCategory *string `json:"system_disk_category,omitempty" cty:"system_disk_category"`
|
SystemDiskCategory *string `json:"system_disk_category,omitempty" cty:"system_disk_category"`
|
||||||
UserData *string `json:"user_data,omitempty" cty:"user_data"`
|
UserData *string `json:"user_data,omitempty" cty:"user_data"`
|
||||||
|
|
||||||
RAMRole *terraform.Literal `json:"role_name,omitempty" cty:"role_name"`
|
RAMRole *terraformWriter.Literal `json:"role_name,omitempty" cty:"role_name"`
|
||||||
ScalingGroup *terraform.Literal `json:"scaling_group_id,omitempty" cty:"scaling_group_id"`
|
ScalingGroup *terraformWriter.Literal `json:"scaling_group_id,omitempty" cty:"scaling_group_id"`
|
||||||
SSHKey *terraform.Literal `json:"key_name,omitempty" cty:"key_name"`
|
SSHKey *terraformWriter.Literal `json:"key_name,omitempty" cty:"key_name"`
|
||||||
SecurityGroup *terraform.Literal `json:"security_group_id,omitempty" cty:"security_group_id"`
|
SecurityGroup *terraformWriter.Literal `json:"security_group_id,omitempty" cty:"security_group_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *LaunchConfiguration) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LaunchConfiguration) error {
|
func (_ *LaunchConfiguration) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LaunchConfiguration) error {
|
||||||
|
|
@ -336,8 +337,8 @@ func (_ *LaunchConfiguration) RenderTerraform(t *terraform.TerraformTarget, a, e
|
||||||
return t.RenderResource("alicloud_ess_scaling_configuration", *e.Name, tf)
|
return t.RenderResource("alicloud_ess_scaling_configuration", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LaunchConfiguration) TerraformLink() *terraform.Literal {
|
func (l *LaunchConfiguration) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_ess_scaling_configuration", fi.StringValue(l.Name), "id")
|
return terraformWriter.LiteralProperty("alicloud_ess_scaling_configuration", fi.StringValue(l.Name), "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteLaunchConfiguration tracks a LaunchConfiguration that we're going to delete
|
// deleteLaunchConfiguration tracks a LaunchConfiguration that we're going to delete
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/slb"
|
"github.com/denverdino/aliyungo/slb"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||||
|
|
@ -264,6 +265,6 @@ func (_ *LoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e, chang
|
||||||
return t.RenderResource("alicloud_slb", *e.Name, tf)
|
return t.RenderResource("alicloud_slb", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LoadBalancer) TerraformLink() *terraform.Literal {
|
func (l *LoadBalancer) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_slb", *l.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_slb", *l.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/slb"
|
"github.com/denverdino/aliyungo/slb"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
|
@ -149,10 +150,10 @@ func (_ *LoadBalancerListener) RenderALI(t *aliup.ALIAPITarget, a, e, changes *L
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformLoadBalancerListener struct {
|
type terraformLoadBalancerListener struct {
|
||||||
ListenerPort *int `json:"frontend_port,omitempty" cty:"frontend_port"`
|
ListenerPort *int `json:"frontend_port,omitempty" cty:"frontend_port"`
|
||||||
BackendServerPort *int `json:"backend_port,omitempty" cty:"backend_port"`
|
BackendServerPort *int `json:"backend_port,omitempty" cty:"backend_port"`
|
||||||
Protocol *string `json:"protocol,omitempty" cty:"protocol"`
|
Protocol *string `json:"protocol,omitempty" cty:"protocol"`
|
||||||
LoadBalancerId *terraform.Literal `json:"load_balancer_id,omitempty" cty:"load_balancer_id"`
|
LoadBalancerId *terraformWriter.Literal `json:"load_balancer_id,omitempty" cty:"load_balancer_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *LoadBalancerListener) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LoadBalancerListener) error {
|
func (_ *LoadBalancerListener) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *LoadBalancerListener) error {
|
||||||
|
|
@ -167,6 +168,6 @@ func (_ *LoadBalancerListener) RenderTerraform(t *terraform.TerraformTarget, a,
|
||||||
return t.RenderResource("alicloud_slb_listener", *e.Name, tf)
|
return t.RenderResource("alicloud_slb_listener", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *LoadBalancerListener) TerraformLink() *terraform.Literal {
|
func (s *LoadBalancerListener) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_slb_listener", *s.Name, "frontend_port")
|
return terraformWriter.LiteralProperty("alicloud_slb_listener", *s.Name, "frontend_port")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -114,8 +115,8 @@ func (_ *NatGateway) RenderALI(t *aliup.ALIAPITarget, a, e, changes *NatGateway)
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformNatGateway struct {
|
type terraformNatGateway struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
VpcId *terraform.Literal `json:"vpc_id,omitempty" cty:"vpc_id"`
|
VpcId *terraformWriter.Literal `json:"vpc_id,omitempty" cty:"vpc_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *NatGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *NatGateway) error {
|
func (_ *NatGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *NatGateway) error {
|
||||||
|
|
@ -127,6 +128,6 @@ func (_ *NatGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("alicloud_nat_gateway", *e.Name, tf)
|
return t.RenderResource("alicloud_nat_gateway", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NatGateway) TerraformLink() *terraform.Literal {
|
func (e *NatGateway) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_nat_gateway", *e.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_nat_gateway", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ram"
|
"github.com/denverdino/aliyungo/ram"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
|
@ -146,9 +147,9 @@ type terraformRAMPolicy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformRAMPolicyAttach struct {
|
type terraformRAMPolicyAttach struct {
|
||||||
PolicyName *terraform.Literal `json:"policy_name,omitempty" cty:"policy_name"`
|
PolicyName *terraformWriter.Literal `json:"policy_name,omitempty" cty:"policy_name"`
|
||||||
PolicyType *string `json:"policy_type,omitempty" cty:"policy_type"`
|
PolicyType *string `json:"policy_type,omitempty" cty:"policy_type"`
|
||||||
RoleName *terraform.Literal `json:"role_name,omitempty" cty:"role_name"`
|
RoleName *terraformWriter.Literal `json:"role_name,omitempty" cty:"role_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *RAMPolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RAMPolicy) error {
|
func (_ *RAMPolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RAMPolicy) error {
|
||||||
|
|
@ -176,6 +177,6 @@ func (_ *RAMPolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RAMPolicy) TerraformLink() *terraform.Literal {
|
func (s *RAMPolicy) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_ram_policy", *s.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_ram_policy", *s.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ram"
|
"github.com/denverdino/aliyungo/ram"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
|
@ -136,6 +137,6 @@ func (_ *RAMRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *R
|
||||||
return t.RenderResource("alicloud_ram_role", *e.Name, tf)
|
return t.RenderResource("alicloud_ram_role", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *RAMRole) TerraformLink() *terraform.Literal {
|
func (s *RAMRole) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_ram_role", *s.Name, "name")
|
return terraformWriter.LiteralProperty("alicloud_ram_role", *s.Name, "name")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ess"
|
"github.com/denverdino/aliyungo/ess"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||||
|
|
@ -181,8 +182,8 @@ type terraformScalingGroup struct {
|
||||||
MaxSize *int `json:"max_size,omitempty" cty:"max_size"`
|
MaxSize *int `json:"max_size,omitempty" cty:"max_size"`
|
||||||
MinSize *int `json:"min_size,omitempty" cty:"min_size"`
|
MinSize *int `json:"min_size,omitempty" cty:"min_size"`
|
||||||
|
|
||||||
VSwitchs []*terraform.Literal `json:"vswitch_ids,omitempty" cty:"vswitch_ids"`
|
VSwitchs []*terraformWriter.Literal `json:"vswitch_ids,omitempty" cty:"vswitch_ids"`
|
||||||
LoadBalancer []*terraform.Literal `json:"loadbalancer_ids,omitempty" cty:"loadbalancer_ids"`
|
LoadBalancer []*terraformWriter.Literal `json:"loadbalancer_ids,omitempty" cty:"loadbalancer_ids"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *ScalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *ScalingGroup) error {
|
func (_ *ScalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *ScalingGroup) error {
|
||||||
|
|
@ -205,6 +206,6 @@ func (_ *ScalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, chang
|
||||||
return t.RenderResource("alicloud_ess_scaling_group", *e.Name, tf)
|
return t.RenderResource("alicloud_ess_scaling_group", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ScalingGroup) TerraformLink() *terraform.Literal {
|
func (a *ScalingGroup) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_ess_scaling_group", *a.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_ess_scaling_group", *a.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
|
|
@ -184,8 +185,8 @@ func (s *SecurityGroup) getGroupTagsToDelete(currentTags map[string]string) map[
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSecurityGroup struct {
|
type terraformSecurityGroup struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
VPCId *terraform.Literal `json:"vpc_id,omitempty" cty:"vpc_id"`
|
VPCId *terraformWriter.Literal `json:"vpc_id,omitempty" cty:"vpc_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SecurityGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SecurityGroup) error {
|
func (_ *SecurityGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SecurityGroup) error {
|
||||||
|
|
@ -197,6 +198,6 @@ func (_ *SecurityGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, chan
|
||||||
return t.RenderResource("alicloud_security_group", *e.Name, tf)
|
return t.RenderResource("alicloud_security_group", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *SecurityGroup) TerraformLink() *terraform.Literal {
|
func (l *SecurityGroup) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_security_group", *l.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_security_group", *l.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||||
|
|
@ -180,13 +181,13 @@ func (_ *SecurityGroupRule) RenderALI(t *aliup.ALIAPITarget, a, e, changes *Secu
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSecurityGroupRole struct {
|
type terraformSecurityGroupRole struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
Type *string `json:"type,omitempty" cty:"type"`
|
Type *string `json:"type,omitempty" cty:"type"`
|
||||||
IpProtocol *string `json:"ip_protocol,omitempty" cty:"ip_protocol"`
|
IpProtocol *string `json:"ip_protocol,omitempty" cty:"ip_protocol"`
|
||||||
SourceCidrIp *string `json:"cidr_ip,omitempty" cty:"cidr_ip"`
|
SourceCidrIp *string `json:"cidr_ip,omitempty" cty:"cidr_ip"`
|
||||||
SecurityGroupId *terraform.Literal `json:"security_group_id,omitempty" cty:"security_group_id"`
|
SecurityGroupId *terraformWriter.Literal `json:"security_group_id,omitempty" cty:"security_group_id"`
|
||||||
SourceGroupId *terraform.Literal `json:"source_security_group_id,omitempty" cty:"source_security_group_id"`
|
SourceGroupId *terraformWriter.Literal `json:"source_security_group_id,omitempty" cty:"source_security_group_id"`
|
||||||
PortRange *string `json:"port_range,omitempty" cty:"port_range"`
|
PortRange *string `json:"port_range,omitempty" cty:"port_range"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SecurityGroupRule) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SecurityGroupRule) error {
|
func (_ *SecurityGroupRule) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SecurityGroupRule) error {
|
||||||
|
|
@ -217,6 +218,6 @@ func (_ *SecurityGroupRule) RenderTerraform(t *terraform.TerraformTarget, a, e,
|
||||||
return t.RenderResource("alicloud_security_group_rule", *e.Name, tf)
|
return t.RenderResource("alicloud_security_group_rule", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *SecurityGroupRule) TerraformLink() *terraform.Literal {
|
func (l *SecurityGroupRule) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_security_group_rule", *l.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_security_group_rule", *l.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
|
|
||||||
common "github.com/denverdino/aliyungo/common"
|
common "github.com/denverdino/aliyungo/common"
|
||||||
ecs "github.com/denverdino/aliyungo/ecs"
|
ecs "github.com/denverdino/aliyungo/ecs"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kops/pkg/pki"
|
"k8s.io/kops/pkg/pki"
|
||||||
|
|
@ -163,6 +164,6 @@ func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SS
|
||||||
return t.RenderResource("alicloud_key_pair", *e.Name, tf)
|
return t.RenderResource("alicloud_key_pair", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SSHKey) TerraformLink() *terraform.Literal {
|
func (s *SSHKey) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_key_pair", *s.Name, "name")
|
return terraformWriter.LiteralProperty("alicloud_key_pair", *s.Name, "name")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/aliup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -173,6 +174,6 @@ func (_ *VPC) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPC)
|
||||||
return t.RenderResource("alicloud_vpc", *e.Name, tf)
|
return t.RenderResource("alicloud_vpc", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *VPC) TerraformLink() *terraform.Literal {
|
func (e *VPC) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_vpc", *e.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_vpc", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
|
|
@ -175,10 +176,10 @@ func (_ *VSwitch) RenderALI(t *aliup.ALIAPITarget, a, e, changes *VSwitch) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformVSwitch struct {
|
type terraformVSwitch struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
CidrBlock *string `json:"cidr_block,omitempty" cty:"cidr_block"`
|
CidrBlock *string `json:"cidr_block,omitempty" cty:"cidr_block"`
|
||||||
ZoneId *string `json:"availability_zone,omitempty" cty:"availability_zone"`
|
ZoneId *string `json:"availability_zone,omitempty" cty:"availability_zone"`
|
||||||
VPCId *terraform.Literal `json:"vpc_id,omitempty" cty:"vpc_id"`
|
VPCId *terraformWriter.Literal `json:"vpc_id,omitempty" cty:"vpc_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *VSwitch) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VSwitch) error {
|
func (_ *VSwitch) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VSwitch) error {
|
||||||
|
|
@ -192,6 +193,6 @@ func (_ *VSwitch) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *V
|
||||||
return t.RenderResource("alicloud_vswitch", *e.Name, tf)
|
return t.RenderResource("alicloud_vswitch", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VSwitch) TerraformLink() *terraform.Literal {
|
func (v *VSwitch) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("alicloud_vswitch", *v.Name, "id")
|
return terraformWriter.LiteralProperty("alicloud_vswitch", *v.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/denverdino/aliyungo/common"
|
"github.com/denverdino/aliyungo/common"
|
||||||
"github.com/denverdino/aliyungo/ecs"
|
"github.com/denverdino/aliyungo/ecs"
|
||||||
|
|
@ -183,8 +184,8 @@ func (_ *VSwitchSNAT) RenderALI(t *aliup.ALIAPITarget, a, e, changes *VSwitchSNA
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformVSwitchSNAT struct {
|
type terraformVSwitchSNAT struct {
|
||||||
SnatTableId *string `json:"snat_table_id,omitempty" cty:"snat_table_id"`
|
SnatTableId *string `json:"snat_table_id,omitempty" cty:"snat_table_id"`
|
||||||
VSwitchId *terraform.Literal `json:"source_vswitch_id,omitempty" cty:"source_vswitch_id"`
|
VSwitchId *terraformWriter.Literal `json:"source_vswitch_id,omitempty" cty:"source_vswitch_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *VSwitchSNAT) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VSwitchSNAT) error {
|
func (_ *VSwitchSNAT) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VSwitchSNAT) error {
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
|
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
"k8s.io/kops/util/pkg/architectures"
|
"k8s.io/kops/util/pkg/architectures"
|
||||||
"k8s.io/kops/util/pkg/hashing"
|
"k8s.io/kops/util/pkg/hashing"
|
||||||
"k8s.io/kops/util/pkg/mirrors"
|
"k8s.io/kops/util/pkg/mirrors"
|
||||||
|
|
@ -699,17 +700,17 @@ func (c *ApplyClusterCmd) Run(ctx context.Context) error {
|
||||||
tf := terraform.NewTerraformTarget(cloud, project, outDir, cluster.Spec.Target)
|
tf := terraform.NewTerraformTarget(cloud, project, outDir, cluster.Spec.Target)
|
||||||
|
|
||||||
// We include a few "util" variables in the TF output
|
// We include a few "util" variables in the TF output
|
||||||
if err := tf.AddOutputVariable("region", terraform.LiteralFromStringValue(cloud.Region())); err != nil {
|
if err := tf.AddOutputVariable("region", terraformWriter.LiteralFromStringValue(cloud.Region())); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if project != "" {
|
if project != "" {
|
||||||
if err := tf.AddOutputVariable("project", terraform.LiteralFromStringValue(project)); err != nil {
|
if err := tf.AddOutputVariable("project", terraformWriter.LiteralFromStringValue(project)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tf.AddOutputVariable("cluster_name", terraform.LiteralFromStringValue(cluster.ObjectMeta.Name)); err != nil {
|
if err := tf.AddOutputVariable("cluster_name", terraformWriter.LiteralFromStringValue(cluster.ObjectMeta.Name)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ go_library(
|
||||||
"//upup/pkg/fi/cloudup/awsup:go_default_library",
|
"//upup/pkg/fi/cloudup/awsup:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/cloudformation:go_default_library",
|
"//upup/pkg/fi/cloudup/cloudformation:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//upup/pkg/fi/utils:go_default_library",
|
"//upup/pkg/fi/utils:go_default_library",
|
||||||
"//util/pkg/maps:go_default_library",
|
"//util/pkg/maps:go_default_library",
|
||||||
"//util/pkg/slice:go_default_library",
|
"//util/pkg/slice:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
"k8s.io/kops/util/pkg/maps"
|
"k8s.io/kops/util/pkg/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -805,16 +806,16 @@ type terraformASGTag struct {
|
||||||
|
|
||||||
type terraformAutoscalingLaunchTemplateSpecification struct {
|
type terraformAutoscalingLaunchTemplateSpecification struct {
|
||||||
// LaunchTemplateID is the ID of the template to use.
|
// LaunchTemplateID is the ID of the template to use.
|
||||||
LaunchTemplateID *terraform.Literal `json:"id,omitempty" cty:"id"`
|
LaunchTemplateID *terraformWriter.Literal `json:"id,omitempty" cty:"id"`
|
||||||
// Version is the version of the Launch Template to use.
|
// Version is the version of the Launch Template to use.
|
||||||
Version *terraform.Literal `json:"version,omitempty" cty:"version"`
|
Version *terraformWriter.Literal `json:"version,omitempty" cty:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformAutoscalingMixedInstancesPolicyLaunchTemplateSpecification struct {
|
type terraformAutoscalingMixedInstancesPolicyLaunchTemplateSpecification struct {
|
||||||
// LaunchTemplateID is the ID of the template to use
|
// LaunchTemplateID is the ID of the template to use
|
||||||
LaunchTemplateID *terraform.Literal `json:"launch_template_id,omitempty" cty:"launch_template_id"`
|
LaunchTemplateID *terraformWriter.Literal `json:"launch_template_id,omitempty" cty:"launch_template_id"`
|
||||||
// Version is the version of the Launch Template to use
|
// Version is the version of the Launch Template to use
|
||||||
Version *terraform.Literal `json:"version,omitempty" cty:"version"`
|
Version *terraformWriter.Literal `json:"version,omitempty" cty:"version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformAutoscalingMixedInstancesPolicyLaunchTemplateOverride struct {
|
type terraformAutoscalingMixedInstancesPolicyLaunchTemplateOverride struct {
|
||||||
|
|
@ -853,19 +854,19 @@ type terraformMixedInstancesPolicy struct {
|
||||||
|
|
||||||
type terraformAutoscalingGroup struct {
|
type terraformAutoscalingGroup struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
LaunchConfigurationName *terraform.Literal `json:"launch_configuration,omitempty" cty:"launch_configuration"`
|
LaunchConfigurationName *terraformWriter.Literal `json:"launch_configuration,omitempty" cty:"launch_configuration"`
|
||||||
LaunchTemplate *terraformAutoscalingLaunchTemplateSpecification `json:"launch_template,omitempty" cty:"launch_template"`
|
LaunchTemplate *terraformAutoscalingLaunchTemplateSpecification `json:"launch_template,omitempty" cty:"launch_template"`
|
||||||
MaxSize *int64 `json:"max_size,omitempty" cty:"max_size"`
|
MaxSize *int64 `json:"max_size,omitempty" cty:"max_size"`
|
||||||
MinSize *int64 `json:"min_size,omitempty" cty:"min_size"`
|
MinSize *int64 `json:"min_size,omitempty" cty:"min_size"`
|
||||||
MixedInstancesPolicy []*terraformMixedInstancesPolicy `json:"mixed_instances_policy,omitempty" cty:"mixed_instances_policy"`
|
MixedInstancesPolicy []*terraformMixedInstancesPolicy `json:"mixed_instances_policy,omitempty" cty:"mixed_instances_policy"`
|
||||||
VPCZoneIdentifier []*terraform.Literal `json:"vpc_zone_identifier,omitempty" cty:"vpc_zone_identifier"`
|
VPCZoneIdentifier []*terraformWriter.Literal `json:"vpc_zone_identifier,omitempty" cty:"vpc_zone_identifier"`
|
||||||
Tags []*terraformASGTag `json:"tag,omitempty" cty:"tag"`
|
Tags []*terraformASGTag `json:"tag,omitempty" cty:"tag"`
|
||||||
MetricsGranularity *string `json:"metrics_granularity,omitempty" cty:"metrics_granularity"`
|
MetricsGranularity *string `json:"metrics_granularity,omitempty" cty:"metrics_granularity"`
|
||||||
EnabledMetrics []*string `json:"enabled_metrics,omitempty" cty:"enabled_metrics"`
|
EnabledMetrics []*string `json:"enabled_metrics,omitempty" cty:"enabled_metrics"`
|
||||||
SuspendedProcesses []*string `json:"suspended_processes,omitempty" cty:"suspended_processes"`
|
SuspendedProcesses []*string `json:"suspended_processes,omitempty" cty:"suspended_processes"`
|
||||||
InstanceProtection *bool `json:"protect_from_scale_in,omitempty" cty:"protect_from_scale_in"`
|
InstanceProtection *bool `json:"protect_from_scale_in,omitempty" cty:"protect_from_scale_in"`
|
||||||
LoadBalancers []*terraform.Literal `json:"load_balancers,omitempty" cty:"load_balancers"`
|
LoadBalancers []*terraformWriter.Literal `json:"load_balancers,omitempty" cty:"load_balancers"`
|
||||||
TargetGroupARNs []*terraform.Literal `json:"target_group_arns,omitempty" cty:"target_group_arns"`
|
TargetGroupARNs []*terraformWriter.Literal `json:"target_group_arns,omitempty" cty:"target_group_arns"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderTerraform is responsible for rendering the terraform codebase
|
// RenderTerraform is responsible for rendering the terraform codebase
|
||||||
|
|
@ -895,12 +896,12 @@ func (_ *AutoscalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, c
|
||||||
for _, k := range e.LoadBalancers {
|
for _, k := range e.LoadBalancers {
|
||||||
tf.LoadBalancers = append(tf.LoadBalancers, k.TerraformLink())
|
tf.LoadBalancers = append(tf.LoadBalancers, k.TerraformLink())
|
||||||
}
|
}
|
||||||
terraform.SortLiterals(tf.LoadBalancers)
|
terraformWriter.SortLiterals(tf.LoadBalancers)
|
||||||
|
|
||||||
for _, tg := range e.TargetGroups {
|
for _, tg := range e.TargetGroups {
|
||||||
tf.TargetGroupARNs = append(tf.TargetGroupARNs, tg.TerraformLink())
|
tf.TargetGroupARNs = append(tf.TargetGroupARNs, tg.TerraformLink())
|
||||||
}
|
}
|
||||||
terraform.SortLiterals(tf.TargetGroupARNs)
|
terraformWriter.SortLiterals(tf.TargetGroupARNs)
|
||||||
|
|
||||||
if e.UseMixedInstancesPolicy() {
|
if e.UseMixedInstancesPolicy() {
|
||||||
// Temporary warning until https://github.com/terraform-providers/terraform-provider-aws/issues/9750 is resolved
|
// Temporary warning until https://github.com/terraform-providers/terraform-provider-aws/issues/9750 is resolved
|
||||||
|
|
@ -988,8 +989,8 @@ func (_ *AutoscalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, c
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerraformLink fills in the property
|
// TerraformLink fills in the property
|
||||||
func (e *AutoscalingGroup) TerraformLink() *terraform.Literal {
|
func (e *AutoscalingGroup) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_autoscaling_group", fi.StringValue(e.Name), "id")
|
return terraformWriter.LiteralProperty("aws_autoscaling_group", fi.StringValue(e.Name), "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationASGTag struct {
|
type cloudformationASGTag struct {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -120,11 +121,11 @@ func (*AutoscalingLifecycleHook) RenderAWS(t *awsup.AWSAPITarget, a, e, changes
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformASGLifecycleHook struct {
|
type terraformASGLifecycleHook struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
AutoScalingGroupName *terraform.Literal `json:"autoscaling_group_name" cty:"autoscaling_group_name"`
|
AutoScalingGroupName *terraformWriter.Literal `json:"autoscaling_group_name" cty:"autoscaling_group_name"`
|
||||||
DefaultResult *string `json:"default_result" cty:"default_result"`
|
DefaultResult *string `json:"default_result" cty:"default_result"`
|
||||||
HeartbeatTimeout *int64 `json:"heartbeat_timeout" cty:"heartbeat_timeout"`
|
HeartbeatTimeout *int64 `json:"heartbeat_timeout" cty:"heartbeat_timeout"`
|
||||||
LifecycleTransition *string `json:"lifecycle_transition" cty:"lifecycle_transition"`
|
LifecycleTransition *string `json:"lifecycle_transition" cty:"lifecycle_transition"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *AutoscalingLifecycleHook) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *AutoscalingLifecycleHook) error {
|
func (_ *AutoscalingLifecycleHook) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *AutoscalingLifecycleHook) error {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
"k8s.io/kops/util/pkg/slice"
|
"k8s.io/kops/util/pkg/slice"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -699,8 +700,8 @@ func (a OrderLoadBalancersByName) Less(i, j int) bool {
|
||||||
type terraformLoadBalancer struct {
|
type terraformLoadBalancer struct {
|
||||||
LoadBalancerName *string `json:"name" cty:"name"`
|
LoadBalancerName *string `json:"name" cty:"name"`
|
||||||
Listener []*terraformLoadBalancerListener `json:"listener" cty:"listener"`
|
Listener []*terraformLoadBalancerListener `json:"listener" cty:"listener"`
|
||||||
SecurityGroups []*terraform.Literal `json:"security_groups" cty:"security_groups"`
|
SecurityGroups []*terraformWriter.Literal `json:"security_groups" cty:"security_groups"`
|
||||||
Subnets []*terraform.Literal `json:"subnets" cty:"subnets"`
|
Subnets []*terraformWriter.Literal `json:"subnets" cty:"subnets"`
|
||||||
Internal *bool `json:"internal,omitempty" cty:"internal"`
|
Internal *bool `json:"internal,omitempty" cty:"internal"`
|
||||||
|
|
||||||
HealthCheck *terraformLoadBalancerHealthCheck `json:"health_check,omitempty" cty:"health_check"`
|
HealthCheck *terraformLoadBalancerHealthCheck `json:"health_check,omitempty" cty:"health_check"`
|
||||||
|
|
@ -754,12 +755,12 @@ func (_ *ClassicLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e
|
||||||
for _, subnet := range e.Subnets {
|
for _, subnet := range e.Subnets {
|
||||||
tf.Subnets = append(tf.Subnets, subnet.TerraformLink())
|
tf.Subnets = append(tf.Subnets, subnet.TerraformLink())
|
||||||
}
|
}
|
||||||
terraform.SortLiterals(tf.Subnets)
|
terraformWriter.SortLiterals(tf.Subnets)
|
||||||
|
|
||||||
for _, sg := range e.SecurityGroups {
|
for _, sg := range e.SecurityGroups {
|
||||||
tf.SecurityGroups = append(tf.SecurityGroups, sg.TerraformLink())
|
tf.SecurityGroups = append(tf.SecurityGroups, sg.TerraformLink())
|
||||||
}
|
}
|
||||||
terraform.SortLiterals(tf.SecurityGroups)
|
terraformWriter.SortLiterals(tf.SecurityGroups)
|
||||||
|
|
||||||
for loadBalancerPort, listener := range e.Listeners {
|
for loadBalancerPort, listener := range e.Listeners {
|
||||||
loadBalancerPortInt, err := strconv.ParseInt(loadBalancerPort, 10, 64)
|
loadBalancerPortInt, err := strconv.ParseInt(loadBalancerPort, 10, 64)
|
||||||
|
|
@ -827,7 +828,7 @@ func (_ *ClassicLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e
|
||||||
return t.RenderResource("aws_elb", *e.Name, tf)
|
return t.RenderResource("aws_elb", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ClassicLoadBalancer) TerraformLink(params ...string) *terraform.Literal {
|
func (e *ClassicLoadBalancer) TerraformLink(params ...string) *terraformWriter.Literal {
|
||||||
shared := fi.BoolValue(e.Shared)
|
shared := fi.BoolValue(e.Shared)
|
||||||
if shared {
|
if shared {
|
||||||
if e.LoadBalancerName == nil {
|
if e.LoadBalancerName == nil {
|
||||||
|
|
@ -835,14 +836,14 @@ func (e *ClassicLoadBalancer) TerraformLink(params ...string) *terraform.Literal
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(4).Infof("reusing existing LB with name %q", *e.LoadBalancerName)
|
klog.V(4).Infof("reusing existing LB with name %q", *e.LoadBalancerName)
|
||||||
return terraform.LiteralFromStringValue(*e.LoadBalancerName)
|
return terraformWriter.LiteralFromStringValue(*e.LoadBalancerName)
|
||||||
}
|
}
|
||||||
|
|
||||||
prop := "id"
|
prop := "id"
|
||||||
if len(params) > 0 {
|
if len(params) > 0 {
|
||||||
prop = params[0]
|
prop = params[0]
|
||||||
}
|
}
|
||||||
return terraform.LiteralProperty("aws_elb", *e.Name, prop)
|
return terraformWriter.LiteralProperty("aws_elb", *e.Name, prop)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationClassicLoadBalancer struct {
|
type cloudformationClassicLoadBalancer struct {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -189,8 +190,8 @@ func (_ *DHCPOptions) RenderTerraform(t *terraform.TerraformTarget, a, e, change
|
||||||
return t.RenderResource("aws_vpc_dhcp_options", *e.Name, tf)
|
return t.RenderResource("aws_vpc_dhcp_options", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *DHCPOptions) TerraformLink() *terraform.Literal {
|
func (e *DHCPOptions) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_vpc_dhcp_options", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_vpc_dhcp_options", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationDHCPOptions struct {
|
type cloudformationDHCPOptions struct {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -49,7 +50,7 @@ type DNSTarget interface {
|
||||||
getHostedZoneId() *string
|
getHostedZoneId() *string
|
||||||
CloudformationAttrDNSName() *cloudformation.Literal
|
CloudformationAttrDNSName() *cloudformation.Literal
|
||||||
CloudformationAttrCanonicalHostedZoneNameID() *cloudformation.Literal
|
CloudformationAttrCanonicalHostedZoneNameID() *cloudformation.Literal
|
||||||
TerraformLink(...string) *terraform.Literal
|
TerraformLink(...string) *terraformWriter.Literal
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *DNSName) Find(c *fi.Context) (*DNSName, error) {
|
func (e *DNSName) Find(c *fi.Context) (*DNSName, error) {
|
||||||
|
|
@ -290,14 +291,14 @@ type terraformRoute53Record struct {
|
||||||
TTL *string `json:"ttl,omitempty" cty:"ttl"`
|
TTL *string `json:"ttl,omitempty" cty:"ttl"`
|
||||||
Records []string `json:"records,omitempty" cty:"records"`
|
Records []string `json:"records,omitempty" cty:"records"`
|
||||||
|
|
||||||
Alias *terraformAlias `json:"alias,omitempty" cty:"alias"`
|
Alias *terraformAlias `json:"alias,omitempty" cty:"alias"`
|
||||||
ZoneID *terraform.Literal `json:"zone_id" cty:"zone_id"`
|
ZoneID *terraformWriter.Literal `json:"zone_id" cty:"zone_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformAlias struct {
|
type terraformAlias struct {
|
||||||
Name *terraform.Literal `json:"name" cty:"name"`
|
Name *terraformWriter.Literal `json:"name" cty:"name"`
|
||||||
ZoneID *terraform.Literal `json:"zone_id" cty:"zone_id"`
|
ZoneID *terraformWriter.Literal `json:"zone_id" cty:"zone_id"`
|
||||||
EvaluateTargetHealth *bool `json:"evaluate_target_health" cty:"evaluate_target_health"`
|
EvaluateTargetHealth *bool `json:"evaluate_target_health" cty:"evaluate_target_health"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *DNSName) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *DNSName) error {
|
func (_ *DNSName) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *DNSName) error {
|
||||||
|
|
@ -318,8 +319,8 @@ func (_ *DNSName) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *D
|
||||||
return t.RenderResource("aws_route53_record", *e.Name, tf)
|
return t.RenderResource("aws_route53_record", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *DNSName) TerraformLink() *terraform.Literal {
|
func (e *DNSName) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralSelfLink("aws_route53_record", *e.Name)
|
return terraformWriter.LiteralSelfLink("aws_route53_record", *e.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationRoute53Record struct {
|
type cloudformationRoute53Record struct {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DNSZone is a zone object in a dns provider
|
// DNSZone is a zone object in a dns provider
|
||||||
|
|
@ -226,9 +227,9 @@ func (_ *DNSZone) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *DNSZone) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformRoute53ZoneAssociation struct {
|
type terraformRoute53ZoneAssociation struct {
|
||||||
ZoneID *terraform.Literal `json:"zone_id" cty:"zone_id"`
|
ZoneID *terraformWriter.Literal `json:"zone_id" cty:"zone_id"`
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
Lifecycle *terraform.Lifecycle `json:"lifecycle,omitempty" cty:"lifecycle"`
|
Lifecycle *terraform.Lifecycle `json:"lifecycle,omitempty" cty:"lifecycle"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *DNSZone) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *DNSZone) error {
|
func (_ *DNSZone) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *DNSZone) error {
|
||||||
|
|
@ -271,7 +272,7 @@ func (_ *DNSZone) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *D
|
||||||
if assocNeeded {
|
if assocNeeded {
|
||||||
klog.Infof("No association between VPC %q and zone %q; adding", vpcName, aws.StringValue(z.HostedZone.Name))
|
klog.Infof("No association between VPC %q and zone %q; adding", vpcName, aws.StringValue(z.HostedZone.Name))
|
||||||
tf := &terraformRoute53ZoneAssociation{
|
tf := &terraformRoute53ZoneAssociation{
|
||||||
ZoneID: terraform.LiteralFromStringValue(*e.ZoneID),
|
ZoneID: terraformWriter.LiteralFromStringValue(*e.ZoneID),
|
||||||
VPCID: e.PrivateVPC.TerraformLink(),
|
VPCID: e.PrivateVPC.TerraformLink(),
|
||||||
}
|
}
|
||||||
return t.RenderResource("aws_route53_zone_association", *e.Name, tf)
|
return t.RenderResource("aws_route53_zone_association", *e.Name, tf)
|
||||||
|
|
@ -290,13 +291,13 @@ func (_ *DNSZone) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *D
|
||||||
return fmt.Errorf("Creation of Route53 hosted zones is not supported for terraform")
|
return fmt.Errorf("Creation of Route53 hosted zones is not supported for terraform")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *DNSZone) TerraformLink() *terraform.Literal {
|
func (e *DNSZone) TerraformLink() *terraformWriter.Literal {
|
||||||
if e.ZoneID != nil {
|
if e.ZoneID != nil {
|
||||||
klog.V(4).Infof("reusing existing route53 zone with id %q", *e.ZoneID)
|
klog.V(4).Infof("reusing existing route53 zone with id %q", *e.ZoneID)
|
||||||
return terraform.LiteralFromStringValue(*e.ZoneID)
|
return terraformWriter.LiteralFromStringValue(*e.ZoneID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralSelfLink("aws_route53_zone", *e.Name)
|
return terraformWriter.LiteralSelfLink("aws_route53_zone", *e.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationRoute53Zone struct {
|
type cloudformationRoute53Zone struct {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
@ -243,9 +244,9 @@ func (_ *EBSVolume) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("aws_ebs_volume", tfName, tf)
|
return t.RenderResource("aws_ebs_volume", tfName, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EBSVolume) TerraformLink() *terraform.Literal {
|
func (e *EBSVolume) TerraformLink() *terraformWriter.Literal {
|
||||||
tfName, _ := e.TerraformName()
|
tfName, _ := e.TerraformName()
|
||||||
return terraform.LiteralSelfLink("aws_ebs_volume", tfName)
|
return terraformWriter.LiteralSelfLink("aws_ebs_volume", tfName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerraformName returns the terraform-safe name, along with a boolean indicating of whether name-prefixing was needed.
|
// TerraformName returns the terraform-safe name, along with a boolean indicating of whether name-prefixing was needed.
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
|
|
@ -292,15 +293,15 @@ func (_ *ElasticIP) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("aws_eip", *e.Name, tf)
|
return t.RenderResource("aws_eip", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ElasticIP) TerraformLink() *terraform.Literal {
|
func (e *ElasticIP) TerraformLink() *terraformWriter.Literal {
|
||||||
if fi.BoolValue(e.Shared) {
|
if fi.BoolValue(e.Shared) {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
klog.Fatalf("ID must be set, if ElasticIP is shared: %v", e)
|
klog.Fatalf("ID must be set, if ElasticIP is shared: %v", e)
|
||||||
}
|
}
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralProperty("aws_eip", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_eip", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationElasticIP struct {
|
type cloudformationElasticIP struct {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -126,9 +127,9 @@ func (eb *EventBridgeRule) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Event
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformEventBridgeRule struct {
|
type terraformEventBridgeRule struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
EventPattern *terraform.Literal `json:"event_pattern" cty:"event_pattern"`
|
EventPattern *terraformWriter.Literal `json:"event_pattern" cty:"event_pattern"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *EventBridgeRule) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EventBridgeRule) error {
|
func (_ *EventBridgeRule) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EventBridgeRule) error {
|
||||||
|
|
@ -146,8 +147,8 @@ func (_ *EventBridgeRule) RenderTerraform(t *terraform.TerraformTarget, a, e, ch
|
||||||
return t.RenderResource("aws_cloudwatch_event_rule", *e.Name, tf)
|
return t.RenderResource("aws_cloudwatch_event_rule", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eb *EventBridgeRule) TerraformLink() *terraform.Literal {
|
func (eb *EventBridgeRule) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_cloudwatch_event_rule", fi.StringValue(eb.Name), "id")
|
return terraformWriter.LiteralProperty("aws_cloudwatch_event_rule", fi.StringValue(eb.Name), "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationTarget struct {
|
type cloudformationTarget struct {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/eventbridge"
|
"github.com/aws/aws-sdk-go/service/eventbridge"
|
||||||
|
|
@ -127,8 +128,8 @@ func (eb *EventBridgeTarget) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Eve
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformEventBridgeTarget struct {
|
type terraformEventBridgeTarget struct {
|
||||||
RuleName *terraform.Literal `json:"rule" cty:"rule"`
|
RuleName *terraformWriter.Literal `json:"rule" cty:"rule"`
|
||||||
TargetArn *string `json:"arn" cty:"arn"`
|
TargetArn *string `json:"arn" cty:"arn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *EventBridgeTarget) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EventBridgeTarget) error {
|
func (_ *EventBridgeTarget) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *EventBridgeTarget) error {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
|
|
@ -165,11 +166,11 @@ func (_ *IAMInstanceProfile) RenderTerraform(t *terraform.TerraformTarget, a, e,
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *IAMInstanceProfile) TerraformLink() *terraform.Literal {
|
func (e *IAMInstanceProfile) TerraformLink() *terraformWriter.Literal {
|
||||||
if fi.BoolValue(e.Shared) {
|
if fi.BoolValue(e.Shared) {
|
||||||
return terraform.LiteralFromStringValue(fi.StringValue(e.Name))
|
return terraformWriter.LiteralFromStringValue(fi.StringValue(e.Name))
|
||||||
}
|
}
|
||||||
return terraform.LiteralProperty("aws_iam_instance_profile", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_iam_instance_profile", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *IAMInstanceProfile) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *IAMInstanceProfile) error {
|
func (_ *IAMInstanceProfile) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *IAMInstanceProfile) error {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -110,9 +111,9 @@ func (_ *IAMInstanceProfileRole) RenderAWS(t *awsup.AWSAPITarget, a, e, changes
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformIAMInstanceProfile struct {
|
type terraformIAMInstanceProfile struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
Role *terraform.Literal `json:"role" cty:"role"`
|
Role *terraformWriter.Literal `json:"role" cty:"role"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *IAMInstanceProfileRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMInstanceProfileRole) error {
|
func (_ *IAMInstanceProfileRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMInstanceProfileRole) error {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -186,8 +187,8 @@ type terraformIAMOIDCProvider struct {
|
||||||
ClientIDList []*string `json:"client_id_list" cty:"client_id_list"`
|
ClientIDList []*string `json:"client_id_list" cty:"client_id_list"`
|
||||||
ThumbprintList []*string `json:"thumbprint_list" cty:"thumbprint_list"`
|
ThumbprintList []*string `json:"thumbprint_list" cty:"thumbprint_list"`
|
||||||
|
|
||||||
AssumeRolePolicy *terraform.Literal `json:"assume_role_policy" cty:"assume_role_policy"`
|
AssumeRolePolicy *terraformWriter.Literal `json:"assume_role_policy" cty:"assume_role_policy"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *IAMOIDCProvider) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMOIDCProvider) error {
|
func (p *IAMOIDCProvider) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMOIDCProvider) error {
|
||||||
|
|
@ -202,8 +203,8 @@ func (p *IAMOIDCProvider) RenderTerraform(t *terraform.TerraformTarget, a, e, ch
|
||||||
return t.RenderResource("aws_iam_openid_connect_provider", *e.Name, tf)
|
return t.RenderResource("aws_iam_openid_connect_provider", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *IAMOIDCProvider) TerraformLink() *terraform.Literal {
|
func (e *IAMOIDCProvider) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_iam_openid_connect_provider", *e.Name, "arn")
|
return terraformWriter.LiteralProperty("aws_iam_openid_connect_provider", *e.Name, "arn")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *IAMOIDCProvider) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *IAMOIDCProvider) error {
|
func (_ *IAMOIDCProvider) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *IAMOIDCProvider) error {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -251,10 +252,10 @@ func (_ *IAMRole) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *IAMRole) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformIAMRole struct {
|
type terraformIAMRole struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
AssumeRolePolicy *terraform.Literal `json:"assume_role_policy" cty:"assume_role_policy"`
|
AssumeRolePolicy *terraformWriter.Literal `json:"assume_role_policy" cty:"assume_role_policy"`
|
||||||
PermissionsBoundary *string `json:"permissions_boundary,omitempty" cty:"permissions_boundary"`
|
PermissionsBoundary *string `json:"permissions_boundary,omitempty" cty:"permissions_boundary"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *IAMRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMRole) error {
|
func (_ *IAMRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMRole) error {
|
||||||
|
|
@ -274,15 +275,15 @@ func (_ *IAMRole) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *I
|
||||||
}
|
}
|
||||||
|
|
||||||
if fi.StringValue(e.ExportWithID) != "" {
|
if fi.StringValue(e.ExportWithID) != "" {
|
||||||
t.AddOutputVariable(*e.ExportWithID+"_role_arn", terraform.LiteralProperty("aws_iam_role", *e.Name, "arn"))
|
t.AddOutputVariable(*e.ExportWithID+"_role_arn", terraformWriter.LiteralProperty("aws_iam_role", *e.Name, "arn"))
|
||||||
t.AddOutputVariable(*e.ExportWithID+"_role_name", e.TerraformLink())
|
t.AddOutputVariable(*e.ExportWithID+"_role_name", e.TerraformLink())
|
||||||
}
|
}
|
||||||
|
|
||||||
return t.RenderResource("aws_iam_role", *e.Name, tf)
|
return t.RenderResource("aws_iam_role", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *IAMRole) TerraformLink() *terraform.Literal {
|
func (e *IAMRole) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_iam_role", *e.Name, "name")
|
return terraformWriter.LiteralProperty("aws_iam_role", *e.Name, "name")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationIAMRole struct {
|
type cloudformationIAMRole struct {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -294,10 +295,10 @@ func (e *IAMRolePolicy) policyDocumentString() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformIAMRolePolicy struct {
|
type terraformIAMRolePolicy struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
Role *terraform.Literal `json:"role" cty:"role"`
|
Role *terraformWriter.Literal `json:"role" cty:"role"`
|
||||||
PolicyDocument *terraform.Literal `json:"policy,omitempty" cty:"policy"`
|
PolicyDocument *terraformWriter.Literal `json:"policy,omitempty" cty:"policy"`
|
||||||
PolicyArn *string `json:"policy_arn,omitempty" cty:"policy_arn"`
|
PolicyArn *string `json:"policy_arn,omitempty" cty:"policy_arn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *IAMRolePolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMRolePolicy) error {
|
func (_ *IAMRolePolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *IAMRolePolicy) error {
|
||||||
|
|
@ -345,8 +346,8 @@ func (_ *IAMRolePolicy) RenderTerraform(t *terraform.TerraformTarget, a, e, chan
|
||||||
return t.RenderResource("aws_iam_role_policy", *e.Name, tf)
|
return t.RenderResource("aws_iam_role_policy", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *IAMRolePolicy) TerraformLink() *terraform.Literal {
|
func (e *IAMRolePolicy) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralSelfLink("aws_iam_role_policy", *e.Name)
|
return terraformWriter.LiteralSelfLink("aws_iam_role_policy", *e.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationIAMRolePolicy struct {
|
type cloudformationIAMRolePolicy struct {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MaxUserDataSize is the max size of the userdata
|
// MaxUserDataSize is the max size of the userdata
|
||||||
|
|
@ -297,14 +297,14 @@ func (_ *Instance) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Instance) err
|
||||||
return t.AddAWSTags(*e.ID, e.Tags)
|
return t.AddAWSTags(*e.ID, e.Tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Instance) TerraformLink() *terraform.Literal {
|
func (e *Instance) TerraformLink() *terraformWriter.Literal {
|
||||||
if fi.BoolValue(e.Shared) {
|
if fi.BoolValue(e.Shared) {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
klog.Fatalf("ID must be set, if NAT Instance is shared: %s", e)
|
klog.Fatalf("ID must be set, if NAT Instance is shared: %s", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralSelfLink("aws_instance", *e.Name)
|
return terraformWriter.LiteralSelfLink("aws_instance", *e.Name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -179,8 +180,8 @@ func (_ *InternetGateway) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Intern
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformInternetGateway struct {
|
type terraformInternetGateway struct {
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *InternetGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *InternetGateway) error {
|
func (_ *InternetGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *InternetGateway) error {
|
||||||
|
|
@ -218,7 +219,7 @@ func (_ *InternetGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, ch
|
||||||
return t.RenderResource("aws_internet_gateway", *e.Name, tf)
|
return t.RenderResource("aws_internet_gateway", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *InternetGateway) TerraformLink() *terraform.Literal {
|
func (e *InternetGateway) TerraformLink() *terraformWriter.Literal {
|
||||||
shared := fi.BoolValue(e.Shared)
|
shared := fi.BoolValue(e.Shared)
|
||||||
if shared {
|
if shared {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
|
|
@ -226,10 +227,10 @@ func (e *InternetGateway) TerraformLink() *terraform.Literal {
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(4).Infof("reusing existing InternetGateway with id %q", *e.ID)
|
klog.V(4).Infof("reusing existing InternetGateway with id %q", *e.ID)
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralProperty("aws_internet_gateway", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_internet_gateway", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationInternetGateway struct {
|
type cloudformationInternetGateway struct {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
type terraformLaunchTemplateNetworkInterface struct {
|
type terraformLaunchTemplateNetworkInterface struct {
|
||||||
|
|
@ -31,7 +32,7 @@ type terraformLaunchTemplateNetworkInterface struct {
|
||||||
// DeleteOnTermination indicates whether the network interface should be destroyed on instance termination.
|
// DeleteOnTermination indicates whether the network interface should be destroyed on instance termination.
|
||||||
DeleteOnTermination *bool `json:"delete_on_termination,omitempty" cty:"delete_on_termination"`
|
DeleteOnTermination *bool `json:"delete_on_termination,omitempty" cty:"delete_on_termination"`
|
||||||
// SecurityGroups is a list of security group ids.
|
// SecurityGroups is a list of security group ids.
|
||||||
SecurityGroups []*terraform.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
SecurityGroups []*terraformWriter.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformLaunchTemplateMonitoring struct {
|
type terraformLaunchTemplateMonitoring struct {
|
||||||
|
|
@ -56,7 +57,7 @@ type terraformLaunchTemplatePlacement struct {
|
||||||
|
|
||||||
type terraformLaunchTemplateIAMProfile struct {
|
type terraformLaunchTemplateIAMProfile struct {
|
||||||
// Name is the name of the profile
|
// Name is the name of the profile
|
||||||
Name *terraform.Literal `json:"name,omitempty" cty:"name"`
|
Name *terraformWriter.Literal `json:"name,omitempty" cty:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformLaunchTemplateMarketOptionsSpotOptions struct {
|
type terraformLaunchTemplateMarketOptionsSpotOptions struct {
|
||||||
|
|
@ -144,7 +145,7 @@ type terraformLaunchTemplate struct {
|
||||||
// InstanceType is the type of instance
|
// InstanceType is the type of instance
|
||||||
InstanceType *string `json:"instance_type,omitempty" cty:"instance_type"`
|
InstanceType *string `json:"instance_type,omitempty" cty:"instance_type"`
|
||||||
// KeyName is the ssh key to use
|
// KeyName is the ssh key to use
|
||||||
KeyName *terraform.Literal `json:"key_name,omitempty" cty:"key_name"`
|
KeyName *terraformWriter.Literal `json:"key_name,omitempty" cty:"key_name"`
|
||||||
// MarketOptions are the spot pricing options
|
// MarketOptions are the spot pricing options
|
||||||
MarketOptions []*terraformLaunchTemplateMarketOptions `json:"instance_market_options,omitempty" cty:"instance_market_options"`
|
MarketOptions []*terraformLaunchTemplateMarketOptions `json:"instance_market_options,omitempty" cty:"instance_market_options"`
|
||||||
// MetadataOptions are the instance metadata options.
|
// MetadataOptions are the instance metadata options.
|
||||||
|
|
@ -160,17 +161,17 @@ type terraformLaunchTemplate struct {
|
||||||
// TagSpecifications are the tags to apply to a resource when it is created.
|
// TagSpecifications are the tags to apply to a resource when it is created.
|
||||||
TagSpecifications []*terraformLaunchTemplateTagSpecification `json:"tag_specifications,omitempty" cty:"tag_specifications"`
|
TagSpecifications []*terraformLaunchTemplateTagSpecification `json:"tag_specifications,omitempty" cty:"tag_specifications"`
|
||||||
// UserData is the user data for the instances
|
// UserData is the user data for the instances
|
||||||
UserData *terraform.Literal `json:"user_data,omitempty" cty:"user_data"`
|
UserData *terraformWriter.Literal `json:"user_data,omitempty" cty:"user_data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerraformLink returns the terraform reference
|
// TerraformLink returns the terraform reference
|
||||||
func (t *LaunchTemplate) TerraformLink() *terraform.Literal {
|
func (t *LaunchTemplate) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_launch_template", fi.StringValue(t.Name), "id")
|
return terraformWriter.LiteralProperty("aws_launch_template", fi.StringValue(t.Name), "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionLink returns the terraform version reference
|
// VersionLink returns the terraform version reference
|
||||||
func (t *LaunchTemplate) VersionLink() *terraform.Literal {
|
func (t *LaunchTemplate) VersionLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_launch_template", fi.StringValue(t.Name), "latest_version")
|
return terraformWriter.LiteralProperty("aws_launch_template", fi.StringValue(t.Name), "latest_version")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderTerraform is responsible for rendering the terraform json
|
// RenderTerraform is responsible for rendering the terraform json
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -361,9 +362,9 @@ func (_ *NatGateway) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *NatGateway)
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformNATGateway struct {
|
type terraformNATGateway struct {
|
||||||
AllocationID *terraform.Literal `json:"allocation_id,omitempty" cty:"allocation_id"`
|
AllocationID *terraformWriter.Literal `json:"allocation_id,omitempty" cty:"allocation_id"`
|
||||||
SubnetID *terraform.Literal `json:"subnet_id,omitempty" cty:"subnet_id"`
|
SubnetID *terraformWriter.Literal `json:"subnet_id,omitempty" cty:"subnet_id"`
|
||||||
Tag map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tag map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *NatGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *NatGateway) error {
|
func (_ *NatGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *NatGateway) error {
|
||||||
|
|
@ -385,16 +386,16 @@ func (_ *NatGateway) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("aws_nat_gateway", *e.Name, tf)
|
return t.RenderResource("aws_nat_gateway", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NatGateway) TerraformLink() *terraform.Literal {
|
func (e *NatGateway) TerraformLink() *terraformWriter.Literal {
|
||||||
if fi.BoolValue(e.Shared) {
|
if fi.BoolValue(e.Shared) {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
klog.Fatalf("ID must be set, if NatGateway is shared: %s", e)
|
klog.Fatalf("ID must be set, if NatGateway is shared: %s", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralProperty("aws_nat_gateway", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_nat_gateway", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationNATGateway struct {
|
type cloudformationNATGateway struct {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NetworkLoadBalancer manages an NLB. We find the existing NLB using the Name tag.
|
// NetworkLoadBalancer manages an NLB. We find the existing NLB using the Name tag.
|
||||||
|
|
@ -736,13 +737,13 @@ type terraformNetworkLoadBalancer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformNetworkLoadBalancerSubnetMapping struct {
|
type terraformNetworkLoadBalancerSubnetMapping struct {
|
||||||
Subnet *terraform.Literal `json:"subnet_id" cty:"subnet_id"`
|
Subnet *terraformWriter.Literal `json:"subnet_id" cty:"subnet_id"`
|
||||||
AllocationID *string `json:"allocation_id,omitempty" cty:"allocation_id"`
|
AllocationID *string `json:"allocation_id,omitempty" cty:"allocation_id"`
|
||||||
PrivateIPv4Address *string `json:"private_ipv4_address,omitempty" cty:"private_ipv4_address"`
|
PrivateIPv4Address *string `json:"private_ipv4_address,omitempty" cty:"private_ipv4_address"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformNetworkLoadBalancerListener struct {
|
type terraformNetworkLoadBalancerListener struct {
|
||||||
LoadBalancer *terraform.Literal `json:"load_balancer_arn" cty:"load_balancer_arn"`
|
LoadBalancer *terraformWriter.Literal `json:"load_balancer_arn" cty:"load_balancer_arn"`
|
||||||
Port int64 `json:"port" cty:"port"`
|
Port int64 `json:"port" cty:"port"`
|
||||||
Protocol string `json:"protocol" cty:"protocol"`
|
Protocol string `json:"protocol" cty:"protocol"`
|
||||||
CertificateARN *string `json:"certificate_arn,omitempty" cty:"certificate_arn"`
|
CertificateARN *string `json:"certificate_arn,omitempty" cty:"certificate_arn"`
|
||||||
|
|
@ -751,8 +752,8 @@ type terraformNetworkLoadBalancerListener struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformNetworkLoadBalancerListenerAction struct {
|
type terraformNetworkLoadBalancerListenerAction struct {
|
||||||
Type string `json:"type" cty:"type"`
|
Type string `json:"type" cty:"type"`
|
||||||
TargetGroupARN *terraform.Literal `json:"target_group_arn,omitempty" cty:"target_group_arn"`
|
TargetGroupARN *terraformWriter.Literal `json:"target_group_arn,omitempty" cty:"target_group_arn"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *NetworkLoadBalancer) error {
|
func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *NetworkLoadBalancer) error {
|
||||||
|
|
@ -816,12 +817,12 @@ func (_ *NetworkLoadBalancer) RenderTerraform(t *terraform.TerraformTarget, a, e
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *NetworkLoadBalancer) TerraformLink(params ...string) *terraform.Literal {
|
func (e *NetworkLoadBalancer) TerraformLink(params ...string) *terraformWriter.Literal {
|
||||||
prop := "id"
|
prop := "id"
|
||||||
if len(params) > 0 {
|
if len(params) > 0 {
|
||||||
prop = params[0]
|
prop = params[0]
|
||||||
}
|
}
|
||||||
return terraform.LiteralProperty("aws_lb", *e.Name, prop)
|
return terraformWriter.LiteralProperty("aws_lb", *e.Name, prop)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationNetworkLoadBalancer struct {
|
type cloudformationNetworkLoadBalancer struct {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -236,12 +237,12 @@ func checkNotNil(s *string) *string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformRoute struct {
|
type terraformRoute struct {
|
||||||
RouteTableID *terraform.Literal `json:"route_table_id" cty:"route_table_id"`
|
RouteTableID *terraformWriter.Literal `json:"route_table_id" cty:"route_table_id"`
|
||||||
CIDR *string `json:"destination_cidr_block,omitempty" cty:"destination_cidr_block"`
|
CIDR *string `json:"destination_cidr_block,omitempty" cty:"destination_cidr_block"`
|
||||||
InternetGatewayID *terraform.Literal `json:"gateway_id,omitempty" cty:"gateway_id"`
|
InternetGatewayID *terraformWriter.Literal `json:"gateway_id,omitempty" cty:"gateway_id"`
|
||||||
NATGatewayID *terraform.Literal `json:"nat_gateway_id,omitempty" cty:"nat_gateway_id"`
|
NATGatewayID *terraformWriter.Literal `json:"nat_gateway_id,omitempty" cty:"nat_gateway_id"`
|
||||||
TransitGatewayID *string `json:"transit_gateway_id,omitempty" cty:"transit_gateway_id"`
|
TransitGatewayID *string `json:"transit_gateway_id,omitempty" cty:"transit_gateway_id"`
|
||||||
InstanceID *terraform.Literal `json:"instance_id,omitempty" cty:"instance_id"`
|
InstanceID *terraformWriter.Literal `json:"instance_id,omitempty" cty:"instance_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *Route) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Route) error {
|
func (_ *Route) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Route) error {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -191,8 +192,8 @@ func (_ *RouteTable) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *RouteTable)
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformRouteTable struct {
|
type terraformRouteTable struct {
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *RouteTable) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RouteTable) error {
|
func (_ *RouteTable) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RouteTable) error {
|
||||||
|
|
@ -212,8 +213,8 @@ func (_ *RouteTable) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("aws_route_table", *e.Name, tf)
|
return t.RenderResource("aws_route_table", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *RouteTable) TerraformLink() *terraform.Literal {
|
func (e *RouteTable) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("aws_route_table", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_route_table", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationRouteTable struct {
|
type cloudformationRouteTable struct {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -187,8 +188,8 @@ func (_ *RouteTableAssociation) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformRouteTableAssociation struct {
|
type terraformRouteTableAssociation struct {
|
||||||
SubnetID *terraform.Literal `json:"subnet_id" cty:"subnet_id"`
|
SubnetID *terraformWriter.Literal `json:"subnet_id" cty:"subnet_id"`
|
||||||
RouteTableID *terraform.Literal `json:"route_table_id" cty:"route_table_id"`
|
RouteTableID *terraformWriter.Literal `json:"route_table_id" cty:"route_table_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *RouteTableAssociation) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RouteTableAssociation) error {
|
func (_ *RouteTableAssociation) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *RouteTableAssociation) error {
|
||||||
|
|
@ -200,8 +201,8 @@ func (_ *RouteTableAssociation) RenderTerraform(t *terraform.TerraformTarget, a,
|
||||||
return t.RenderResource("aws_route_table_association", *e.Name, tf)
|
return t.RenderResource("aws_route_table_association", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *RouteTableAssociation) TerraformLink() *terraform.Literal {
|
func (e *RouteTableAssociation) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralSelfLink("aws_route_table_association", *e.Name)
|
return terraformWriter.LiteralSelfLink("aws_route_table_association", *e.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationRouteTableAssociation struct {
|
type cloudformationRouteTableAssociation struct {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -184,10 +185,10 @@ func (_ *SecurityGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Security
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSecurityGroup struct {
|
type terraformSecurityGroup struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
Description *string `json:"description" cty:"description"`
|
Description *string `json:"description" cty:"description"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SecurityGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SecurityGroup) error {
|
func (_ *SecurityGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SecurityGroup) error {
|
||||||
|
|
@ -207,18 +208,18 @@ func (_ *SecurityGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, chan
|
||||||
return t.RenderResource("aws_security_group", *e.Name, tf)
|
return t.RenderResource("aws_security_group", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SecurityGroup) TerraformLink() *terraform.Literal {
|
func (e *SecurityGroup) TerraformLink() *terraformWriter.Literal {
|
||||||
shared := fi.BoolValue(e.Shared)
|
shared := fi.BoolValue(e.Shared)
|
||||||
if shared {
|
if shared {
|
||||||
// Not terraform owned / managed
|
// Not terraform owned / managed
|
||||||
if e.ID != nil {
|
if e.ID != nil {
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
} else {
|
} else {
|
||||||
klog.Warningf("ID not set on shared subnet %v", e)
|
klog.Warningf("ID not set on shared subnet %v", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralProperty("aws_security_group", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_security_group", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationSecurityGroup struct {
|
type cloudformationSecurityGroup struct {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -293,8 +294,8 @@ func (_ *SecurityGroupRule) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Secu
|
||||||
type terraformSecurityGroupIngress struct {
|
type terraformSecurityGroupIngress struct {
|
||||||
Type *string `json:"type" cty:"type"`
|
Type *string `json:"type" cty:"type"`
|
||||||
|
|
||||||
SecurityGroup *terraform.Literal `json:"security_group_id" cty:"security_group_id"`
|
SecurityGroup *terraformWriter.Literal `json:"security_group_id" cty:"security_group_id"`
|
||||||
SourceGroup *terraform.Literal `json:"source_security_group_id,omitempty" cty:"source_security_group_id"`
|
SourceGroup *terraformWriter.Literal `json:"source_security_group_id,omitempty" cty:"source_security_group_id"`
|
||||||
|
|
||||||
FromPort *int64 `json:"from_port,omitempty" cty:"from_port"`
|
FromPort *int64 `json:"from_port,omitempty" cty:"from_port"`
|
||||||
ToPort *int64 `json:"to_port,omitempty" cty:"to_port"`
|
ToPort *int64 `json:"to_port,omitempty" cty:"to_port"`
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/sqs"
|
"github.com/aws/aws-sdk-go/service/sqs"
|
||||||
|
|
@ -176,10 +177,10 @@ func (q *SQS) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *SQS) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSQSQueue struct {
|
type terraformSQSQueue struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
MessageRetentionSeconds int `json:"message_retention_seconds" cty:"message_retention_seconds"`
|
MessageRetentionSeconds int `json:"message_retention_seconds" cty:"message_retention_seconds"`
|
||||||
Policy *terraform.Literal `json:"policy" cty:"policy"`
|
Policy *terraformWriter.Literal `json:"policy" cty:"policy"`
|
||||||
Tags map[string]string `json:"tags" cty:"tags"`
|
Tags map[string]string `json:"tags" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SQS) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SQS) error {
|
func (_ *SQS) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SQS) error {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
|
|
||||||
"k8s.io/kops/pkg/pki"
|
"k8s.io/kops/pkg/pki"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
|
@ -182,9 +183,9 @@ func (_ *SSHKey) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *SSHKey) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSSHKey struct {
|
type terraformSSHKey struct {
|
||||||
Name *string `json:"key_name" cty:"key_name"`
|
Name *string `json:"key_name" cty:"key_name"`
|
||||||
PublicKey *terraform.Literal `json:"public_key" cty:"public_key"`
|
PublicKey *terraformWriter.Literal `json:"public_key" cty:"public_key"`
|
||||||
Tags map[string]string `json:"tags" cty:"tags"`
|
Tags map[string]string `json:"tags" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SSHKey) error {
|
func (_ *SSHKey) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *SSHKey) error {
|
||||||
|
|
@ -213,15 +214,15 @@ func (e *SSHKey) IsExistingKey() bool {
|
||||||
return e.PublicKey == nil
|
return e.PublicKey == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SSHKey) TerraformLink() *terraform.Literal {
|
func (e *SSHKey) TerraformLink() *terraformWriter.Literal {
|
||||||
if e.NoSSHKey() {
|
if e.NoSSHKey() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if e.IsExistingKey() {
|
if e.IsExistingKey() {
|
||||||
return terraform.LiteralFromStringValue(*e.Name)
|
return terraformWriter.LiteralFromStringValue(*e.Name)
|
||||||
}
|
}
|
||||||
tfName := strings.Replace(*e.Name, ":", "", -1)
|
tfName := strings.Replace(*e.Name, ":", "", -1)
|
||||||
return terraform.LiteralProperty("aws_key_pair", tfName, "id")
|
return terraformWriter.LiteralProperty("aws_key_pair", tfName, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *SSHKey) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *SSHKey) error {
|
func (_ *SSHKey) RenderCloudformation(t *cloudformation.CloudformationTarget, a, e, changes *SSHKey) error {
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
"k8s.io/kops/upup/pkg/fi/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -215,10 +216,10 @@ func subnetSlicesEqualIgnoreOrder(l, r []*Subnet) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSubnet struct {
|
type terraformSubnet struct {
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
CIDR *string `json:"cidr_block" cty:"cidr_block"`
|
CIDR *string `json:"cidr_block" cty:"cidr_block"`
|
||||||
AvailabilityZone *string `json:"availability_zone" cty:"availability_zone"`
|
AvailabilityZone *string `json:"availability_zone" cty:"availability_zone"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *Subnet) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Subnet) error {
|
func (_ *Subnet) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Subnet) error {
|
||||||
|
|
@ -237,7 +238,7 @@ func (_ *Subnet) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Su
|
||||||
// We probably shouldn't output subnet_ids only in this case - we normally output them by role,
|
// We probably shouldn't output subnet_ids only in this case - we normally output them by role,
|
||||||
// but removing it now might break people. We could always output subnet_ids though, if we
|
// but removing it now might break people. We could always output subnet_ids though, if we
|
||||||
// ever get a request for that.
|
// ever get a request for that.
|
||||||
return t.AddOutputVariableArray("subnet_ids", terraform.LiteralFromStringValue(*e.ID))
|
return t.AddOutputVariableArray("subnet_ids", terraformWriter.LiteralFromStringValue(*e.ID))
|
||||||
}
|
}
|
||||||
|
|
||||||
tf := &terraformSubnet{
|
tf := &terraformSubnet{
|
||||||
|
|
@ -250,7 +251,7 @@ func (_ *Subnet) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Su
|
||||||
return t.RenderResource("aws_subnet", *e.Name, tf)
|
return t.RenderResource("aws_subnet", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Subnet) TerraformLink() *terraform.Literal {
|
func (e *Subnet) TerraformLink() *terraformWriter.Literal {
|
||||||
shared := fi.BoolValue(e.Shared)
|
shared := fi.BoolValue(e.Shared)
|
||||||
if shared {
|
if shared {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
|
|
@ -258,10 +259,10 @@ func (e *Subnet) TerraformLink() *terraform.Literal {
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(4).Infof("reusing existing subnet with id %q", *e.ID)
|
klog.V(4).Infof("reusing existing subnet with id %q", *e.ID)
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralProperty("aws_subnet", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_subnet", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationSubnet struct {
|
type cloudformationSubnet struct {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -210,7 +211,7 @@ type terraformTargetGroup struct {
|
||||||
Name string `json:"name" cty:"name"`
|
Name string `json:"name" cty:"name"`
|
||||||
Port int64 `json:"port" cty:"port"`
|
Port int64 `json:"port" cty:"port"`
|
||||||
Protocol string `json:"protocol" cty:"protocol"`
|
Protocol string `json:"protocol" cty:"protocol"`
|
||||||
VPCID terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
Tags map[string]string `json:"tags,omitempty" cty:"tags"`
|
||||||
HealthCheck terraformTargetGroupHealthCheck `json:"health_check" cty:"health_check"`
|
HealthCheck terraformTargetGroupHealthCheck `json:"health_check" cty:"health_check"`
|
||||||
}
|
}
|
||||||
|
|
@ -247,16 +248,16 @@ func (_ *TargetGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, change
|
||||||
return t.RenderResource("aws_lb_target_group", *e.Name, tf)
|
return t.RenderResource("aws_lb_target_group", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *TargetGroup) TerraformLink(params ...string) *terraform.Literal {
|
func (e *TargetGroup) TerraformLink(params ...string) *terraformWriter.Literal {
|
||||||
shared := fi.BoolValue(e.Shared)
|
shared := fi.BoolValue(e.Shared)
|
||||||
if shared {
|
if shared {
|
||||||
if e.ARN != nil {
|
if e.ARN != nil {
|
||||||
return terraform.LiteralFromStringValue(*e.ARN)
|
return terraformWriter.LiteralFromStringValue(*e.ARN)
|
||||||
} else {
|
} else {
|
||||||
klog.Warningf("ID not set on shared Target Group %v", e)
|
klog.Warningf("ID not set on shared Target Group %v", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return terraform.LiteralProperty("aws_lb_target_group", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_lb_target_group", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationTargetGroup struct {
|
type cloudformationTargetGroup struct {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -267,7 +268,7 @@ func (_ *VPC) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPC)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := t.AddOutputVariable("vpc_cidr_block", terraform.LiteralProperty("aws_vpc", *e.Name, "cidr_block")); err != nil {
|
if err := t.AddOutputVariable("vpc_cidr_block", terraformWriter.LiteralProperty("aws_vpc", *e.Name, "cidr_block")); err != nil {
|
||||||
// TODO: Should we try to output vpc_cidr_block for shared vpcs?
|
// TODO: Should we try to output vpc_cidr_block for shared vpcs?
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -282,7 +283,7 @@ func (_ *VPC) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPC)
|
||||||
return t.RenderResource("aws_vpc", *e.Name, tf)
|
return t.RenderResource("aws_vpc", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *VPC) TerraformLink() *terraform.Literal {
|
func (e *VPC) TerraformLink() *terraformWriter.Literal {
|
||||||
shared := fi.BoolValue(e.Shared)
|
shared := fi.BoolValue(e.Shared)
|
||||||
if shared {
|
if shared {
|
||||||
if e.ID == nil {
|
if e.ID == nil {
|
||||||
|
|
@ -290,10 +291,10 @@ func (e *VPC) TerraformLink() *terraform.Literal {
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(4).Infof("reusing existing VPC with id %q", *e.ID)
|
klog.V(4).Infof("reusing existing VPC with id %q", *e.ID)
|
||||||
return terraform.LiteralFromStringValue(*e.ID)
|
return terraformWriter.LiteralFromStringValue(*e.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return terraform.LiteralProperty("aws_vpc", *e.Name, "id")
|
return terraformWriter.LiteralProperty("aws_vpc", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
type cloudformationVPC struct {
|
type cloudformationVPC struct {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -102,8 +103,8 @@ func (_ *VPCDHCPOptionsAssociation) RenderAWS(t *awsup.AWSAPITarget, a, e, chang
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformVPCDHCPOptionsAssociation struct {
|
type terraformVPCDHCPOptionsAssociation struct {
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
DHCPOptionsID *terraform.Literal `json:"dhcp_options_id" cty:"dhcp_options_id"`
|
DHCPOptionsID *terraformWriter.Literal `json:"dhcp_options_id" cty:"dhcp_options_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *VPCDHCPOptionsAssociation) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPCDHCPOptionsAssociation) error {
|
func (_ *VPCDHCPOptionsAssociation) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPCDHCPOptionsAssociation) error {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
"k8s.io/kops/upup/pkg/fi/cloudup/cloudformation"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -124,8 +125,8 @@ func (_ *VPCCIDRBlock) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *VPCCIDRBl
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformVPCCIDRBlock struct {
|
type terraformVPCCIDRBlock struct {
|
||||||
VPCID *terraform.Literal `json:"vpc_id" cty:"vpc_id"`
|
VPCID *terraformWriter.Literal `json:"vpc_id" cty:"vpc_id"`
|
||||||
CIDRBlock *string `json:"cidr_block" cty:"cidr_block"`
|
CIDRBlock *string `json:"cidr_block" cty:"cidr_block"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *VPCCIDRBlock) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPCCIDRBlock) error {
|
func (_ *VPCCIDRBlock) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *VPCCIDRBlock) error {
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ go_library(
|
||||||
"//upup/pkg/fi:go_default_library",
|
"//upup/pkg/fi:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/gce:go_default_library",
|
"//upup/pkg/fi/cloudup/gce:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//vendor/google.golang.org/api/compute/v1:go_default_library",
|
"//vendor/google.golang.org/api/compute/v1:go_default_library",
|
||||||
"//vendor/google.golang.org/api/storage/v1:go_default_library",
|
"//vendor/google.golang.org/api/storage/v1:go_default_library",
|
||||||
"//vendor/k8s.io/klog/v2:go_default_library",
|
"//vendor/k8s.io/klog/v2:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -163,8 +164,8 @@ func (_ *Address) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *A
|
||||||
return t.RenderResource("google_compute_address", *e.Name, tf)
|
return t.RenderResource("google_compute_address", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Address) TerraformAddress() *terraform.Literal {
|
func (e *Address) TerraformAddress() *terraformWriter.Literal {
|
||||||
name := fi.StringValue(e.Name)
|
name := fi.StringValue(e.Name)
|
||||||
|
|
||||||
return terraform.LiteralProperty("google_compute_address", name, "address")
|
return terraformWriter.LiteralProperty("google_compute_address", name, "address")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FirewallRule represents a GCE firewall rules
|
// FirewallRule represents a GCE firewall rules
|
||||||
|
|
@ -163,8 +164,8 @@ type terraformAllow struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformFirewall struct {
|
type terraformFirewall struct {
|
||||||
Name string `json:"name" cty:"name"`
|
Name string `json:"name" cty:"name"`
|
||||||
Network *terraform.Literal `json:"network" cty:"network"`
|
Network *terraformWriter.Literal `json:"network" cty:"network"`
|
||||||
|
|
||||||
Allowed []*terraformAllow `json:"allow,omitempty" cty:"allow"`
|
Allowed []*terraformAllow `json:"allow,omitempty" cty:"allow"`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ForwardingRule represents a GCE ForwardingRule
|
// ForwardingRule represents a GCE ForwardingRule
|
||||||
|
|
@ -138,11 +139,11 @@ func (_ *ForwardingRule) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Forwardin
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformForwardingRule struct {
|
type terraformForwardingRule struct {
|
||||||
Name string `json:"name" cty:"name"`
|
Name string `json:"name" cty:"name"`
|
||||||
PortRange string `json:"port_range,omitempty" cty:"port_range"`
|
PortRange string `json:"port_range,omitempty" cty:"port_range"`
|
||||||
Target *terraform.Literal `json:"target,omitempty" cty:"target"`
|
Target *terraformWriter.Literal `json:"target,omitempty" cty:"target"`
|
||||||
IPAddress *terraform.Literal `json:"ip_address,omitempty" cty:"ip_address"`
|
IPAddress *terraformWriter.Literal `json:"ip_address,omitempty" cty:"ip_address"`
|
||||||
IPProtocol string `json:"ip_protocol,omitempty" cty:"ip_protocol"`
|
IPProtocol string `json:"ip_protocol,omitempty" cty:"ip_protocol"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *ForwardingRule) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *ForwardingRule) error {
|
func (_ *ForwardingRule) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *ForwardingRule) error {
|
||||||
|
|
@ -165,8 +166,8 @@ func (_ *ForwardingRule) RenderTerraform(t *terraform.TerraformTarget, a, e, cha
|
||||||
return t.RenderResource("google_compute_forwarding_rule", name, tf)
|
return t.RenderResource("google_compute_forwarding_rule", name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ForwardingRule) TerraformLink() *terraform.Literal {
|
func (e *ForwardingRule) TerraformLink() *terraformWriter.Literal {
|
||||||
name := fi.StringValue(e.Name)
|
name := fi.StringValue(e.Name)
|
||||||
|
|
||||||
return terraform.LiteralSelfLink("google_compute_forwarding_rule", name)
|
return terraformWriter.LiteralSelfLink("google_compute_forwarding_rule", name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
var scopeAliases map[string]string
|
var scopeAliases map[string]string
|
||||||
|
|
@ -393,17 +394,17 @@ func ShortenImageURL(defaultProject string, imageURL string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformInstance struct {
|
type terraformInstance struct {
|
||||||
Name string `json:"name" cty:"name"`
|
Name string `json:"name" cty:"name"`
|
||||||
CanIPForward bool `json:"can_ip_forward" cty:"can_ip_forward"`
|
CanIPForward bool `json:"can_ip_forward" cty:"can_ip_forward"`
|
||||||
MachineType string `json:"machine_type,omitempty" cty:"machine_type"`
|
MachineType string `json:"machine_type,omitempty" cty:"machine_type"`
|
||||||
ServiceAccount *terraformServiceAccount `json:"service_account,omitempty" cty:"service_account"`
|
ServiceAccount *terraformServiceAccount `json:"service_account,omitempty" cty:"service_account"`
|
||||||
Scheduling *terraformScheduling `json:"scheduling,omitempty" cty:"scheduling"`
|
Scheduling *terraformScheduling `json:"scheduling,omitempty" cty:"scheduling"`
|
||||||
Disks []*terraformInstanceAttachedDisk `json:"disk,omitempty" cty:"disk"`
|
Disks []*terraformInstanceAttachedDisk `json:"disk,omitempty" cty:"disk"`
|
||||||
NetworkInterfaces []*terraformNetworkInterface `json:"network_interface,omitempty" cty:"network_interface"`
|
NetworkInterfaces []*terraformNetworkInterface `json:"network_interface,omitempty" cty:"network_interface"`
|
||||||
Metadata map[string]*terraform.Literal `json:"metadata,omitempty" cty:"metadata"`
|
Metadata map[string]*terraformWriter.Literal `json:"metadata,omitempty" cty:"metadata"`
|
||||||
MetadataStartupScript *terraform.Literal `json:"metadata_startup_script,omitempty" cty:"metadata_startup_script"`
|
MetadataStartupScript *terraformWriter.Literal `json:"metadata_startup_script,omitempty" cty:"metadata_startup_script"`
|
||||||
Tags []string `json:"tags,omitempty" cty:"tags"`
|
Tags []string `json:"tags,omitempty" cty:"tags"`
|
||||||
Zone string `json:"zone,omitempty" cty:"zone"`
|
Zone string `json:"zone,omitempty" cty:"zone"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformInstanceAttachedDisk struct {
|
type terraformInstanceAttachedDisk struct {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -171,16 +172,16 @@ func (_ *InstanceGroupManager) RenderGCE(t *gce.GCEAPITarget, a, e, changes *Ins
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformInstanceGroupManager struct {
|
type terraformInstanceGroupManager struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
Zone *string `json:"zone" cty:"zone"`
|
Zone *string `json:"zone" cty:"zone"`
|
||||||
BaseInstanceName *string `json:"base_instance_name" cty:"base_instance_name"`
|
BaseInstanceName *string `json:"base_instance_name" cty:"base_instance_name"`
|
||||||
Version *terraformVersion `json:"version" cty:"version"`
|
Version *terraformVersion `json:"version" cty:"version"`
|
||||||
TargetSize *int64 `json:"target_size" cty:"target_size"`
|
TargetSize *int64 `json:"target_size" cty:"target_size"`
|
||||||
TargetPools []*terraform.Literal `json:"target_pools,omitempty" cty:"target_pools"`
|
TargetPools []*terraformWriter.Literal `json:"target_pools,omitempty" cty:"target_pools"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformVersion struct {
|
type terraformVersion struct {
|
||||||
InstanceTemplate *terraform.Literal `json:"instance_template" cty:"instance_template"`
|
InstanceTemplate *terraformWriter.Literal `json:"instance_template" cty:"instance_template"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *InstanceGroupManager) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *InstanceGroupManager) error {
|
func (_ *InstanceGroupManager) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *InstanceGroupManager) error {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -451,8 +452,8 @@ type terraformInstanceTemplate struct {
|
||||||
Scheduling *terraformScheduling `json:"scheduling,omitempty" cty:"scheduling"`
|
Scheduling *terraformScheduling `json:"scheduling,omitempty" cty:"scheduling"`
|
||||||
Disks []*terraformInstanceTemplateAttachedDisk `json:"disk,omitempty" cty:"disk"`
|
Disks []*terraformInstanceTemplateAttachedDisk `json:"disk,omitempty" cty:"disk"`
|
||||||
NetworkInterfaces []*terraformNetworkInterface `json:"network_interface,omitempty" cty:"network_interface"`
|
NetworkInterfaces []*terraformNetworkInterface `json:"network_interface,omitempty" cty:"network_interface"`
|
||||||
Metadata map[string]*terraform.Literal `json:"metadata,omitempty" cty:"metadata"`
|
Metadata map[string]*terraformWriter.Literal `json:"metadata,omitempty" cty:"metadata"`
|
||||||
MetadataStartupScript *terraform.Literal `json:"metadata_startup_script,omitempty" cty:"metadata_startup_script"`
|
MetadataStartupScript *terraformWriter.Literal `json:"metadata_startup_script,omitempty" cty:"metadata_startup_script"`
|
||||||
Tags []string `json:"tags,omitempty" cty:"tags"`
|
Tags []string `json:"tags,omitempty" cty:"tags"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -484,13 +485,13 @@ type terraformInstanceTemplateAttachedDisk struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformNetworkInterface struct {
|
type terraformNetworkInterface struct {
|
||||||
Network *terraform.Literal `json:"network,omitempty" cty:"network"`
|
Network *terraformWriter.Literal `json:"network,omitempty" cty:"network"`
|
||||||
Subnetwork *terraform.Literal `json:"subnetwork,omitempty" cty:"subnetwork"`
|
Subnetwork *terraformWriter.Literal `json:"subnetwork,omitempty" cty:"subnetwork"`
|
||||||
AccessConfig []*terraformAccessConfig `json:"access_config" cty:"access_config"`
|
AccessConfig []*terraformAccessConfig `json:"access_config" cty:"access_config"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformAccessConfig struct {
|
type terraformAccessConfig struct {
|
||||||
NatIP *terraform.Literal `json:"nat_ip,omitempty" cty:"nat_ip"`
|
NatIP *terraformWriter.Literal `json:"nat_ip,omitempty" cty:"nat_ip"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addNetworks(network *Network, subnet *Subnet, networkInterfaces []*compute.NetworkInterface) []*terraformNetworkInterface {
|
func addNetworks(network *Network, subnet *Subnet, networkInterfaces []*compute.NetworkInterface) []*terraformNetworkInterface {
|
||||||
|
|
@ -507,7 +508,7 @@ func addNetworks(network *Network, subnet *Subnet, networkInterfaces []*compute.
|
||||||
tac := &terraformAccessConfig{}
|
tac := &terraformAccessConfig{}
|
||||||
natIP := gac.NatIP
|
natIP := gac.NatIP
|
||||||
if natIP != "" {
|
if natIP != "" {
|
||||||
tac.NatIP = terraform.LiteralFromStringValue(natIP)
|
tac.NatIP = terraformWriter.LiteralFromStringValue(natIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
tf.AccessConfig = append(tf.AccessConfig, tac)
|
tf.AccessConfig = append(tf.AccessConfig, tac)
|
||||||
|
|
@ -518,11 +519,11 @@ func addNetworks(network *Network, subnet *Subnet, networkInterfaces []*compute.
|
||||||
return ni
|
return ni
|
||||||
}
|
}
|
||||||
|
|
||||||
func addMetadata(target *terraform.TerraformTarget, name string, metadata *compute.Metadata) (map[string]*terraform.Literal, error) {
|
func addMetadata(target *terraform.TerraformTarget, name string, metadata *compute.Metadata) (map[string]*terraformWriter.Literal, error) {
|
||||||
if metadata == nil {
|
if metadata == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
m := make(map[string]*terraform.Literal)
|
m := make(map[string]*terraformWriter.Literal)
|
||||||
for _, g := range metadata.Items {
|
for _, g := range metadata.Items {
|
||||||
val := fi.StringValue(g.Value)
|
val := fi.StringValue(g.Value)
|
||||||
if strings.Contains(val, "\n") {
|
if strings.Contains(val, "\n") {
|
||||||
|
|
@ -532,7 +533,7 @@ func addMetadata(target *terraform.TerraformTarget, name string, metadata *compu
|
||||||
}
|
}
|
||||||
m[g.Key] = tfResource
|
m[g.Key] = tfResource
|
||||||
} else {
|
} else {
|
||||||
m[g.Key] = terraform.LiteralFromStringValue(val)
|
m[g.Key] = terraformWriter.LiteralFromStringValue(val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m, nil
|
return m, nil
|
||||||
|
|
@ -612,6 +613,6 @@ func (_ *InstanceTemplate) RenderTerraform(t *terraform.TerraformTarget, a, e, c
|
||||||
return t.RenderResource("google_compute_instance_template", name, tf)
|
return t.RenderResource("google_compute_instance_template", name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *InstanceTemplate) TerraformLink() *terraform.Literal {
|
func (i *InstanceTemplate) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralSelfLink("google_compute_instance_template", *i.Name)
|
return terraformWriter.LiteralSelfLink("google_compute_instance_template", *i.Name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -175,6 +176,6 @@ func (_ *Network) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *N
|
||||||
return t.RenderResource("google_compute_network", *e.Name, tf)
|
return t.RenderResource("google_compute_network", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Network) TerraformName() *terraform.Literal {
|
func (i *Network) TerraformName() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("google_compute_network", *i.Name, "name")
|
return terraformWriter.LiteralProperty("google_compute_network", *i.Name, "name")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -202,6 +203,6 @@ func (*Router) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Rout
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerraformName returns the Terraform name.
|
// TerraformName returns the Terraform name.
|
||||||
func (r *Router) TerraformName() *terraform.Literal {
|
func (r *Router) TerraformName() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("google_compute_router_nat", *r.Name, "name")
|
return terraformWriter.LiteralProperty("google_compute_router_nat", *r.Name, "name")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -202,10 +203,10 @@ func (e *Subnet) URL(project string, region string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformSubnet struct {
|
type terraformSubnet struct {
|
||||||
Name *string `json:"name" cty:"name"`
|
Name *string `json:"name" cty:"name"`
|
||||||
Network *terraform.Literal `json:"network" cty:"network"`
|
Network *terraformWriter.Literal `json:"network" cty:"network"`
|
||||||
Region *string `json:"region" cty:"region"`
|
Region *string `json:"region" cty:"region"`
|
||||||
CIDR *string `json:"ip_cidr_range" cty:"ip_cidr_range"`
|
CIDR *string `json:"ip_cidr_range" cty:"ip_cidr_range"`
|
||||||
|
|
||||||
// SecondaryIPRange defines additional IP ranges
|
// SecondaryIPRange defines additional IP ranges
|
||||||
SecondaryIPRange []terraformSubnetRange `json:"secondary_ip_range,omitempty" cty:"secondary_ip_range"`
|
SecondaryIPRange []terraformSubnetRange `json:"secondary_ip_range,omitempty" cty:"secondary_ip_range"`
|
||||||
|
|
@ -234,6 +235,6 @@ func (_ *Subnet) RenderSubnet(t *terraform.TerraformTarget, a, e, changes *Subne
|
||||||
return t.RenderResource("google_compute_subnetwork", *e.Name, tf)
|
return t.RenderResource("google_compute_subnetwork", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Subnet) TerraformName() *terraform.Literal {
|
func (i *Subnet) TerraformName() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("google_compute_subnetwork", *i.Name, "name")
|
return terraformWriter.LiteralProperty("google_compute_subnetwork", *i.Name, "name")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
"k8s.io/kops/upup/pkg/fi/cloudup/gce"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TargetPool represents a GCE TargetPool
|
// TargetPool represents a GCE TargetPool
|
||||||
|
|
@ -117,8 +118,8 @@ func (_ *TargetPool) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("google_compute_target_pool", name, tf)
|
return t.RenderResource("google_compute_target_pool", name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *TargetPool) TerraformLink() *terraform.Literal {
|
func (e *TargetPool) TerraformLink() *terraformWriter.Literal {
|
||||||
name := fi.StringValue(e.Name)
|
name := fi.StringValue(e.Name)
|
||||||
|
|
||||||
return terraform.LiteralSelfLink("google_compute_target_pool", name)
|
return terraformWriter.LiteralSelfLink("google_compute_target_pool", name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ go_library(
|
||||||
"//upup/pkg/fi/cloudup/awstasks:go_default_library",
|
"//upup/pkg/fi/cloudup/awstasks:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/awsup:go_default_library",
|
"//upup/pkg/fi/cloudup/awsup:go_default_library",
|
||||||
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
"//upup/pkg/fi/cloudup/terraform:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//upup/pkg/fi/utils:go_default_library",
|
"//upup/pkg/fi/utils:go_default_library",
|
||||||
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
|
"//vendor/github.com/aws/aws-sdk-go/service/ec2:go_default_library",
|
||||||
"//vendor/github.com/aws/aws-sdk-go/service/elb:go_default_library",
|
"//vendor/github.com/aws/aws-sdk-go/service/elb:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
"k8s.io/kops/upup/pkg/fi/utils"
|
"k8s.io/kops/upup/pkg/fi/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1346,8 +1347,8 @@ type terraformElastigroup struct {
|
||||||
Description *string `json:"description,omitempty" cty:"description"`
|
Description *string `json:"description,omitempty" cty:"description"`
|
||||||
Product *string `json:"product,omitempty" cty:"product"`
|
Product *string `json:"product,omitempty" cty:"product"`
|
||||||
Region *string `json:"region,omitempty" cty:"region"`
|
Region *string `json:"region,omitempty" cty:"region"`
|
||||||
SubnetIDs []*terraform.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
|
SubnetIDs []*terraformWriter.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
|
||||||
LoadBalancers []*terraform.Literal `json:"elastic_load_balancers,omitempty" cty:"elastic_load_balancers"`
|
LoadBalancers []*terraformWriter.Literal `json:"elastic_load_balancers,omitempty" cty:"elastic_load_balancers"`
|
||||||
NetworkInterfaces []*terraformElastigroupNetworkInterface `json:"network_interface,omitempty" cty:"network_interface"`
|
NetworkInterfaces []*terraformElastigroupNetworkInterface `json:"network_interface,omitempty" cty:"network_interface"`
|
||||||
RootBlockDevice *terraformElastigroupBlockDevice `json:"ebs_block_device,omitempty" cty:"ebs_block_device"`
|
RootBlockDevice *terraformElastigroupBlockDevice `json:"ebs_block_device,omitempty" cty:"ebs_block_device"`
|
||||||
EphemeralBlockDevice []*terraformElastigroupBlockDevice `json:"ephemeral_block_device,omitempty" cty:"ephemeral_block_device"`
|
EphemeralBlockDevice []*terraformElastigroupBlockDevice `json:"ephemeral_block_device,omitempty" cty:"ephemeral_block_device"`
|
||||||
|
|
@ -1368,14 +1369,14 @@ type terraformElastigroup struct {
|
||||||
OnDemand *string `json:"instance_types_ondemand,omitempty" cty:"instance_types_ondemand"`
|
OnDemand *string `json:"instance_types_ondemand,omitempty" cty:"instance_types_ondemand"`
|
||||||
Spot []string `json:"instance_types_spot,omitempty" cty:"instance_types_spot"`
|
Spot []string `json:"instance_types_spot,omitempty" cty:"instance_types_spot"`
|
||||||
|
|
||||||
Monitoring *bool `json:"enable_monitoring,omitempty" cty:"enable_monitoring"`
|
Monitoring *bool `json:"enable_monitoring,omitempty" cty:"enable_monitoring"`
|
||||||
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
|
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
|
||||||
ImageID *string `json:"image_id,omitempty" cty:"image_id"`
|
ImageID *string `json:"image_id,omitempty" cty:"image_id"`
|
||||||
HealthCheckType *string `json:"health_check_type,omitempty" cty:"health_check_type"`
|
HealthCheckType *string `json:"health_check_type,omitempty" cty:"health_check_type"`
|
||||||
SecurityGroups []*terraform.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
SecurityGroups []*terraformWriter.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
||||||
UserData *terraform.Literal `json:"user_data,omitempty" cty:"user_data"`
|
UserData *terraformWriter.Literal `json:"user_data,omitempty" cty:"user_data"`
|
||||||
IAMInstanceProfile *terraform.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
|
IAMInstanceProfile *terraformWriter.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
|
||||||
KeyName *terraform.Literal `json:"key_name,omitempty" cty:"key_name"`
|
KeyName *terraformWriter.Literal `json:"key_name,omitempty" cty:"key_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformElastigroupBlockDevice struct {
|
type terraformElastigroupBlockDevice struct {
|
||||||
|
|
@ -1665,8 +1666,8 @@ func (_ *Elastigroup) RenderTerraform(t *terraform.TerraformTarget, a, e, change
|
||||||
return t.RenderResource("spotinst_elastigroup_aws", *e.Name, tf)
|
return t.RenderResource("spotinst_elastigroup_aws", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Elastigroup) TerraformLink() *terraform.Literal {
|
func (e *Elastigroup) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("spotinst_elastigroup_aws", *e.Name, "id")
|
return terraformWriter.LiteralProperty("spotinst_elastigroup_aws", *e.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Elastigroup) buildTags() []*aws.Tag {
|
func (e *Elastigroup) buildTags() []*aws.Tag {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -770,8 +771,8 @@ func (_ *LaunchSpec) update(cloud awsup.AWSCloud, a, e, changes *LaunchSpec) err
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformLaunchSpec struct {
|
type terraformLaunchSpec struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
OceanID *terraform.Literal `json:"ocean_id,omitempty" cty:"ocean_id"`
|
OceanID *terraformWriter.Literal `json:"ocean_id,omitempty" cty:"ocean_id"`
|
||||||
|
|
||||||
Monitoring *bool `json:"monitoring,omitempty" cty:"monitoring"`
|
Monitoring *bool `json:"monitoring,omitempty" cty:"monitoring"`
|
||||||
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
|
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
|
||||||
|
|
@ -779,12 +780,12 @@ type terraformLaunchSpec struct {
|
||||||
AssociatePublicIPAddress *bool `json:"associate_public_ip_address,omitempty" cty:"associate_public_ip_address"`
|
AssociatePublicIPAddress *bool `json:"associate_public_ip_address,omitempty" cty:"associate_public_ip_address"`
|
||||||
RestrictScaleDown *bool `json:"restrict_scale_down,omitempty" cty:"restrict_scale_down"`
|
RestrictScaleDown *bool `json:"restrict_scale_down,omitempty" cty:"restrict_scale_down"`
|
||||||
RootVolumeSize *int64 `json:"root_volume_size,omitempty" cty:"root_volume_size"`
|
RootVolumeSize *int64 `json:"root_volume_size,omitempty" cty:"root_volume_size"`
|
||||||
UserData *terraform.Literal `json:"user_data,omitempty" cty:"user_data"`
|
UserData *terraformWriter.Literal `json:"user_data,omitempty" cty:"user_data"`
|
||||||
IAMInstanceProfile *terraform.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
|
IAMInstanceProfile *terraformWriter.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
|
||||||
KeyName *terraform.Literal `json:"key_name,omitempty" cty:"key_name"`
|
KeyName *terraformWriter.Literal `json:"key_name,omitempty" cty:"key_name"`
|
||||||
InstanceTypes []string `json:"instance_types,omitempty" cty:"instance_types"`
|
InstanceTypes []string `json:"instance_types,omitempty" cty:"instance_types"`
|
||||||
SubnetIDs []*terraform.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
|
SubnetIDs []*terraformWriter.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
|
||||||
SecurityGroups []*terraform.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
SecurityGroups []*terraformWriter.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
||||||
Taints []*terraformTaint `json:"taints,omitempty" cty:"taints"`
|
Taints []*terraformTaint `json:"taints,omitempty" cty:"taints"`
|
||||||
Labels []*terraformKV `json:"labels,omitempty" cty:"labels"`
|
Labels []*terraformKV `json:"labels,omitempty" cty:"labels"`
|
||||||
Tags []*terraformKV `json:"tags,omitempty" cty:"tags"`
|
Tags []*terraformKV `json:"tags,omitempty" cty:"tags"`
|
||||||
|
|
@ -981,8 +982,8 @@ func (_ *LaunchSpec) RenderTerraform(t *terraform.TerraformTarget, a, e, changes
|
||||||
return t.RenderResource("spotinst_ocean_aws_launch_spec", *e.Name, tf)
|
return t.RenderResource("spotinst_ocean_aws_launch_spec", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *LaunchSpec) TerraformLink() *terraform.Literal {
|
func (o *LaunchSpec) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("spotinst_ocean_aws_launch_spec", *o.Name, "id")
|
return terraformWriter.LiteralProperty("spotinst_ocean_aws_launch_spec", *o.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *LaunchSpec) buildTags() []*aws.Tag {
|
func (o *LaunchSpec) buildTags() []*aws.Tag {
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
"k8s.io/kops/upup/pkg/fi/cloudup/awsup"
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraform"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// +kops:fitask
|
// +kops:fitask
|
||||||
|
|
@ -977,14 +978,14 @@ func (_ *Ocean) update(cloud awsup.AWSCloud, a, e, changes *Ocean) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type terraformOcean struct {
|
type terraformOcean struct {
|
||||||
Name *string `json:"name,omitempty" cty:"name"`
|
Name *string `json:"name,omitempty" cty:"name"`
|
||||||
ControllerClusterID *string `json:"controller_id,omitempty" cty:"controller_id"`
|
ControllerClusterID *string `json:"controller_id,omitempty" cty:"controller_id"`
|
||||||
Region *string `json:"region,omitempty" cty:"region"`
|
Region *string `json:"region,omitempty" cty:"region"`
|
||||||
InstanceTypesWhitelist []string `json:"whitelist,omitempty" cty:"whitelist"`
|
InstanceTypesWhitelist []string `json:"whitelist,omitempty" cty:"whitelist"`
|
||||||
InstanceTypesBlacklist []string `json:"blacklist,omitempty" cty:"blacklist"`
|
InstanceTypesBlacklist []string `json:"blacklist,omitempty" cty:"blacklist"`
|
||||||
SubnetIDs []*terraform.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
|
SubnetIDs []*terraformWriter.Literal `json:"subnet_ids,omitempty" cty:"subnet_ids"`
|
||||||
AutoScaler *terraformAutoScaler `json:"autoscaler,omitempty" cty:"autoscaler"`
|
AutoScaler *terraformAutoScaler `json:"autoscaler,omitempty" cty:"autoscaler"`
|
||||||
Tags []*terraformKV `json:"tags,omitempty" cty:"tags"`
|
Tags []*terraformKV `json:"tags,omitempty" cty:"tags"`
|
||||||
|
|
||||||
MinSize *int64 `json:"min_size,omitempty" cty:"min_size"`
|
MinSize *int64 `json:"min_size,omitempty" cty:"min_size"`
|
||||||
MaxSize *int64 `json:"max_size,omitempty" cty:"max_size"`
|
MaxSize *int64 `json:"max_size,omitempty" cty:"max_size"`
|
||||||
|
|
@ -995,15 +996,15 @@ type terraformOcean struct {
|
||||||
DrainingTimeout *int64 `json:"draining_timeout,omitempty" cty:"draining_timeout"`
|
DrainingTimeout *int64 `json:"draining_timeout,omitempty" cty:"draining_timeout"`
|
||||||
GracePeriod *int64 `json:"grace_period,omitempty" cty:"grace_period"`
|
GracePeriod *int64 `json:"grace_period,omitempty" cty:"grace_period"`
|
||||||
|
|
||||||
Monitoring *bool `json:"monitoring,omitempty" cty:"monitoring"`
|
Monitoring *bool `json:"monitoring,omitempty" cty:"monitoring"`
|
||||||
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
|
EBSOptimized *bool `json:"ebs_optimized,omitempty" cty:"ebs_optimized"`
|
||||||
ImageID *string `json:"image_id,omitempty" cty:"image_id"`
|
ImageID *string `json:"image_id,omitempty" cty:"image_id"`
|
||||||
AssociatePublicIPAddress *bool `json:"associate_public_ip_address,omitempty" cty:"associate_public_ip_address"`
|
AssociatePublicIPAddress *bool `json:"associate_public_ip_address,omitempty" cty:"associate_public_ip_address"`
|
||||||
RootVolumeSize *int64 `json:"root_volume_size,omitempty" cty:"root_volume_size"`
|
RootVolumeSize *int64 `json:"root_volume_size,omitempty" cty:"root_volume_size"`
|
||||||
UserData *terraform.Literal `json:"user_data,omitempty" cty:"user_data"`
|
UserData *terraformWriter.Literal `json:"user_data,omitempty" cty:"user_data"`
|
||||||
IAMInstanceProfile *terraform.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
|
IAMInstanceProfile *terraformWriter.Literal `json:"iam_instance_profile,omitempty" cty:"iam_instance_profile"`
|
||||||
KeyName *terraform.Literal `json:"key_name,omitempty" cty:"key_name"`
|
KeyName *terraformWriter.Literal `json:"key_name,omitempty" cty:"key_name"`
|
||||||
SecurityGroups []*terraform.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
SecurityGroups []*terraformWriter.Literal `json:"security_groups,omitempty" cty:"security_groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {
|
func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Ocean) error {
|
||||||
|
|
@ -1171,8 +1172,8 @@ func (_ *Ocean) RenderTerraform(t *terraform.TerraformTarget, a, e, changes *Oce
|
||||||
return t.RenderResource("spotinst_ocean_aws", *e.Name, tf)
|
return t.RenderResource("spotinst_ocean_aws", *e.Name, tf)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Ocean) TerraformLink() *terraform.Literal {
|
func (o *Ocean) TerraformLink() *terraformWriter.Literal {
|
||||||
return terraform.LiteralProperty("spotinst_ocean_aws", *o.Name, "id")
|
return terraformWriter.LiteralProperty("spotinst_ocean_aws", *o.Name, "id")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Ocean) buildTags() []*aws.Tag {
|
func (o *Ocean) buildTags() []*aws.Tag {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ go_library(
|
||||||
srcs = [
|
srcs = [
|
||||||
"hcl2.go",
|
"hcl2.go",
|
||||||
"lifecycle.go",
|
"lifecycle.go",
|
||||||
"literal.go",
|
|
||||||
"target.go",
|
"target.go",
|
||||||
"target_hcl2.go",
|
"target_hcl2.go",
|
||||||
"target_json.go",
|
"target_json.go",
|
||||||
|
|
@ -16,6 +15,7 @@ go_library(
|
||||||
"//pkg/apis/kops:go_default_library",
|
"//pkg/apis/kops:go_default_library",
|
||||||
"//pkg/featureflag:go_default_library",
|
"//pkg/featureflag:go_default_library",
|
||||||
"//upup/pkg/fi:go_default_library",
|
"//upup/pkg/fi:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//vendor/github.com/hashicorp/hcl/v2:go_default_library",
|
"//vendor/github.com/hashicorp/hcl/v2:go_default_library",
|
||||||
"//vendor/github.com/hashicorp/hcl/v2/hclsyntax:go_default_library",
|
"//vendor/github.com/hashicorp/hcl/v2/hclsyntax:go_default_library",
|
||||||
"//vendor/github.com/hashicorp/hcl/v2/hclwrite:go_default_library",
|
"//vendor/github.com/hashicorp/hcl/v2/hclwrite:go_default_library",
|
||||||
|
|
@ -34,6 +34,7 @@ go_test(
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/diff:go_default_library",
|
"//pkg/diff:go_default_library",
|
||||||
|
"//upup/pkg/fi/cloudup/terraformWriter:go_default_library",
|
||||||
"//vendor/github.com/hashicorp/hcl/v2/hclwrite:go_default_library",
|
"//vendor/github.com/hashicorp/hcl/v2/hclwrite:go_default_library",
|
||||||
"//vendor/github.com/zclconf/go-cty/cty:go_default_library",
|
"//vendor/github.com/zclconf/go-cty/cty:go_default_library",
|
||||||
"//vendor/github.com/zclconf/go-cty/cty/gocty:go_default_library",
|
"//vendor/github.com/zclconf/go-cty/cty/gocty:go_default_library",
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/hashicorp/hcl/v2/hclwrite"
|
"github.com/hashicorp/hcl/v2/hclwrite"
|
||||||
"github.com/zclconf/go-cty/cty"
|
"github.com/zclconf/go-cty/cty"
|
||||||
"github.com/zclconf/go-cty/cty/gocty"
|
"github.com/zclconf/go-cty/cty/gocty"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeValue writes a cty Value to a body with a given key
|
// writeValue writes a cty Value to a body with a given key
|
||||||
|
|
@ -38,12 +39,12 @@ func writeValue(body *hclwrite.Body, key string, value cty.Value) {
|
||||||
if value.LengthInt() == 0 {
|
if value.LengthInt() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
literals := make([]*Literal, 0)
|
literals := make([]*terraformWriter.Literal, 0)
|
||||||
|
|
||||||
for _, val := range value.AsValueSlice() {
|
for _, val := range value.AsValueSlice() {
|
||||||
refLiteral := reflect.New(reflect.TypeOf(Literal{}))
|
refLiteral := reflect.New(reflect.TypeOf(terraformWriter.Literal{}))
|
||||||
err := gocty.FromCtyValue(val, refLiteral.Interface())
|
err := gocty.FromCtyValue(val, refLiteral.Interface())
|
||||||
if literal, ok := refLiteral.Interface().(*Literal); err == nil && ok {
|
if literal, ok := refLiteral.Interface().(*terraformWriter.Literal); err == nil && ok {
|
||||||
literals = append(literals, literal)
|
literals = append(literals, literal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,9 +74,9 @@ func writeValue(body *hclwrite.Body, key string, value cty.Value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
refLiteral := reflect.New(reflect.TypeOf(Literal{}))
|
refLiteral := reflect.New(reflect.TypeOf(terraformWriter.Literal{}))
|
||||||
err := gocty.FromCtyValue(value, refLiteral.Interface())
|
err := gocty.FromCtyValue(value, refLiteral.Interface())
|
||||||
if literal, ok := refLiteral.Interface().(*Literal); err == nil && ok {
|
if literal, ok := refLiteral.Interface().(*terraformWriter.Literal); err == nil && ok {
|
||||||
writeLiteral(body, key, literal)
|
writeLiteral(body, key, literal)
|
||||||
} else if value.Type().IsObjectType() {
|
} else if value.Type().IsObjectType() {
|
||||||
childBlock := body.AppendNewBlock(key, nil)
|
childBlock := body.AppendNewBlock(key, nil)
|
||||||
|
|
@ -101,7 +102,7 @@ func writeValue(body *hclwrite.Body, key string, value cty.Value) {
|
||||||
// key = "value1"
|
// key = "value1"
|
||||||
// key = res_type.res_name.res_prop
|
// key = res_type.res_name.res_prop
|
||||||
// key = file("${module.path}/foo")
|
// key = file("${module.path}/foo")
|
||||||
func writeLiteral(body *hclwrite.Body, key string, literal *Literal) {
|
func writeLiteral(body *hclwrite.Body, key string, literal *terraformWriter.Literal) {
|
||||||
if literal.FilePath != "" {
|
if literal.FilePath != "" {
|
||||||
tokens := hclwrite.Tokens{
|
tokens := hclwrite.Tokens{
|
||||||
{
|
{
|
||||||
|
|
@ -127,7 +128,7 @@ func writeLiteral(body *hclwrite.Body, key string, literal *Literal) {
|
||||||
// key = [type1.name1.attr1, type2.name2.attr2, "stringliteral"]
|
// key = [type1.name1.attr1, type2.name2.attr2, "stringliteral"]
|
||||||
//
|
//
|
||||||
// The HCL2 library does not support this natively. See https://github.com/hashicorp/hcl/issues/347
|
// The HCL2 library does not support this natively. See https://github.com/hashicorp/hcl/issues/347
|
||||||
func writeLiteralList(body *hclwrite.Body, key string, literals []*Literal) {
|
func writeLiteralList(body *hclwrite.Body, key string, literals []*terraformWriter.Literal) {
|
||||||
tokens := hclwrite.Tokens{
|
tokens := hclwrite.Tokens{
|
||||||
{Type: hclsyntax.TokenOBrack, Bytes: []byte("["), SpacesBefore: 1},
|
{Type: hclsyntax.TokenOBrack, Bytes: []byte("["), SpacesBefore: 1},
|
||||||
}
|
}
|
||||||
|
|
@ -186,10 +187,10 @@ func writeMap(body *hclwrite.Body, key string, values map[string]cty.Value) {
|
||||||
|
|
||||||
v := values[k]
|
v := values[k]
|
||||||
|
|
||||||
refLiteral := reflect.New(reflect.TypeOf(Literal{}))
|
refLiteral := reflect.New(reflect.TypeOf(terraformWriter.Literal{}))
|
||||||
err := gocty.FromCtyValue(v, refLiteral.Interface())
|
err := gocty.FromCtyValue(v, refLiteral.Interface())
|
||||||
// If this is a map of literals then do not surround the value with quotes
|
// If this is a map of literals then do not surround the value with quotes
|
||||||
if literal, ok := refLiteral.Interface().(*Literal); err == nil && ok {
|
if literal, ok := refLiteral.Interface().(*terraformWriter.Literal); err == nil && ok {
|
||||||
// For maps of literals we currently only support file references
|
// 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 we ever need to support a map of strings to resource property references that can be added here
|
||||||
if literal.FilePath != "" {
|
if literal.FilePath != "" {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/zclconf/go-cty/cty"
|
"github.com/zclconf/go-cty/cty"
|
||||||
"github.com/zclconf/go-cty/cty/gocty"
|
"github.com/zclconf/go-cty/cty/gocty"
|
||||||
"k8s.io/kops/pkg/diff"
|
"k8s.io/kops/pkg/diff"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteValue(t *testing.T) {
|
func TestWriteValue(t *testing.T) {
|
||||||
|
|
@ -113,17 +114,17 @@ foo {
|
||||||
func TestWriteLiteral(t *testing.T) {
|
func TestWriteLiteral(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
literal *Literal
|
literal *terraformWriter.Literal
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "string",
|
name: "string",
|
||||||
literal: &Literal{Value: "value"},
|
literal: &terraformWriter.Literal{Value: "value"},
|
||||||
expected: `foo = "value"`,
|
expected: `foo = "value"`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "traversal",
|
name: "traversal",
|
||||||
literal: &Literal{
|
literal: &terraformWriter.Literal{
|
||||||
ResourceType: "type",
|
ResourceType: "type",
|
||||||
ResourceName: "name",
|
ResourceName: "name",
|
||||||
ResourceProp: "prop",
|
ResourceProp: "prop",
|
||||||
|
|
@ -131,11 +132,8 @@ func TestWriteLiteral(t *testing.T) {
|
||||||
expected: "foo = type.name.prop",
|
expected: "foo = type.name.prop",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "file",
|
name: "file",
|
||||||
literal: &Literal{
|
literal: terraformWriter.LiteralFileExpression("${path.module}/foo", false),
|
||||||
FilePath: "${path.module}/foo",
|
|
||||||
FileFn: fileFnFile,
|
|
||||||
},
|
|
||||||
expected: `foo = file("${path.module}/foo")`,
|
expected: `foo = file("${path.module}/foo")`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -155,7 +153,7 @@ func TestWriteLiteral(t *testing.T) {
|
||||||
func TestWriteLiteralList(t *testing.T) {
|
func TestWriteLiteralList(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
literals []*Literal
|
literals []*terraformWriter.Literal
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
@ -164,7 +162,7 @@ func TestWriteLiteralList(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "one literal",
|
name: "one literal",
|
||||||
literals: []*Literal{
|
literals: []*terraformWriter.Literal{
|
||||||
{
|
{
|
||||||
ResourceType: "type",
|
ResourceType: "type",
|
||||||
ResourceName: "name",
|
ResourceName: "name",
|
||||||
|
|
@ -175,7 +173,7 @@ func TestWriteLiteralList(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "two literals",
|
name: "two literals",
|
||||||
literals: []*Literal{
|
literals: []*terraformWriter.Literal{
|
||||||
{
|
{
|
||||||
ResourceType: "type1",
|
ResourceType: "type1",
|
||||||
ResourceName: "name1",
|
ResourceName: "name1",
|
||||||
|
|
@ -191,7 +189,7 @@ func TestWriteLiteralList(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "one traversal literal, one string literal",
|
name: "one traversal literal, one string literal",
|
||||||
literals: []*Literal{
|
literals: []*terraformWriter.Literal{
|
||||||
{
|
{
|
||||||
ResourceType: "type",
|
ResourceType: "type",
|
||||||
ResourceName: "name",
|
ResourceName: "name",
|
||||||
|
|
@ -268,14 +266,14 @@ tags = {
|
||||||
func TestWriteMapLiterals(t *testing.T) {
|
func TestWriteMapLiterals(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
values map[string]Literal
|
values map[string]terraformWriter.Literal
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "literal values",
|
name: "literal values",
|
||||||
values: map[string]Literal{
|
values: map[string]terraformWriter.Literal{
|
||||||
"key1": {FilePath: "${module.path}/path/to/value1", FileFn: fileFnFile},
|
"key1": *terraformWriter.LiteralFileExpression("${module.path}/path/to/value1", false),
|
||||||
"key2": {FilePath: "${module.path}/path/to/value2", FileFn: fileFnFileBase64},
|
"key2": *terraformWriter.LiteralFileExpression("${module.path}/path/to/value2", true),
|
||||||
},
|
},
|
||||||
expected: `
|
expected: `
|
||||||
metadata = {
|
metadata = {
|
||||||
|
|
|
||||||
|
|
@ -21,77 +21,41 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/pkg/featureflag"
|
"k8s.io/kops/pkg/featureflag"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TerraformTarget struct {
|
type TerraformTarget struct {
|
||||||
|
terraformWriter.TerraformWriter
|
||||||
Cloud fi.Cloud
|
Cloud fi.Cloud
|
||||||
Project string
|
Project string
|
||||||
|
|
||||||
ClusterName string
|
ClusterName string
|
||||||
|
|
||||||
outDir string
|
outDir string
|
||||||
|
|
||||||
// mutex protects the following items (resources & files)
|
|
||||||
mutex sync.Mutex
|
|
||||||
// resources is a list of TF items that should be created
|
|
||||||
resources []*terraformResource
|
|
||||||
// outputs is a list of our TF output variables
|
|
||||||
outputs map[string]*terraformOutputVariable
|
|
||||||
// files is a map of TF resource files that should be created
|
|
||||||
files map[string][]byte
|
|
||||||
// extra config to add to the provider block
|
// extra config to add to the provider block
|
||||||
clusterSpecTarget *kops.TargetSpec
|
clusterSpecTarget *kops.TargetSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTerraformTarget(cloud fi.Cloud, project string, outDir string, clusterSpecTarget *kops.TargetSpec) *TerraformTarget {
|
func NewTerraformTarget(cloud fi.Cloud, project string, outDir string, clusterSpecTarget *kops.TargetSpec) *TerraformTarget {
|
||||||
return &TerraformTarget{
|
target := TerraformTarget{
|
||||||
Cloud: cloud,
|
Cloud: cloud,
|
||||||
Project: project,
|
Project: project,
|
||||||
|
|
||||||
outDir: outDir,
|
outDir: outDir,
|
||||||
files: make(map[string][]byte),
|
|
||||||
outputs: make(map[string]*terraformOutputVariable),
|
|
||||||
clusterSpecTarget: clusterSpecTarget,
|
clusterSpecTarget: clusterSpecTarget,
|
||||||
}
|
}
|
||||||
|
target.InitTerraformWriter()
|
||||||
|
return &target
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.Target = &TerraformTarget{}
|
var _ fi.Target = &TerraformTarget{}
|
||||||
|
|
||||||
type terraformResource struct {
|
func (t *TerraformTarget) AddFileResource(resourceType string, resourceName string, key string, r fi.Resource, base64 bool) (*terraformWriter.Literal, error) {
|
||||||
ResourceType string
|
|
||||||
ResourceName string
|
|
||||||
Item interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type terraformOutputVariable struct {
|
|
||||||
Key string
|
|
||||||
Value *Literal
|
|
||||||
ValueArray []*Literal
|
|
||||||
}
|
|
||||||
|
|
||||||
type terraformOutputValue struct {
|
|
||||||
Value *Literal
|
|
||||||
ValueArray []*Literal
|
|
||||||
}
|
|
||||||
|
|
||||||
// A TF name can't have dots in it (if we want to refer to it from a literal),
|
|
||||||
// so we replace them
|
|
||||||
func tfSanitize(name string) string {
|
|
||||||
if _, err := strconv.Atoi(string(name[0])); err == nil {
|
|
||||||
panic(fmt.Sprintf("Terraform resource names cannot start with a digit. This is a bug in Kops, please report this in a GitHub Issue. Name: %v", name))
|
|
||||||
}
|
|
||||||
return strings.NewReplacer(".", "-", "/", "--", ":", "_").Replace(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TerraformTarget) AddFileResource(resourceType string, resourceName string, key string, r fi.Resource, base64 bool) (*Literal, error) {
|
|
||||||
d, err := fi.ResourceAsBytes(r)
|
d, err := fi.ResourceAsBytes(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
id := resourceType + "_" + resourceName + "_" + key
|
id := resourceType + "_" + resourceName + "_" + key
|
||||||
|
|
@ -101,76 +65,11 @@ func (t *TerraformTarget) AddFileResource(resourceType string, resourceName stri
|
||||||
return t.AddFileBytes(resourceType, resourceName, key, d, base64)
|
return t.AddFileBytes(resourceType, resourceName, key, d, base64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TerraformTarget) AddFileBytes(resourceType string, resourceName string, key string, data []byte, base64 bool) (*Literal, error) {
|
|
||||||
id := resourceType + "_" + resourceName + "_" + key
|
|
||||||
|
|
||||||
t.mutex.Lock()
|
|
||||||
defer t.mutex.Unlock()
|
|
||||||
|
|
||||||
p := path.Join("data", id)
|
|
||||||
t.files[p] = data
|
|
||||||
|
|
||||||
modulePath := path.Join("${path.module}", p)
|
|
||||||
l := LiteralFileExpression(modulePath, base64)
|
|
||||||
return l, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TerraformTarget) ProcessDeletions() bool {
|
func (t *TerraformTarget) ProcessDeletions() bool {
|
||||||
// Terraform tracks & performs deletions itself
|
// Terraform tracks & performs deletions itself
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TerraformTarget) RenderResource(resourceType string, resourceName string, e interface{}) error {
|
|
||||||
res := &terraformResource{
|
|
||||||
ResourceType: resourceType,
|
|
||||||
ResourceName: resourceName,
|
|
||||||
Item: e,
|
|
||||||
}
|
|
||||||
|
|
||||||
t.mutex.Lock()
|
|
||||||
defer t.mutex.Unlock()
|
|
||||||
|
|
||||||
t.resources = append(t.resources, res)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TerraformTarget) AddOutputVariable(key string, literal *Literal) error {
|
|
||||||
v := &terraformOutputVariable{
|
|
||||||
Key: key,
|
|
||||||
Value: literal,
|
|
||||||
}
|
|
||||||
|
|
||||||
t.mutex.Lock()
|
|
||||||
defer t.mutex.Unlock()
|
|
||||||
|
|
||||||
if t.outputs[key] != nil {
|
|
||||||
return fmt.Errorf("duplicate variable: %q", key)
|
|
||||||
}
|
|
||||||
t.outputs[key] = v
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TerraformTarget) AddOutputVariableArray(key string, literal *Literal) error {
|
|
||||||
t.mutex.Lock()
|
|
||||||
defer t.mutex.Unlock()
|
|
||||||
|
|
||||||
if t.outputs[key] == nil {
|
|
||||||
v := &terraformOutputVariable{
|
|
||||||
Key: key,
|
|
||||||
}
|
|
||||||
t.outputs[key] = v
|
|
||||||
}
|
|
||||||
if t.outputs[key].Value != nil {
|
|
||||||
return fmt.Errorf("variable %q is both an array and a scalar", key)
|
|
||||||
}
|
|
||||||
|
|
||||||
t.outputs[key].ValueArray = append(t.outputs[key].ValueArray, literal)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// tfGetProviderExtraConfig is a helper function to get extra config with safety checks on the pointers.
|
// tfGetProviderExtraConfig is a helper function to get extra config with safety checks on the pointers.
|
||||||
func tfGetProviderExtraConfig(c *kops.TargetSpec) map[string]string {
|
func tfGetProviderExtraConfig(c *kops.TargetSpec) map[string]string {
|
||||||
if c != nil &&
|
if c != nil &&
|
||||||
|
|
@ -192,7 +91,7 @@ func (t *TerraformTarget) Finish(taskMap map[string]fi.Task) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for relativePath, contents := range t.files {
|
for relativePath, contents := range t.Files {
|
||||||
p := path.Join(t.outDir, relativePath)
|
p := path.Join(t.outDir, relativePath)
|
||||||
|
|
||||||
err = os.MkdirAll(path.Dir(p), os.FileMode(0755))
|
err = os.MkdirAll(path.Dir(p), os.FileMode(0755))
|
||||||
|
|
@ -209,44 +108,3 @@ func (t *TerraformTarget) Finish(taskMap map[string]fi.Task) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TerraformTarget) getResourcesByType() (map[string]map[string]interface{}, error) {
|
|
||||||
resourcesByType := make(map[string]map[string]interface{})
|
|
||||||
|
|
||||||
for _, res := range t.resources {
|
|
||||||
resources := resourcesByType[res.ResourceType]
|
|
||||||
if resources == nil {
|
|
||||||
resources = make(map[string]interface{})
|
|
||||||
resourcesByType[res.ResourceType] = resources
|
|
||||||
}
|
|
||||||
|
|
||||||
tfName := tfSanitize(res.ResourceName)
|
|
||||||
|
|
||||||
if resources[tfName] != nil {
|
|
||||||
return nil, fmt.Errorf("duplicate resource found: %s.%s", res.ResourceType, tfName)
|
|
||||||
}
|
|
||||||
|
|
||||||
resources[tfName] = res.Item
|
|
||||||
}
|
|
||||||
|
|
||||||
return resourcesByType, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TerraformTarget) getOutputs() (map[string]terraformOutputValue, error) {
|
|
||||||
values := map[string]terraformOutputValue{}
|
|
||||||
for _, v := range t.outputs {
|
|
||||||
tfName := tfSanitize(v.Key)
|
|
||||||
if _, found := values[tfName]; found {
|
|
||||||
return nil, fmt.Errorf("duplicate variable found: %s", tfName)
|
|
||||||
}
|
|
||||||
deduped, err := dedupLiterals(v.ValueArray)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
values[tfName] = terraformOutputValue{
|
|
||||||
Value: v.Value,
|
|
||||||
ValueArray: deduped,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return values, nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,14 @@ import (
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/pkg/featureflag"
|
"k8s.io/kops/pkg/featureflag"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *TerraformTarget) finishHCL2(taskMap map[string]fi.Task) error {
|
func (t *TerraformTarget) finishHCL2(taskMap map[string]fi.Task) error {
|
||||||
f := hclwrite.NewEmptyFile()
|
f := hclwrite.NewEmptyFile()
|
||||||
rootBody := f.Body()
|
rootBody := f.Body()
|
||||||
|
|
||||||
outputs, err := t.getOutputs()
|
outputs, err := t.GetOutputs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +51,7 @@ func (t *TerraformTarget) finishHCL2(taskMap map[string]fi.Task) error {
|
||||||
}
|
}
|
||||||
rootBody.AppendNewline()
|
rootBody.AppendNewline()
|
||||||
|
|
||||||
resourcesByType, err := t.getResourcesByType()
|
resourcesByType, err := t.GetResourcesByType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +118,7 @@ func (t *TerraformTarget) finishHCL2(taskMap map[string]fi.Task) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes := hclwrite.Format(f.Bytes())
|
bytes := hclwrite.Format(f.Bytes())
|
||||||
t.files["kubernetes.tf"] = bytes
|
t.Files["kubernetes.tf"] = bytes
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -134,7 +135,7 @@ func (t *TerraformTarget) finishHCL2(taskMap map[string]fi.Task) error {
|
||||||
// output "key2" {
|
// output "key2" {
|
||||||
// value = "value2"
|
// value = "value2"
|
||||||
// }
|
// }
|
||||||
func writeLocalsOutputs(body *hclwrite.Body, outputs map[string]terraformOutputValue) error {
|
func writeLocalsOutputs(body *hclwrite.Body, outputs map[string]terraformWriter.OutputValue) error {
|
||||||
if len(outputs) == 0 {
|
if len(outputs) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,13 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/hcl/v2/hclwrite"
|
"github.com/hashicorp/hcl/v2/hclwrite"
|
||||||
"k8s.io/kops/pkg/diff"
|
"k8s.io/kops/pkg/diff"
|
||||||
|
"k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestWriteLocalsOutputs(t *testing.T) {
|
func TestWriteLocalsOutputs(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
values map[string]terraformOutputValue
|
values map[string]terraformWriter.OutputValue
|
||||||
expected string
|
expected string
|
||||||
errExpected bool
|
errExpected bool
|
||||||
}{
|
}{
|
||||||
|
|
@ -37,9 +38,9 @@ func TestWriteLocalsOutputs(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "single output",
|
name: "single output",
|
||||||
values: map[string]terraformOutputValue{
|
values: map[string]terraformWriter.OutputValue{
|
||||||
"key1": {
|
"key1": {
|
||||||
Value: LiteralFromStringValue("value1"),
|
Value: terraformWriter.LiteralFromStringValue("value1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: `
|
expected: `
|
||||||
|
|
@ -53,11 +54,11 @@ output "key1" {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "list output",
|
name: "list output",
|
||||||
values: map[string]terraformOutputValue{
|
values: map[string]terraformWriter.OutputValue{
|
||||||
"key1": {
|
"key1": {
|
||||||
ValueArray: []*Literal{
|
ValueArray: []*terraformWriter.Literal{
|
||||||
LiteralFromStringValue("value1"),
|
terraformWriter.LiteralFromStringValue("value1"),
|
||||||
LiteralFromStringValue("value2"),
|
terraformWriter.LiteralFromStringValue("value2"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (t *TerraformTarget) finishJSON(taskMap map[string]fi.Task) error {
|
func (t *TerraformTarget) finishJSON(taskMap map[string]fi.Task) error {
|
||||||
resourcesByType, err := t.getResourcesByType()
|
resourcesByType, err := t.GetResourcesByType()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ func (t *TerraformTarget) finishJSON(taskMap map[string]fi.Task) error {
|
||||||
providersByName["aws"] = providerAWS
|
providersByName["aws"] = providerAWS
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs, err := t.getOutputs()
|
outputs, err := t.GetOutputs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -110,6 +110,6 @@ func (t *TerraformTarget) finishJSON(taskMap map[string]fi.Task) error {
|
||||||
return fmt.Errorf("error marshaling terraform data to json: %v", err)
|
return fmt.Errorf("error marshaling terraform data to json: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.files["kubernetes.tf.json"] = jsonBytes
|
t.Files["kubernetes.tf.json"] = jsonBytes
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = [
|
||||||
|
"literal.go",
|
||||||
|
"writer.go",
|
||||||
|
],
|
||||||
|
importpath = "k8s.io/kops/upup/pkg/fi/cloudup/terraformWriter",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["//vendor/k8s.io/klog/v2:go_default_library"],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = ["writer_test.go"],
|
||||||
|
embed = [":go_default_library"],
|
||||||
|
deps = [
|
||||||
|
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||||
|
"//vendor/github.com/stretchr/testify/require:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package terraform
|
package terraformWriter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
@ -0,0 +1,173 @@
|
||||||
|
/*
|
||||||
|
Copyright 2021 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 terraformWriter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TerraformWriter struct {
|
||||||
|
// mutex protects the following items (resources & Files)
|
||||||
|
mutex sync.Mutex
|
||||||
|
// resources is a list of TF items that should be created
|
||||||
|
resources []*terraformResource
|
||||||
|
// outputs is a list of our TF output variables
|
||||||
|
outputs map[string]*terraformOutputVariable
|
||||||
|
// Files is a map of TF resource Files that should be created
|
||||||
|
Files map[string][]byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type OutputValue struct {
|
||||||
|
Value *Literal
|
||||||
|
ValueArray []*Literal
|
||||||
|
}
|
||||||
|
|
||||||
|
type terraformResource struct {
|
||||||
|
ResourceType string
|
||||||
|
ResourceName string
|
||||||
|
Item interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type terraformOutputVariable struct {
|
||||||
|
Key string
|
||||||
|
Value *Literal
|
||||||
|
ValueArray []*Literal
|
||||||
|
}
|
||||||
|
|
||||||
|
// A TF name can't have dots in it (if we want to refer to it from a literal),
|
||||||
|
// so we replace them
|
||||||
|
func tfSanitize(name string) string {
|
||||||
|
if _, err := strconv.Atoi(string(name[0])); err == nil {
|
||||||
|
panic(fmt.Sprintf("Terraform resource names cannot start with a digit. This is a bug in Kops, please report this in a GitHub Issue. Name: %v", name))
|
||||||
|
}
|
||||||
|
return strings.NewReplacer(".", "-", "/", "--", ":", "_").Replace(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) InitTerraformWriter() {
|
||||||
|
t.Files = make(map[string][]byte)
|
||||||
|
t.outputs = make(map[string]*terraformOutputVariable)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) AddFileBytes(resourceType string, resourceName string, key string, data []byte, base64 bool) (*Literal, error) {
|
||||||
|
id := resourceType + "_" + resourceName + "_" + key
|
||||||
|
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
|
p := path.Join("data", id)
|
||||||
|
t.Files[p] = data
|
||||||
|
|
||||||
|
modulePath := path.Join("${path.module}", p)
|
||||||
|
l := LiteralFileExpression(modulePath, base64)
|
||||||
|
return l, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) RenderResource(resourceType string, resourceName string, e interface{}) error {
|
||||||
|
res := &terraformResource{
|
||||||
|
ResourceType: resourceType,
|
||||||
|
ResourceName: resourceName,
|
||||||
|
Item: e,
|
||||||
|
}
|
||||||
|
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
|
t.resources = append(t.resources, res)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) AddOutputVariable(key string, literal *Literal) error {
|
||||||
|
v := &terraformOutputVariable{
|
||||||
|
Key: key,
|
||||||
|
Value: literal,
|
||||||
|
}
|
||||||
|
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
|
if t.outputs[key] != nil {
|
||||||
|
return fmt.Errorf("duplicate variable: %q", key)
|
||||||
|
}
|
||||||
|
t.outputs[key] = v
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) AddOutputVariableArray(key string, literal *Literal) error {
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
|
if t.outputs[key] == nil {
|
||||||
|
v := &terraformOutputVariable{
|
||||||
|
Key: key,
|
||||||
|
}
|
||||||
|
t.outputs[key] = v
|
||||||
|
}
|
||||||
|
if t.outputs[key].Value != nil {
|
||||||
|
return fmt.Errorf("variable %q is both an array and a scalar", key)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.outputs[key].ValueArray = append(t.outputs[key].ValueArray, literal)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) GetResourcesByType() (map[string]map[string]interface{}, error) {
|
||||||
|
resourcesByType := make(map[string]map[string]interface{})
|
||||||
|
|
||||||
|
for _, res := range t.resources {
|
||||||
|
resources := resourcesByType[res.ResourceType]
|
||||||
|
if resources == nil {
|
||||||
|
resources = make(map[string]interface{})
|
||||||
|
resourcesByType[res.ResourceType] = resources
|
||||||
|
}
|
||||||
|
|
||||||
|
tfName := tfSanitize(res.ResourceName)
|
||||||
|
|
||||||
|
if resources[tfName] != nil {
|
||||||
|
return nil, fmt.Errorf("duplicate resource found: %s.%s", res.ResourceType, tfName)
|
||||||
|
}
|
||||||
|
|
||||||
|
resources[tfName] = res.Item
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourcesByType, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TerraformWriter) GetOutputs() (map[string]OutputValue, error) {
|
||||||
|
values := map[string]OutputValue{}
|
||||||
|
for _, v := range t.outputs {
|
||||||
|
tfName := tfSanitize(v.Key)
|
||||||
|
if _, found := values[tfName]; found {
|
||||||
|
return nil, fmt.Errorf("duplicate variable found: %s", tfName)
|
||||||
|
}
|
||||||
|
deduped, err := dedupLiterals(v.ValueArray)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
values[tfName] = OutputValue{
|
||||||
|
Value: v.Value,
|
||||||
|
ValueArray: deduped,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package terraform
|
package terraformWriter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -27,7 +27,7 @@ func TestGetOutputs(t *testing.T) {
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
values map[string]*terraformOutputVariable
|
values map[string]*terraformOutputVariable
|
||||||
expected map[string]terraformOutputValue
|
expected map[string]OutputValue
|
||||||
errExpected bool
|
errExpected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
|
@ -41,7 +41,7 @@ func TestGetOutputs(t *testing.T) {
|
||||||
Value: LiteralFromStringValue("value1"),
|
Value: LiteralFromStringValue("value1"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]terraformOutputValue{
|
expected: map[string]OutputValue{
|
||||||
"key1": {
|
"key1": {
|
||||||
Value: LiteralFromStringValue("value1"),
|
Value: LiteralFromStringValue("value1"),
|
||||||
},
|
},
|
||||||
|
|
@ -58,7 +58,7 @@ func TestGetOutputs(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]terraformOutputValue{
|
expected: map[string]OutputValue{
|
||||||
"key1": {
|
"key1": {
|
||||||
ValueArray: []*Literal{
|
ValueArray: []*Literal{
|
||||||
LiteralFromStringValue("value1"),
|
LiteralFromStringValue("value1"),
|
||||||
|
|
@ -93,7 +93,7 @@ func TestGetOutputs(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: map[string]terraformOutputValue{
|
expected: map[string]OutputValue{
|
||||||
"key1": {
|
"key1": {
|
||||||
ValueArray: []*Literal{
|
ValueArray: []*Literal{
|
||||||
LiteralFromStringValue("value1"),
|
LiteralFromStringValue("value1"),
|
||||||
|
|
@ -105,10 +105,10 @@ func TestGetOutputs(t *testing.T) {
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
target := TerraformTarget{
|
target := TerraformWriter{
|
||||||
outputs: tc.values,
|
outputs: tc.values,
|
||||||
}
|
}
|
||||||
actual, err := target.getOutputs()
|
actual, err := target.GetOutputs()
|
||||||
if tc.errExpected {
|
if tc.errExpected {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
return
|
return
|
||||||
Loading…
Reference in New Issue