Skip to content

Commit 266309c

Browse files
committed
multi-arch-builders/tofu: add distro var; rework networking
Now with the distro var we can conditionally choose to use the created network (vpc/subnet) or the one that was already provided for us in the RHCOS account case.
1 parent 99bc470 commit 266309c

File tree

4 files changed

+86
-9
lines changed

4 files changed

+86
-9
lines changed

multi-arch-builders/provisioning/aarch64/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ Make sure your AMI user has access to this policies:
3535
}
3636
```
3737

38+
### TF vars via environment variables
39+
40+
If you'd like to override the target distro (defaults to `fcos`) you
41+
can:
42+
43+
```
44+
export TF_VAR_distro=rhcos
45+
```
46+
3847
## Running tofu
3948
```bash
4049
# To begin using it, run 'init' within this directory.

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

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ variable "project" {
2424
default = "coreos-aarch64-builder"
2525
}
2626

27+
# Which distro are we deploying a builder for? Override the
28+
# default by setting the env var: TF_VAR_distro=rhcos
29+
variable "distro" {
30+
type = string
31+
default = "fcos"
32+
}
33+
check "health_check_distro" {
34+
assert {
35+
condition = anytrue([
36+
var.distro == "fcos",
37+
var.distro == "rhcos"
38+
])
39+
error_message = "Distro must be 'fcos' or 'rhcos'"
40+
}
41+
}
2742

2843
# Get ignition created for the multiarch builder
2944
resource "null_resource" "butane" {
@@ -47,6 +62,22 @@ locals {
4762
ami = lookup(jsondecode(data.http.stream_metadata.body).architectures.aarch64.images.aws.regions, data.aws_region.aws_region.name).image
4863
}
4964

65+
variable "rhcos_aws_vpc_prod" {
66+
description = "RHCOS Prod US East 2"
67+
default = "vpc-0e33d95334e362c7e"
68+
}
69+
variable "rhcos_aws_subnet_internal" {
70+
description = "RHCOS Prod US East 2 subnet"
71+
default = "subnet-02014b5e587d01fd2"
72+
}
73+
# If we are RHCOS we'll be using an already existing VPC/subnet rather
74+
# than the newly created one.
75+
locals {
76+
aws_vpc_id = var.distro == "rhcos" ? var.rhcos_aws_vpc_prod : aws_vpc.vpc.id
77+
aws_subnet_id = var.distro == "rhcos" ? var.rhcos_aws_subnet_internal : aws_subnet.private_subnets[0].id
78+
}
79+
80+
5081
resource "aws_instance" "coreos-aarch64-builder" {
5182
tags = {
5283
Name = "${var.project}-${formatdate("YYYYMMDD", timestamp())}"
@@ -55,7 +86,7 @@ resource "aws_instance" "coreos-aarch64-builder" {
5586
user_data = file("coreos-aarch64-builder.ign")
5687
instance_type = "m6g.metal"
5788
vpc_security_group_ids = [aws_security_group.sg.id]
58-
subnet_id = var.aws_subnet_internal
89+
subnet_id = local.aws_subnet_id
5990
root_block_device {
6091
volume_size = "200"
6192
volume_type = "gp3"
Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
1-
variable "aws_vpc_prod" {
2-
description = "RHCOS Prod US East 2"
3-
default = "vpc-0e33d95334e362c7e"
1+
resource "aws_vpc" "vpc" {
2+
cidr_block = "172.31.0.0/16"
3+
tags = {
4+
Name = "${var.project}-vpc"
5+
}
46
}
57

6-
variable "aws_subnet_internal" {
7-
description = "Internal subnet"
8-
default = "subnet-02014b5e587d01fd2"
8+
resource "aws_internet_gateway" "gw" {
9+
vpc_id = aws_vpc.vpc.id
910
}
1011

12+
data "aws_availability_zones" "azs" {
13+
state = "available"
14+
}
15+
16+
variable "private_subnet_cidrs" {
17+
type = list(string)
18+
description = "Private Subnet CIDR values"
19+
default = ["172.31.1.0/24", "172.31.2.0/24", "172.31.3.0/24", "172.31.4.0/24", "172.31.5.0/24", "172.31.6.0/24", "172.31.7.0/24", "172.31.8.0/24"]
20+
}
21+
22+
resource "aws_subnet" "private_subnets" {
23+
count = length(data.aws_availability_zones.azs.names)
24+
vpc_id = aws_vpc.vpc.id
25+
cidr_block = element(var.private_subnet_cidrs, count.index)
26+
availability_zone = element(data.aws_availability_zones.azs.names, count.index)
27+
tags = {
28+
Name = "${var.project}-private-subnet-${count.index + 1}"
29+
}
30+
}
31+
32+
33+
resource "aws_route_table" "internet_route" {
34+
vpc_id = aws_vpc.vpc.id
35+
route {
36+
cidr_block = "0.0.0.0/0"
37+
gateway_id = aws_internet_gateway.gw.id
38+
}
39+
tags = {
40+
Name = "${var.project}-ig"
41+
}
42+
}
43+
44+
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
47+
}

multi-arch-builders/provisioning/aarch64/security-groups.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
resource "aws_security_group" "sg" {
22
name = "${var.project}-security-group"
33
description = "Allow SSH inbound traffic only"
4-
vpc_id = var.aws_vpc_prod
5-
4+
vpc_id = local.aws_vpc_id
5+
66
ingress {
77
description = "SSH access"
88
from_port = 22

0 commit comments

Comments
 (0)