-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
93 lines (75 loc) · 2.39 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
data "aws_availability_zones" "available" {
state = "available"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "3.18.1"
name = "Mastering Terraform"
azs = slice(data.aws_availability_zones.available.names, 0, var.aws_vpc_azs)
cidr = var.aws_vpc_cidr
public_subnets = [
for index in range(100, 100 + var.aws_vpc_azs, 1):
cidrsubnet(var.aws_vpc_cidr, 8, index)
]
private_subnets = cidrsubnets(var.aws_vpc_cidr, 8, 8)
database_subnets = var.aws_vpc_db_subnets
enable_dns_hostnames = true
enable_dns_support = true
enable_nat_gateway = true
single_nat_gateway = true
one_nat_gateway_per_az = false
tags = merge(
tomap({"Name" = "Mastering Terraform VPC"}),
var.mandatory_tags
)
}
module "dns" {
source = "./modules/dns"
domain_name = var.domain_name
mandatory_tags = var.mandatory_tags
}
module "ssl_certificate" {
source = "./modules/ssl"
domain_name = var.domain_name
domain_zone_id = module.dns.domain_zone_id
mandatory_tags = var.mandatory_tags
}
module "bastion_host" {
source = "./modules/bastion"
aws_vpc_id = module.vpc.vpc_id
aws_ami = var.aws_bastion_ami
aws_ec2_type = var.aws_bastion_ec2_type
aws_vpc_public_subnets = module.vpc.public_subnets
mandatory_tags = var.mandatory_tags
domain_zone_id = module.dns.domain_zone_id
}
module "storage" {
source = "./modules/storage"
aws_vpc_id = module.vpc.vpc_id
aws_region = var.aws_region
aws_vpc_route_tables = module.vpc.private_route_table_ids
s3_bucket_name = var.s3_bucket_name
mandatory_tags = var.mandatory_tags
}
module "application" {
source = "./modules/application"
aws_vpc_id = module.vpc.vpc_id
aws_vpc_public_subnets = module.vpc.public_subnets
aws_vpc_private_subnets = module.vpc.private_subnets
aws_ami = var.aws_app_ami
aws_ec2_type = var.aws_app_ec2_type
mandatory_tags = var.mandatory_tags
bastion_security_group_id = module.bastion_host.bastion_security_group_id
app_key_pair_name = module.bastion_host.app_key_pair_name
domain_zone_id = module.dns.domain_zone_id
ssl_certificate_arn = module.ssl_certificate.ssl_certificate_arn
}
module "database" {
source = "./modules/database"
aws_vpc_id = module.vpc.vpc_id
aws_vpc_db_subnets = module.vpc.database_subnets
aws_sg_app_id = module.application.sg_app_id
aws_db_type = var.aws_db_type
aws_db_name = var.aws_db_name
mandatory_tags = var.mandatory_tags
}