File tree Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Expand file tree Collapse file tree 3 files changed +107
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -419,6 +419,30 @@ resource "aws_subnet" "private" {
419
419
)
420
420
}
421
421
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
+
422
446
# #################
423
447
# Database subnet
424
448
# #################
@@ -1042,6 +1066,16 @@ resource "aws_route_table_association" "private" {
1042
1066
)
1043
1067
}
1044
1068
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
+
1045
1079
resource "aws_route_table_association" "database" {
1046
1080
count = var. create_vpc && length (var. database_subnets ) > 0 ? length (var. database_subnets ) : 0
1047
1081
@@ -1201,3 +1235,4 @@ resource "aws_default_vpc" "this" {
1201
1235
var. default_vpc_tags ,
1202
1236
)
1203
1237
}
1238
+
Original file line number Diff line number Diff line change @@ -124,6 +124,12 @@ variable "private_subnet_suffix" {
124
124
default = " private"
125
125
}
126
126
127
+ variable "outpost_subnet_suffix" {
128
+ description = " Suffix to append to outpost subnets name"
129
+ type = string
130
+ default = " outpost"
131
+ }
132
+
127
133
variable "intra_subnet_suffix" {
128
134
description = " Suffix to append to intra subnets name"
129
135
type = string
@@ -160,6 +166,12 @@ variable "private_subnets" {
160
166
default = []
161
167
}
162
168
169
+ variable "outpost_subnets" {
170
+ description = " A list of outpost subnets inside the VPC"
171
+ type = list (string )
172
+ default = []
173
+ }
174
+
163
175
variable "database_subnets" {
164
176
description = " A list of database subnets"
165
177
type = list (string )
@@ -2267,6 +2279,12 @@ variable "private_subnet_tags" {
2267
2279
default = {}
2268
2280
}
2269
2281
2282
+ variable "outpost_subnet_tags" {
2283
+ description = " Additional tags for the outpost subnets"
2284
+ type = map (string )
2285
+ default = {}
2286
+ }
2287
+
2270
2288
variable "public_route_table_tags" {
2271
2289
description = " Additional tags for the public route tables"
2272
2290
type = map (string )
@@ -2902,3 +2920,21 @@ variable "create_egress_only_igw" {
2902
2920
type = bool
2903
2921
default = true
2904
2922
}
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
+ }
You can’t perform that action at this time.
0 commit comments