Skip to content

Commit a8937de

Browse files
committed
fix: 51258: adding in ftp
1 parent 5a2b4b7 commit a8937de

File tree

2 files changed

+96
-13
lines changed

2 files changed

+96
-13
lines changed

main.tf

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
locals {
22
max_subnet_length = max(
33
length(var.private_subnets),
4+
length(var.ftp_subnets),
45
length(var.elasticache_subnets),
56
length(var.database_subnets),
67
length(var.redshift_subnets),
@@ -32,12 +33,12 @@ resource "aws_vpc" "this" {
3233
#tfsec:ignore:aws-ec2-require-vpc-flow-logs-for-all-vpcs
3334
count = var.create_vpc ? 1 : 0
3435

35-
cidr_block = var.cidr
36-
instance_tenancy = var.instance_tenancy
37-
enable_dns_hostnames = var.enable_dns_hostnames
38-
enable_dns_support = var.enable_dns_support
39-
# enable_classiclink = var.enable_classiclink
40-
# enable_classiclink_dns_support = var.enable_classiclink_dns_support
36+
cidr_block = var.cidr
37+
instance_tenancy = var.instance_tenancy
38+
enable_dns_hostnames = var.enable_dns_hostnames
39+
enable_dns_support = var.enable_dns_support
40+
# enable_classiclink = var.enable_classiclink
41+
# enable_classiclink_dns_support = var.enable_classiclink_dns_support
4142
assign_generated_ipv6_cidr_block = var.enable_ipv6
4243

4344
tags = merge(
@@ -264,6 +265,28 @@ resource "aws_route_table" "private" {
264265
)
265266
}
266267

268+
#################
269+
# Ftp routes
270+
# There are as many routing tables as the number of NAT gateways
271+
#################
272+
resource "aws_route_table" "ftp" {
273+
count = var.create_vpc && local.max_subnet_length > 0 ? local.nat_gateway_count : 0
274+
275+
vpc_id = local.vpc_id
276+
277+
tags = merge(
278+
{
279+
"Name" = var.single_nat_gateway ? "${var.name}-${var.ftp_subnet_suffix}" : format(
280+
"%s-${var.ftp_subnet_suffix}-%s",
281+
var.name,
282+
element(var.azs, count.index),
283+
)
284+
},
285+
var.tags,
286+
var.ftp_route_table_tags,
287+
)
288+
}
289+
267290
#################
268291
# Database routes
269292
#################
@@ -455,7 +478,6 @@ resource "aws_subnet" "public_eks_green" {
455478
)
456479
}
457480

458-
459481
#################
460482
# Private subnet
461483
#################
@@ -483,6 +505,33 @@ resource "aws_subnet" "private" {
483505
)
484506
}
485507

508+
#################
509+
# Ftp subnet
510+
#################
511+
resource "aws_subnet" "ftp" {
512+
count = var.create_vpc && length(var.ftp_subnets) > 0 ? length(var.ftp_subnets) : 0
513+
514+
vpc_id = local.vpc_id
515+
cidr_block = var.ftp_subnets[count.index]
516+
availability_zone = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) > 0 ? element(var.azs, count.index) : null
517+
availability_zone_id = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) == 0 ? element(var.azs, count.index) : null
518+
assign_ipv6_address_on_creation = var.ftp_subnet_assign_ipv6_address_on_creation == null ? var.assign_ipv6_address_on_creation : var.ftp_subnet_assign_ipv6_address_on_creation
519+
520+
ipv6_cidr_block = var.enable_ipv6 && length(var.ftp_subnet_ipv6_prefixes) > 0 ? cidrsubnet(aws_vpc.this[0].ipv6_cidr_block, 8, var.ftp_subnet_ipv6_prefixes[count.index]) : null
521+
522+
tags = merge(
523+
{
524+
"Name" = format(
525+
"%s-${var.ftp_subnet_suffix}-%s",
526+
var.name,
527+
element(var.azs, count.index),
528+
)
529+
},
530+
var.tags,
531+
var.ftp_subnet_tags,
532+
)
533+
}
534+
486535
##################
487536
###############################################################################
488537
# Private EKS subnet
@@ -812,7 +861,7 @@ resource "aws_network_acl_rule" "public_outbound" {
812861
}
813862

814863
#########################
815-
# Public eks Network ACLS
864+
# Public eks Network ACLS
816865
#########################
817866

