Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data/aws: use azs for master set in manifests #1121

Merged
merged 2 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions data/data/aws/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module "bootstrap" {
instance_type = "${var.aws_bootstrap_instance_type}"
cluster_id = "${var.cluster_id}"
ignition = "${var.ignition_bootstrap}"
subnet_id = "${module.vpc.public_subnet_ids[0]}"
subnet_id = "${module.vpc.az_to_private_subnet_id[var.aws_master_availability_zones[0]]}"
target_group_arns = "${module.vpc.aws_lb_target_group_arns}"
target_group_arns_length = "${module.vpc.aws_lb_target_group_arns_length}"
vpc_id = "${module.vpc.vpc_id}"
Expand All @@ -32,12 +32,13 @@ module "masters" {

tags = "${local.tags}"

availability_zones = "${var.aws_master_availability_zones}"
az_to_subnet_id = "${module.vpc.az_to_private_subnet_id}"
instance_count = "${var.master_count}"
master_sg_ids = "${list(module.vpc.master_sg_id)}"
root_volume_iops = "${var.aws_master_root_volume_iops}"
root_volume_size = "${var.aws_master_root_volume_size}"
root_volume_type = "${var.aws_master_root_volume_type}"
subnet_ids = "${module.vpc.private_subnet_ids}"
target_group_arns = "${module.vpc.aws_lb_target_group_arns}"
target_group_arns_length = "${module.vpc.aws_lb_target_group_arns_length}"
ec2_ami = "${aws_ami_copy.main.id}"
Expand Down
2 changes: 1 addition & 1 deletion data/data/aws/master/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ resource "aws_instance" "master" {

iam_instance_profile = "${aws_iam_instance_profile.master.name}"
instance_type = "${var.instance_type}"
subnet_id = "${element(var.subnet_ids, count.index)}"
subnet_id = "${var.az_to_subnet_id[var.availability_zones[count.index]]}"
abhinavdahiya marked this conversation as resolved.
Show resolved Hide resolved
user_data = "${var.user_data_ign}"

vpc_security_group_ids = ["${var.master_sg_ids}"]
Expand Down
8 changes: 0 additions & 8 deletions data/data/aws/master/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
output "subnet_ids" {
value = "${var.subnet_ids}"
}

output "cluster_id" {
value = "${var.cluster_id}"
}

output "ip_addresses" {
value = "${aws_instance.master.*.private_ip}"
}
14 changes: 10 additions & 4 deletions data/data/aws/master/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
variable "availability_zones" {
type = "list"
description = "List of the availability zones in which to create the masters. The length of this list must match instance_count."
}

variable "az_to_subnet_id" {
type = "map"
description = "Map from availability zone name to the ID of the subnet in that availability zone"
}

variable "cluster_id" {
type = "string"
}
Expand Down Expand Up @@ -40,10 +50,6 @@ variable "root_volume_type" {
description = "The type of volume for the root block device."
}

variable "subnet_ids" {
type = "list"
}

variable "tags" {
type = "map"
default = {}
Expand Down
5 changes: 5 additions & 0 deletions data/data/aws/variables-aws.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ variable "aws_region" {
type = "string"
description = "The target AWS region for the cluster."
}

variable "aws_master_availability_zones" {
type = "list"
description = "The availability zones in which to create the masters. The length of this list must match master_count."
}
4 changes: 4 additions & 0 deletions data/data/aws/vpc/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ output "vpc_id" {
value = "${data.aws_vpc.cluster_vpc.id}"
}

output "az_to_private_subnet_id" {
value = "${zipmap(local.new_subnet_azs, local.private_subnet_ids)}"
}

output "public_subnet_ids" {
value = "${local.public_subnet_ids}"
}
Expand Down
8 changes: 5 additions & 3 deletions pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,11 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
if err != nil {
return err
}
data, err = awstfvars.TFVars(
masters[0].Spec.ProviderSpec.Value.Object.(*awsprovider.AWSMachineProviderConfig),
)
masterConfigs := make([]*awsprovider.AWSMachineProviderConfig, len(masters))
for i, m := range masters {
masterConfigs[i] = m.Spec.ProviderSpec.Value.Object.(*awsprovider.AWSMachineProviderConfig)
}
data, err := awstfvars.TFVars(masterConfigs)
if err != nil {
return errors.Wrapf(err, "failed to get %s Terraform variables", platform)
}
Expand Down
17 changes: 13 additions & 4 deletions pkg/tfvars/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@ type config struct {
ExtraTags map[string]string `json:"aws_extra_tags,omitempty"`
BootstrapInstanceType string `json:"aws_bootstrap_instance_type,omitempty"`
MasterInstanceType string `json:"aws_master_instance_type,omitempty"`
AvailabilityZones []string `json:"aws_master_availability_zones"`
IOPS int64 `json:"aws_master_root_volume_iops"`
Size int64 `json:"aws_master_root_volume_size,omitempty"`
Type string `json:"aws_master_root_volume_type,omitempty"`
Region string `json:"aws_region,omitempty"`
}

// TFVars generates AWS-specific Terraform variables launching the cluster.
func TFVars(masterConfig *v1beta1.AWSMachineProviderConfig) ([]byte, error) {
func TFVars(masterConfigs []*v1beta1.AWSMachineProviderConfig) ([]byte, error) {
masterConfig := masterConfigs[0]

tags := make(map[string]string, len(masterConfig.Tags))
for _, tag := range masterConfig.Tags {
tags[tag.Name] = tag.Value
}

availabilityZones := make([]string, len(masterConfigs))
for i, c := range masterConfigs {
availabilityZones[i] = c.Placement.AvailabilityZone
}

if len(masterConfig.BlockDevices) == 0 {
return nil, errors.New("block device slice cannot be empty")
}
Expand All @@ -52,9 +60,10 @@ func TFVars(masterConfig *v1beta1.AWSMachineProviderConfig) ([]byte, error) {
instanceClass := defaults.InstanceClass(masterConfig.Placement.Region)

cfg := &config{
Region: masterConfig.Placement.Region,
ExtraTags: tags,
AMI: *masterConfig.AMI.ID,
Region: masterConfig.Placement.Region,
ExtraTags: tags,
AMI: *masterConfig.AMI.ID,
AvailabilityZones: availabilityZones,
BootstrapInstanceType: fmt.Sprintf("%s.large", instanceClass),
MasterInstanceType: masterConfig.InstanceType,
Size: *rootVolume.EBS.VolumeSize,
Expand Down