-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduction.tf
124 lines (114 loc) · 5.01 KB
/
production.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#Cria um bucket para o site estático
module "bucket_website_production" {
source = "./modules/s3/"
s3_bucket_name = "lab-application-production"
s3_site_index = "index.html"
s3_site_error = "error.html"
}
#Cria uma role para o ECS
module "ecs_iam_production" {
source = "./modules/iam/"
iam_ecs_role_name = "iam-ecs-production"
}
#Cria um cluster ECS
module "ecs_production" {
source = "./modules/ecs/"
ecs_cluster_name = "application-production"
}
#Cria uma task definition ECS
module "application_production" {
source = "./modules/ecs_task/"
ecs_task_family = "application-production"
ecs_task_role_arn = module.ecs_iam_production.ecs_role_arn
ecs_task_compatibilities = ["FARGATE"]
ecs_task_container_name = "application-production"
ecs_task_container_image = "luizfilipesm/waycarbon"
ecs_task_container_image_tag = "latest"
ecs_task_container_port = "80"
ecs_task_port = module.application_production.task_container_port
ecs_task_memory = "512"
ecs_task_cpu = "256"
depends_on = [module.ecs_iam_production]
}
#Cria uma VPC com duas subnetes privadas que utiliza um NAT gateway e uma publica que utiliza um internet gateway
module "vpc_production" {
source = "./modules/vpc/"
vpc_name = "vpc-application-production"
vpc_cidr_block = "10.0.0.0/16"
vpc_subnet_private_count = "2"
vpc_subnet_public_count = "2"
vpc_subnet_regions = "us-east-1a,us-east-1b"
}
#Cria um load balancer
module "elb_production" {
source = "./modules/elb/"
elb_name = "elb-application-production"
elb_type = "application"
elb_subnets = module.vpc_production.subnet_public_id
elb_security_groups = [module.vpc_production.security_group_id_elb]
elb_target_group_name = "application-production"
elb_target_group_port = module.application_production.task_container_port
elb_target_group_protocol = "HTTP"
elb_target_group_vpc = module.vpc_production.vpc_id
elb_group_target_heatlh_interval = "10"
elb_group_target_heatlh_path = "/api"
elb_group_target_heatlh_timeout = "5"
elb_group_target_heatlh_threshold = "3"
elb_group_target_unhealthy_threshold = "2"
elb_listener_port_http = "80"
elb_listener_protocol_http = "HTTP"
depends_on = [module.vpc_production]
}
#Cria um service ECS
module "application_service_production" {
source = "./modules/ecs_service/"
ecs_service_name = "application-production"
ecs_service_cluster = module.ecs_production.cluster_name
ecs_service_task = module.application_production.task_arn
ecs_service_count = "1"
ecs_service_type = "FARGATE"
ecs_service_target_group_arn = module.elb_production.target_group_arn
ecs_service_container_name = module.application_production.task_container_name
ecs_service_container_port = module.application_production.task_container_port
ecs_service_subnets = module.vpc_production.subnet_private_id
ecs_service_security_groups = [module.vpc_production.security_group_id_ecs]
depends_on = [module.vpc_production, module.application_production, module.ecs_production, module.bucket_website_staging, module.cdn_production, module.elb_production, module.ecs_iam_production]
}
#Cria um CDN para a aplicação
module "cdn_production" {
source = "./modules/cdn/"
cdn_damin_name = module.elb_production.dns_name
cdn_origin_id = module.elb_production.elb_name
cdn_enabled = "true"
cdn_ipv6 = "true"
cdn_allowed_methods = ["GET", "HEAD", "OPTIONS"]
cdn_cached_methods = ["GET", "HEAD", "OPTIONS"]
cdn_cache_target_origin = module.elb_production.elb_name
cdn_query_string = "false"
cdn_cookies = "none"
cdn_protocol_policy = "redirect-to-https"
cdn_min_ttl = "0"
cdn_default_ttl = "3600"
cdn_max_ttl = "86400"
cdn_geo_restriction = "none"
cdn_certificate_default = "true"
cdn_target_path = "/api"
depends_on = [module.elb_production]
}
# #Cria um dominio e um record do tipo CNAME
# module "route53" {
# source = "./modules/route53/"
# route53_zone_name = "labluizfilipe.com.br"
# route53_record_name = "application-teste"
# route53_record_type = "CNAME"
# route53_record_ttl = "15"
# route53_records = [""] #Alterar
# }
output "frontend_url_production" {
value = module.bucket_website_production.domain_name
description = "URL do frontend"
}
output "backend_url_production" {
value = module.cdn_production.cloudfront_domain_name
description = "Dominio do CloudFront"
}