818867
resource "aws_network_acl" "public_eks_blue" {
@@ -967,7 +1016,7 @@ resource "aws_network_acl_rule" "private_outbound" {
9671016

9681017
########################
9691018
################################################################################
970-
# Private Networks ACLS for the eks
1019+
# Private Networks ACLS for the eks
9711020
################################################################################
9721021

9731022
resource "aws_network_acl" "private_eks_blue" {
@@ -1297,8 +1346,6 @@ locals {
12971346
resource "aws_eip" "nat" {
12981347
count = var.create_vpc && var.enable_nat_gateway && false == var.reuse_nat_ips ? local.nat_gateway_count : 0
12991348

1300-
vpc = true
1301-
13021349
tags = merge(
13031350
{
13041351
"Name" = format(
@@ -1575,7 +1622,7 @@ resource "aws_default_vpc" "this" {
15751622

15761623
enable_dns_support = var.default_vpc_enable_dns_support
15771624
enable_dns_hostnames = var.default_vpc_enable_dns_hostnames
1578-
# enable_classiclink = var.default_vpc_enable_classiclink
1625+
# enable_classiclink = var.default_vpc_enable_classiclink
15791626

15801627
tags = merge(
15811628
{

variables.tf

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variable "create_vpc" {
77
variable "name" {
88
description = "Name to be used on all the resources as identifier"
99
type = string
10-
}
10+
}
1111

1212
variable "cidr" {
1313
description = "The CIDR block for the VPC. Default value is a valid CIDR, but not acceptable by AWS and should be overridden"
@@ -27,6 +27,12 @@ variable "private_subnet_ipv6_prefixes" {
2727
default = []
2828
}
2929

30+
variable "ftp_subnet_ipv6_prefixes" {
31+
description = "Assigns IPv6 ftp subnet id based on the Amazon provided /56 prefix base 10 integer (0-256). Must be of equal length to the corresponding IPv4 subnet list"
32+
type = list(string)
33+
default = []
34+
}
35+
3036
variable "public_subnet_ipv6_prefixes" {
3137
description = "Assigns IPv6 public subnet id based on the Amazon provided /56 prefix base 10 integer (0-256). Must be of equal length to the corresponding IPv4 subnet list"
3238
type = list(string)
@@ -69,6 +75,12 @@ variable "private_subnet_assign_ipv6_address_on_creation" {
6975
default = null
7076
}
7177

78+
variable "ftp_subnet_assign_ipv6_address_on_creation" {
79+
description = "Assign IPv6 address on ftp subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map_public_ip_on_launch"
80+
type = bool
81+
default = null
82+
}
83+
7284
variable "public_subnet_assign_ipv6_address_on_creation" {
7385
description = "Assign IPv6 address on public subnet, must be disabled to change IPv6 CIDRs. This is the IPv6 equivalent of map_public_ip_on_launch"
7486
type = bool
@@ -123,6 +135,12 @@ variable "private_subnet_suffix" {
123135
default = "private"
124136
}
125137

138+
variable "ftp_subnet_suffix" {
139+
description = "Suffix to append to ftp subnets name"
140+
type = string
141+
default = "ftp"
142+
}
143+
126144
variable "intra_subnet_suffix" {
127145
description = "Suffix to append to intra subnets name"
128146
type = string
@@ -171,6 +189,12 @@ variable "private_subnets" {
171189
default = []
172190
}
173191

192+
variable "ftp_subnets" {
193+
description = "A list of private subnets inside the VPC"
194+
type = list(string)
195+
default = []
196+
}
197+
174198
variable "database_subnets" {
175199
description = "A list of database subnets"
176200
type = list(string)
@@ -2278,6 +2302,12 @@ variable "private_subnet_tags" {
22782302
default = {}
22792303
}
22802304

2305+
variable "ftp_subnet_tags" {
2306+
description = "Additional tags for the private subnets"
2307+
type = map(string)
2308+
default = {}
2309+
}
2310+
22812311
variable "private_eks_subnet_tags_blue" {
22822312
description = "Additional tags for the private eks subnets"
22832313
type = map(string)
@@ -2314,6 +2344,12 @@ variable "private_route_table_tags" {
23142344
default = {}
23152345
}
23162346

2347+
variable "ftp_route_table_tags" {
2348+
description = "Additional tags for the ftp route tables"
2349+
type = map(string)
2350+
default = {}
2351+
}
2352+
23172353
variable "database_route_table_tags" {
23182354
description = "Additional tags for the database route tables"
23192355
type = map(string)

0 commit comments

Comments
 (0)