33resource "aws_vpc" "{{ infra__vpc_name }}" {
44 cidr_block = "{{ infra__vpc_cidr }}"
55 tags = merge(var.env_tags,{Name = "{{ infra__vpc_name }}"})
6- # NOTE: Below variables not available in cloudera.exe
7- # instance_tenancy = "aws.vpc.vpc_instanceTenancy "
8- # enable_dns_support = "aws.vpc.vpc_enable_dns_support"
9- # enable_dns_hostnames = "aws.vpc.vpc_enable_dns_hostnames"
6+
7+ instance_tenancy = "default "
8+ enable_dns_support = true
9+ enable_dns_hostnames = true
1010}
1111
1212{# *** START Create AWS Public Network infrastructure ****#}
@@ -15,17 +15,17 @@ resource "aws_vpc" "{{ infra__vpc_name }}" {
1515# Internet Gateway
1616resource "aws_internet_gateway" "{{ infra__aws_igw_name }}" {
1717 vpc_id = aws_vpc.{{ infra__vpc_name }}.id
18- tags = merge(var.env_tags,{Name = "{{ infra__aws_igw_name }}"})
18+ tags = merge(var.env_tags,{Name = "{{ infra__aws_igw_name }}"})
1919}
2020
2121# AWS VPC Public Subnets
2222{% for __aws_public_subnet_item in infra__vpc_public_subnets_info %}
2323resource "aws_subnet" "{{ __aws_public_subnet_item.name }}" {
24- vpc_id = aws_vpc.{{ infra__vpc_name }}.id
25- cidr_block = "{{ __aws_public_subnet_item.cidr }}"
24+ vpc_id = aws_vpc.{{ infra__vpc_name }}.id
25+ cidr_block = "{{ __aws_public_subnet_item.cidr }}"
2626 map_public_ip_on_launch = true
27- availability_zone = "{{ __aws_az_info.availability_zones[loop.index0 % infra__aws_vpc_az_count | int] .zone_name }}"
28- tags = merge(var.env_tags,{% for key , value in __aws_public_subnet_item .tags .items () %} { "{{ key }}" = "{{ value }}" },{% endfor %} )
27+ availability_zone = "{{ __aws_az_info.availability_zones[loop.index0 % infra__aws_vpc_az_count | int] .zone_name }}"
28+ tags = merge(var.env_tags,{% for key , value in __aws_public_subnet_item .tags .items () %} { "{{ key }}" = "{{ value }}" },{% endfor %} )
2929}
3030{% endfor %}
3131
@@ -38,7 +38,7 @@ resource "aws_default_route_table" "{{ infra__aws_public_route_table_name }}" {
3838 gateway_id = aws_internet_gateway.{{ infra__aws_igw_name }}.id
3939 }
4040
41- tags = merge(var.env_tags,{Name = "{{ infra__aws_public_route_table_name }}"})
41+ tags = merge(var.env_tags,{Name = "{{ infra__aws_public_route_table_name }}"})
4242
4343}
4444
@@ -58,16 +58,15 @@ resource "aws_route_table_association" "{{ __aws_public_subnet_item.name }}-asso
5858{% if ( infra__tunnel ) and ( infra__aws_subnet_ids is not defined ) %}
5959
6060# ------- AWS Private Networking infrastructure -------
61- # TODO: Conditional when: infra__tunnel and infra__aws_subnet_ids is undefined
6261
6362# AWS VPC Private Subnets
6463{% for __aws_private_subnet_item in infra__vpc_private_subnets_info %}
6564resource "aws_subnet" "{{ __aws_private_subnet_item.name }}" {
66- vpc_id = aws_vpc.{{ infra__vpc_name }}.id
67- cidr_block = "{{ __aws_private_subnet_item.cidr }}"
65+ vpc_id = aws_vpc.{{ infra__vpc_name }}.id
66+ cidr_block = "{{ __aws_private_subnet_item.cidr }}"
6867 map_public_ip_on_launch = true
69- availability_zone = "{{ __aws_az_info.availability_zones[loop.index0 % infra__aws_vpc_az_count | int] .zone_name }}"
70- tags = merge(var.env_tags,{% for key , value in __aws_private_subnet_item .tags .items () %} { "{{ key }}" = "{{ value }}" },{% endfor %} )
68+ availability_zone = "{{ __aws_az_info.availability_zones[loop.index0 % infra__aws_vpc_az_count | int] .zone_name }}"
69+ tags = merge(var.env_tags,{% for key , value in __aws_private_subnet_item .tags .items () %} { "{{ key }}" = "{{ value }}" },{% endfor %} )
7170}
7271{% endfor %}
7372
@@ -77,7 +76,7 @@ resource "aws_subnet" "{{ __aws_private_subnet_item.name }}" {
7776# Elastic IP for each NAT gateway
7877{% for __aws_public_subnet_item in infra__vpc_public_subnets_info %}
7978resource "aws_eip" "{{ infra__aws_nat_gateway_name }}-eip-{{ loop.index0 }}" {
80- vpc = true
79+ vpc = true
8180
8281 tags = var.env_tags
8382}
@@ -91,7 +90,7 @@ resource "aws_nat_gateway" "{{ infra__aws_nat_gateway_name }}-{{ loop.index0 }}"
9190 allocation_id = aws_eip.{{ infra__aws_nat_gateway_name }}-eip-{{ loop.index0 }}.id
9291 connectivity_type = "public"
9392
94- tags = merge(var.env_tags,{Name = "{{ '-'.join([infra__aws_nat_gateway_name, loop.index0 | string ]) }}"})
93+ tags = merge(var.env_tags,{Name = "{{ '-'.join([infra__aws_nat_gateway_name, loop.index0 | string ]) }}"})
9594}
9695{% endfor %}
9796
@@ -100,10 +99,10 @@ resource "aws_nat_gateway" "{{ infra__aws_nat_gateway_name }}-{{ loop.index0 }}"
10099resource "aws_route_table" "{{ infra__aws_private_route_table_name }}-{{ loop.index0 }}" {
101100 vpc_id = aws_vpc.{{ infra__vpc_name }}.id
102101
103- tags = merge(var.env_tags,{Name = "{{ '-'.join([infra__aws_private_route_table_name, loop.index0 | string ]) }}"})
102+ tags = merge(var.env_tags,{Name = "{{ '-'.join([infra__aws_private_route_table_name, loop.index0 | string ]) }}"})
104103
105104 route {
106- cidr_block = "0.0.0.0/0"
105+ cidr_block = "0.0.0.0/0"
107106 nat_gateway_id = aws_nat_gateway.{{ infra__aws_nat_gateway_name }}-{{ loop.index0 % infra__vpc_public_subnets_info | length }}.id
108107 }
109108
@@ -130,15 +129,15 @@ resource "aws_security_group" "{{ __security_group_name_item }}" {
130129 name = "{{ __security_group_name_item }}"
131130 description = "{{ __security_group_name_item }}"
132131
133- tags = merge(var.env_tags,{Name = "{{ __security_group_name_item }}"})
132+ tags = merge(var.env_tags,{Name = "{{ __security_group_name_item }}"})
134133
135134 # Create self reference ingress rule to allow
136135 # communication among resources in the security group.
137136 ingress {
138137 from_port = 0
139- to_port = 0
140- protocol = "all"
141- self = true
138+ to_port = 0
139+ protocol = "all"
140+ self = true
142141 }
143142
144143{# ******* NOTE: HERE COMES THE MESSY PART! *******#}
@@ -158,7 +157,7 @@ resource "aws_security_group" "{{ __security_group_name_item }}" {
158157{# **Loop over security group rule**#}
159158{% for ingress in infra__aws_security_group_rules %}
160159# ----- Raw Inputs -----
161- # ports = {{ ingress.ports|pprint }}
160+ # ports = {{ ingress.ports|pprint }}
162161# cidr_blocks = {{ ingress.cidr_ip }}
163162# protocol = {{ ingress.proto }}
164163# ----------------------
0 commit comments