Skip to content

Commit 788477b

Browse files
ravanellidustymabe
authored andcommitted
multi-arch-builders/tofu: Add conditional statement for networking
For rhcos we already have pre-existing networking configurations, including VPC, subnets, and other settings. Since we lack the permissions to create new ones, let's use a conditional 'count' statement to ensure tofu doesn't attempt to create additional networking resources. Signed-off-by: Renata <[email protected]>
1 parent 64ef43b commit 788477b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

multi-arch-builders/provisioning/aarch64/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ variable "rhcos_aws_subnet_internal" {
117117
# If we are RHCOS we'll be using an already existing VPC/subnet rather
118118
# than the newly created one.
119119
locals {
120-
aws_vpc_id = var.distro == "rhcos" ? var.rhcos_aws_vpc_prod : aws_vpc.vpc.id
120+
aws_vpc_id = var.distro == "rhcos" ? var.rhcos_aws_vpc_prod : aws_vpc.vpc[0].id
121121
aws_subnet_id = var.distro == "rhcos" ? var.rhcos_aws_subnet_internal : aws_subnet.private_subnets[0].id
122122
}
123123

multi-arch-builders/provisioning/aarch64/networks.tf

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
resource "aws_vpc" "vpc" {
2+
count = var.distro == "fcos" ? 1 : 0
23
cidr_block = "172.31.0.0/16"
34
tags = {
45
Name = "${var.project}-vpc"
56
}
67
}
78

89
resource "aws_internet_gateway" "gw" {
9-
vpc_id = aws_vpc.vpc.id
10+
count = var.distro == "fcos" ? 1 : 0
11+
vpc_id = aws_vpc.vpc[0].id
1012
}
1113

1214
data "aws_availability_zones" "azs" {
@@ -20,8 +22,8 @@ variable "private_subnet_cidrs" {
2022
}
2123

2224
resource "aws_subnet" "private_subnets" {
23-
count = length(data.aws_availability_zones.azs.names)
24-
vpc_id = aws_vpc.vpc.id
25+
count = var.distro == "fcos" ? length(data.aws_availability_zones.azs.names) : 0
26+
vpc_id = aws_vpc.vpc[0].id
2527
cidr_block = element(var.private_subnet_cidrs, count.index)
2628
availability_zone = element(data.aws_availability_zones.azs.names, count.index)
2729
tags = {
@@ -31,17 +33,19 @@ resource "aws_subnet" "private_subnets" {
3133

3234

3335
resource "aws_route_table" "internet_route" {
34-
vpc_id = aws_vpc.vpc.id
36+
count = var.distro == "fcos" ? 1 : 0
37+
vpc_id = aws_vpc.vpc[0].id
3538
route {
3639
cidr_block = "0.0.0.0/0"
37-
gateway_id = aws_internet_gateway.gw.id
40+
gateway_id = aws_internet_gateway.gw[0].id
3841
}
3942
tags = {
4043
Name = "${var.project}-ig"
4144
}
4245
}
4346

4447
resource "aws_main_route_table_association" "public-set-main-default-rt-assoc" {
45-
vpc_id = aws_vpc.vpc.id
46-
route_table_id = aws_route_table.internet_route.id
48+
count = var.distro == "fcos" ? 1 : 0
49+
vpc_id = aws_vpc.vpc[0].id
50+
route_table_id = aws_route_table.internet_route[0].id
4751
}

0 commit comments

Comments
 (0)