Skip to content

Commit 7931855

Browse files
committed
data/aws: Consolidate pivate and public load balancer target groups
The listeners may be private or public, but as far as the bootstrap and master modules are concerned, these are just lists of ARNs that need attaching. This partially unwinds changes from 16dfbb3 (data/aws: use nlbs instead of elbs, 2018-01-01, openshift#594), before which the bootstrap module used a unified list of load balancers while the master module made private/public distinctions. While I'm touching variables.tf, I've alphabetized the dns_server_ip and kubeconfig_content entries as well.
1 parent 1c66a54 commit 7931855

File tree

6 files changed

+63
-115
lines changed

6 files changed

+63
-115
lines changed

data/data/aws/bootstrap/main.tf

+3-10
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,9 @@ resource "aws_instance" "bootstrap" {
130130
volume_tags = "${var.tags}"
131131
}
132132

133-
resource "aws_lb_target_group_attachment" "public" {
134-
count = "${var.public_target_group_arns_length}"
133+
resource "aws_lb_target_group_attachment" "bootstrap" {
134+
count = "${var.target_group_arns_length}"
135135

136-
target_group_arn = "${var.public_target_group_arns[count.index]}"
137-
target_id = "${aws_instance.bootstrap.private_ip}"
138-
}
139-
140-
resource "aws_lb_target_group_attachment" "private" {
141-
count = "${var.private_target_group_arns_length}"
142-
143-
target_group_arn = "${var.private_target_group_arns[count.index]}"
136+
target_group_arn = "${var.target_group_arns[count.index]}"
144137
target_id = "${aws_instance.bootstrap.private_ip}"
145138
}

data/data/aws/bootstrap/variables.tf

+10-20
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,6 @@ variable "instance_type" {
3030
description = "The EC2 instance type for the bootstrap node."
3131
}
3232

33-
variable "private_target_group_arns" {
34-
type = "list"
35-
default = []
36-
description = "The list of target group ARNs for the private load balancer."
37-
}
38-
39-
variable "private_target_group_arns_length" {
40-
description = "The length of the 'private_target_group_arns' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
41-
}
42-
43-
variable "public_target_group_arns" {
44-
type = "list"
45-
default = []
46-
description = "The list of target group ARNs for the public load balancer."
47-
}
48-
49-
variable "public_target_group_arns_length" {
50-
description = "The length of the 'public_target_group_arns' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
51-
}
52-
5333
variable "subnet_id" {
5434
type = "string"
5535
description = "The subnet ID for the bootstrap node."
@@ -61,6 +41,16 @@ variable "tags" {
6141
description = "AWS tags to be applied to created resources."
6242
}
6343

44+
variable "target_group_arns" {
45+
type = "list"
46+
default = []
47+
description = "The list of target group ARNs for the load balancer."
48+
}
49+
50+
variable "target_group_arns_length" {
51+
description = "The length of the 'target_group_arns' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
52+
}
53+
6454
variable "volume_iops" {
6555
type = "string"
6656
default = "100"

data/data/aws/main.tf

+26-31
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,15 @@ provider "aws" {
1717
module "bootstrap" {
1818
source = "./bootstrap"
1919

20-
ami = "${var.tectonic_aws_ec2_ami_override}"
21-
associate_public_ip_address = "${var.tectonic_aws_endpoints != "private"}"
22-
cluster_name = "${var.tectonic_cluster_name}"
23-
public_target_group_arns = "${module.vpc.aws_lb_public_target_group_arns}"
24-
public_target_group_arns_length = "${module.vpc.aws_lb_public_target_group_arns_length}"
25-
private_target_group_arns = "${module.vpc.aws_lb_private_target_group_arns}"
26-
private_target_group_arns_length = "${module.vpc.aws_lb_private_target_group_arns_length}"
27-
iam_role = "${var.tectonic_aws_master_iam_role_name}"
28-
ignition = "${var.ignition_bootstrap}"
29-
subnet_id = "${module.vpc.master_subnet_ids[0]}"
30-
vpc_security_group_ids = ["${concat(var.tectonic_aws_master_extra_sg_ids, list(module.vpc.master_sg_id))}"]
20+
ami = "${var.tectonic_aws_ec2_ami_override}"
21+
associate_public_ip_address = "${var.tectonic_aws_endpoints != "private"}"
22+
cluster_name = "${var.tectonic_cluster_name}"
23+
iam_role = "${var.tectonic_aws_master_iam_role_name}"
24+
ignition = "${var.ignition_bootstrap}"
25+
subnet_id = "${module.vpc.master_subnet_ids[0]}"
26+
target_group_arns = "${module.vpc.aws_lb_target_group_arns}"
27+
target_group_arns_length = "${module.vpc.aws_lb_target_group_arns_length}"
28+
vpc_security_group_ids = ["${concat(var.tectonic_aws_master_extra_sg_ids, list(module.vpc.master_sg_id))}"]
3129

3230
tags = "${merge(map(
3331
"Name", "${var.tectonic_cluster_name}-bootstrap",
@@ -38,26 +36,23 @@ module "bootstrap" {
3836
module "masters" {
3937
source = "./master"
4038

41-
public_target_group_arns = "${module.vpc.aws_lb_public_target_group_arns}"
42-
public_target_group_arns_length = "${module.vpc.aws_lb_public_target_group_arns_length}"
43-
private_target_group_arns = "${module.vpc.aws_lb_private_target_group_arns}"
44-
private_target_group_arns_length = "${module.vpc.aws_lb_private_target_group_arns_length}"
45-
base_domain = "${var.tectonic_base_domain}"
46-
cluster_id = "${var.tectonic_cluster_id}"
47-
cluster_name = "${var.tectonic_cluster_name}"
48-
ec2_type = "${var.tectonic_aws_master_ec2_type}"
49-
extra_tags = "${var.tectonic_aws_extra_tags}"
50-
instance_count = "${var.tectonic_master_count}"
51-
master_iam_role = "${var.tectonic_aws_master_iam_role_name}"
52-
master_sg_ids = "${concat(var.tectonic_aws_master_extra_sg_ids, list(module.vpc.master_sg_id))}"
53-
private_endpoints = "${local.private_endpoints}"
54-
public_endpoints = "${local.public_endpoints}"
55-
root_volume_iops = "${var.tectonic_aws_master_root_volume_iops}"
56-
root_volume_size = "${var.tectonic_aws_master_root_volume_size}"
57-
root_volume_type = "${var.tectonic_aws_master_root_volume_type}"
58-
subnet_ids = "${module.vpc.master_subnet_ids}"
59-
ec2_ami = "${var.tectonic_aws_ec2_ami_override}"
60-
user_data_ign = "${var.ignition_master}"
39+
base_domain = "${var.tectonic_base_domain}"
40+
cluster_id = "${var.tectonic_cluster_id}"
41+
cluster_name = "${var.tectonic_cluster_name}"
42+
ec2_type = "${var.tectonic_aws_master_ec2_type}"
43+
extra_tags = "${var.tectonic_aws_extra_tags}"
44+
instance_count = "${var.tectonic_master_count}"
45+
master_iam_role = "${var.tectonic_aws_master_iam_role_name}"
46+
master_sg_ids = "${concat(var.tectonic_aws_master_extra_sg_ids, list(module.vpc.master_sg_id))}"
47+
public_endpoints = "${local.public_endpoints}"
48+
root_volume_iops = "${var.tectonic_aws_master_root_volume_iops}"
49+
root_volume_size = "${var.tectonic_aws_master_root_volume_size}"
50+
root_volume_type = "${var.tectonic_aws_master_root_volume_type}"
51+
subnet_ids = "${module.vpc.master_subnet_ids}"
52+
target_group_arns = "${module.vpc.aws_lb_target_group_arns}"
53+
target_group_arns_length = "${module.vpc.aws_lb_target_group_arns_length}"
54+
ec2_ami = "${var.tectonic_aws_ec2_ami_override}"
55+
user_data_ign = "${var.ignition_master}"
6156
}
6257

6358
module "iam" {

data/data/aws/master/main.tf

+4-11
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,9 @@ resource "aws_instance" "master" {
113113
), var.extra_tags)}"
114114
}
115115

116-
resource "aws_lb_target_group_attachment" "public" {
117-
count = "${var.public_endpoints ? var.instance_count * var.public_target_group_arns_length : 0}"
116+
resource "aws_lb_target_group_attachment" "master" {
117+
count = "${var.instance_count * var.target_group_arns_length}"
118118

119-
target_group_arn = "${var.public_target_group_arns[count.index % var.public_target_group_arns_length]}"
120-
target_id = "${aws_instance.master.*.private_ip[count.index / var.public_target_group_arns_length]}"
121-
}
122-
123-
resource "aws_lb_target_group_attachment" "private" {
124-
count = "${var.private_endpoints ? var.instance_count * var.private_target_group_arns_length : 0}"
125-
126-
target_group_arn = "${var.private_target_group_arns[count.index % var.private_target_group_arns_length]}"
127-
target_id = "${aws_instance.master.*.private_ip[count.index / var.private_target_group_arns_length]}"
119+
target_group_arn = "${var.target_group_arns[count.index % var.target_group_arns_length]}"
120+
target_id = "${aws_instance.master.*.private_ip[count.index / var.target_group_arns_length]}"
128121
}

data/data/aws/master/variables.tf

+16-31
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ variable "cluster_name" {
1111
type = "string"
1212
}
1313

14+
variable "dns_server_ip" {
15+
type = "string"
16+
default = ""
17+
}
18+
1419
variable "ec2_type" {
1520
type = "string"
1621
}
@@ -30,6 +35,11 @@ variable "instance_count" {
3035
type = "string"
3136
}
3237

38+
variable "kubeconfig_content" {
39+
type = "string"
40+
default = ""
41+
}
42+
3343
variable "master_iam_role" {
3444
type = "string"
3545
default = ""
@@ -41,36 +51,11 @@ variable "master_sg_ids" {
4151
description = "The security group IDs to be applied to the master nodes."
4252
}
4353

44-
variable "private_endpoints" {
45-
description = "If set to true, private-facing ingress resources are created."
46-
default = true
47-
}
48-
49-
variable "private_target_group_arns" {
50-
type = "list"
51-
default = []
52-
description = "The list of target group ARNs for the private load balancer."
53-
}
54-
55-
variable "private_target_group_arns_length" {
56-
description = "The length of the 'private_target_group_arns' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
57-
}
58-
5954
variable "public_endpoints" {
6055
description = "If set to true, public-facing ingress resources are created."
6156
default = true
6257
}
6358

64-
variable "public_target_group_arns" {
65-
type = "list"
66-
default = []
67-
description = "The list of target group ARNs for the public load balancer."
68-
}
69-
70-
variable "public_target_group_arns_length" {
71-
description = "The length of the 'public_target_group_arns' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
72-
}
73-
7459
variable "root_volume_iops" {
7560
type = "string"
7661
default = "100"
@@ -91,14 +76,14 @@ variable "subnet_ids" {
9176
type = "list"
9277
}
9378

94-
variable "dns_server_ip" {
95-
type = "string"
96-
default = ""
79+
variable "target_group_arns" {
80+
type = "list"
81+
default = []
82+
description = "The list of target group ARNs for the load balancer."
9783
}
9884

99-
variable "kubeconfig_content" {
100-
type = "string"
101-
default = ""
85+
variable "target_group_arns_length" {
86+
description = "The length of the 'target_group_arns' variable, to work around https://github.com/hashicorp/terraform/issues/12570."
10287
}
10388

10489
variable "user_data_ign" {

data/data/aws/vpc/outputs.tf

+4-12
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,12 @@ output "console_sg_id" {
2626
value = "${aws_security_group.console.id}"
2727
}
2828

29-
output "aws_lb_private_target_group_arns" {
30-
value = "${compact(concat(aws_lb_target_group.api_internal.*.arn, aws_lb_target_group.services.*.arn))}"
29+
output "aws_lb_target_group_arns" {
30+
value = "${compact(concat(aws_lb_target_group.api_internal.*.arn, aws_lb_target_group.services.*.arn, aws_lb_target_group.api_external.*.arn))}"
3131
}
3232

33-
output "aws_lb_private_target_group_arns_length" {
34-
value = "${var.private_master_endpoints ? 2 : 0}"
35-
}
36-
37-
output "aws_lb_public_target_group_arns" {
38-
value = "${compact(concat(aws_lb_target_group.api_external.*.arn))}"
39-
}
40-
41-
output "aws_lb_public_target_group_arns_length" {
42-
value = "${var.public_master_endpoints ? 1 : 0}"
33+
output "aws_lb_target_group_arns_length" {
34+
value = "${(var.private_master_endpoints ? 2 : 0) + (var.public_master_endpoints ? 1 : 0)}"
4335
}
4436

4537
output "aws_lb_api_external_dns_name" {

0 commit comments

Comments
 (0)