-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
103 lines (89 loc) · 3.77 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0 */
# --- root/main.tf ---
module "vpc" {
for_each = { for k, v in var.vpcs : k => v if v.spoke_type != "connect" }
source = "./modules/vpc"
identifier = var.project_identifier
vpc_name = each.key
vpc_info = each.value
}
module "connect_vpc" {
source = "./modules/connect_vpc"
for_each = { for k, v in var.vpcs : k => v if v.spoke_type == "connect" }
connect_peer_cidr_blocks = var.connect_peer_cidr_blocks
identifier = var.project_identifier
key_name = module.key_pairs.ssh_key_name
tgw_cidr_block = module.transit_gateway.tgw_cidr_block
tgw_spoke_route_table = module.transit_gateway.tgw_spoke_route_table
transit_gateway_id = module.transit_gateway.tgw_id
vpc_info = each.value
vpc_name = each.key
remote_tunnel_bgp_asn = local.remote_vpc_public_ip_asn
isakmp_secret = random_password.isakmp_secret.result
tunnel_cidr_block = var.tunnel_cidr_block
my_ip = data.external.curlip.result.extip
eips = aws_eip.csr_public_ip
transit_gateway_cidr_block = var.transit_gateway_cidr_block
vpcs = var.vpcs
}
module "remote_vpc" {
source = "./modules/remote_vpc"
for_each = { for k, v in var.vpcs : k => v if v.spoke_type == "remote" }
identifier = var.project_identifier
key_name = module.key_pairs.ssh_key_name
vpc_info = each.value
vpc_name = each.key
remote_tunnel_bgp_asn = local.connect_vpc_public_ip_asn
isakmp_secret = random_password.isakmp_secret.result
tunnel_cidr_block = var.tunnel_cidr_block
my_ip = data.external.curlip.result.extip
eips = aws_eip.csr_public_ip
}
module "transit_gateway" {
source = "./modules/transit_gateway"
identifier = var.project_identifier
vpcs = merge(module.vpc, module.connect_vpc)
amazon_side_asn = var.amazon_side_asn
transit_gateway_cidr_block = var.transit_gateway_cidr_block
}
module "key_pairs" {
source = "./modules/key_pairs"
identifier = var.project_identifier
aws_region = var.aws_region
}
module "compute" {
for_each = { for k, v in module.vpc : k => v if length(regexall("spoke", k)) > 0 }
source = "./modules/compute"
identifier = var.project_identifier
vpc_name = each.key
vpc_info = each.value
instance_type = var.vpcs[each.key].instance_type
ec2_iam_instance_profile = module.iam_kms.ec2_iam_instance_profile
ec2_security_group = local.security_groups.spoke_vpc.instance
key_name = module.key_pairs.ssh_key_name
}
module "vpc_endpoints" {
for_each = { for k, v in merge(module.vpc, module.connect_vpc, module.remote_vpc) : k => v }
source = "./modules/vpc_endpoints"
identifier = var.project_identifier
vpc_name = each.key
vpc_info = each.value
endpoints_security_group = local.security_groups.vpc_endpoints.endpoints
endpoint_service_names = local.endpoint_service_names
}
module "iam_kms" {
source = "./modules/iam_kms"
identifier = var.project_identifier
aws_region = var.aws_region
}
resource "random_password" "isakmp_secret" {
length = 8
special = true
override_special = "_%@"
}
resource "aws_eip" "csr_public_ip" {
for_each = { for k, v in var.eips : k => v }
vpc = true
tags = merge(each.value.tags)
}