Skip to content

Commit acd87a9

Browse files
committed
added outpost subnet support and example
1 parent 0c2db00 commit acd87a9

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

examples/outpost-subnets/main.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
}
4+
5+
module "vpc" {
6+
source = "../terraform-aws-vpc"
7+
8+
name = "outpost-example"
9+
10+
cidr = "10.0.0.0/16"
11+
12+
azs = ["us-west-2a", "us-west-2b", "us-west-2c"]
13+
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
14+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
15+
outpost_subnets = ["10.0.50.0/24"]
16+
create_outpost_subnet = true
17+
outpost_arn = "arn:aws:outposts:us-west-2:116668991109:outpost/op-0a8c1ab53b023a5a4"
18+
19+
enable_ipv6 = true
20+
21+
enable_nat_gateway = true
22+
single_nat_gateway = true
23+
24+
public_subnet_tags = {
25+
Name = "overridden-name-public"
26+
}
27+
28+
tags = {
29+
Owner = "user"
30+
Environment = "dev"
31+
}
32+
33+
vpc_tags = {
34+
Name = "vpc-name"
35+
}
36+
}

main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,30 @@ resource "aws_subnet" "private" {
419419
)
420420
}
421421

422+
#################
423+
# Outpost subnet
424+
#################
425+
resource "aws_subnet" "outpost" {
426+
count = var.create_vpc && var.create_outpost_subnet == true ? length(var.outpost_subnets) : 0
427+
428+
vpc_id = local.vpc_id
429+
cidr_block = var.outpost_subnets[count.index]
430+
availability_zone = var.outpost_az
431+
outpost_arn = var.outpost_arn
432+
433+
tags = merge(
434+
{
435+
"Name" = format(
436+
"%s-${var.outpost_subnet_suffix}-%s",
437+
var.name,
438+
element(var.azs, count.index),
439+
)
440+
},
441+
var.tags,
442+
var.outpost_subnet_tags,
443+
)
444+
}
445+
422446
##################
423447
# Database subnet
424448
##################
@@ -1042,6 +1066,16 @@ resource "aws_route_table_association" "private" {
10421066
)
10431067
}
10441068

1069+
resource "aws_route_table_association" "outpost" {
1070+
count = var.create_vpc && var.create_outpost_subnet == true ? length(var.outpost_subnets) : 0
1071+
1072+
subnet_id = element(aws_subnet.outpost.*.id, count.index)
1073+
route_table_id = element(
1074+
aws_route_table.private.*.id,
1075+
var.single_nat_gateway ? 0 : count.index,
1076+
)
1077+
}
1078+
10451079
resource "aws_route_table_association" "database" {
10461080
count = var.create_vpc && length(var.database_subnets) > 0 ? length(var.database_subnets) : 0
10471081

@@ -1201,3 +1235,4 @@ resource "aws_default_vpc" "this" {
12011235
var.default_vpc_tags,
12021236
)
12031237
}
1238+

variables.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ variable "private_subnet_suffix" {
124124
default = "private"
125125
}
126126

127+
variable "outpost_subnet_suffix" {
128+
description = "Suffix to append to outpost subnets name"
129+
type = string
130+
default = "outpost"
131+
}
132+
127133
variable "intra_subnet_suffix" {
128134
description = "Suffix to append to intra subnets name"
129135
type = string
@@ -160,6 +166,12 @@ variable "private_subnets" {
160166
default = []
161167
}
162168

169+
variable "outpost_subnets" {
170+
description = "A list of outpost subnets inside the VPC"
171+
type = list(string)
172+
default = []
173+
}
174+
163175
variable "database_subnets" {
164176
description = "A list of database subnets"
165177
type = list(string)
@@ -2267,6 +2279,12 @@ variable "private_subnet_tags" {
22672279
default = {}
22682280
}
22692281

2282+
variable "outpost_subnet_tags" {
2283+
description = "Additional tags for the outpost subnets"
2284+
type = map(string)
2285+
default = {}
2286+
}
2287+
22702288
variable "public_route_table_tags" {
22712289
description = "Additional tags for the public route tables"
22722290
type = map(string)
@@ -2902,3 +2920,21 @@ variable "create_egress_only_igw" {
29022920
type = bool
29032921
default = true
29042922
}
2923+
2924+
variable "create_outpost_subnet" {
2925+
description = "Controls if an outpost subnet is deployed"
2926+
type = bool
2927+
default = false
2928+
}
2929+
2930+
variable "outpost_arn" {
2931+
description = "ARN of outpost you want to create a subnet in"
2932+
type = string
2933+
default = ""
2934+
}
2935+
2936+
variable "outpost_az" {
2937+
description = "AZ where outpost is anchored"
2938+
type = string
2939+
default = ""
2940+
}

0 commit comments

Comments
 (0)