forked from rahulactz/tf-ecs-fargate-tmpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
105 lines (91 loc) · 3.34 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
104
provider "aws" {
access_key = var.aws-access-key
secret_key = var.aws-secret-key
region = var.aws-region
}
terraform {
backend "s3" {
bucket = "vcl-terraform-backend-store"
encrypt = true
key = "terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-state-lock-dynamo" #- uncomment this line once the terraform-state-lock-dynamo has been terraformed
}
}
resource "aws_dynamodb_table" "dynamodb-terraform-state-lock" {
name = "terraform-state-lock-dynamo"
hash_key = "LockID"
read_capacity = 20
write_capacity = 20
attribute {
name = "LockID"
type = "S"
}
tags = {
Name = "DynamoDB Terraform State Lock Table"
}
}
module "vpc" {
source = "./vpc"
name = var.name
cidr = var.cidr
private_subnets = var.private_subnets
public_subnets = var.public_subnets
availability_zones = var.availability_zones
environment = var.environment
}
module "secrets" {
source = "./secrets"
name = var.name
environment = var.environment
application-secrets = var.application-secrets
}
module "ecs-cluster" {
source = "./ecs-cluster"
name = var.name
environment = var.environment
}
module "security_groups" {
for_each = var.services
source = "./security-groups"
name = "${var.name}-${each.key}"
vpc_id = module.vpc.id
environment = var.environment
container_port = var.container_port
}
module "alb" {
for_each = var.services
source = "./alb"
name = "${var.name}-${each.key}"
vpc_id = module.vpc.id
subnets = module.vpc.public_subnets
environment = var.environment
alb_security_groups = [module.security_groups[each.key].alb]
alb_tls_cert_arn = var.tls_certificate_arn
health_check_path = var.health_check_path
}
module "ecr" {
for_each = var.services
source = "./ecr"
name = "${var.name}-${each.key}"
environment = var.environment
}
module "ecs" {
for_each = var.services
source = "./ecs"
ecs_cluster = module.ecs-cluster.ecs_cluster
name = "${var.name}-${each.key}"
environment = var.environment
region = var.aws-region
subnets = module.vpc.private_subnets
aws_alb_target_group_arn = module.alb[each.key].aws_alb_target_group_arn
ecs_service_security_groups = [module.security_groups[each.key].ecs_tasks]
container_port = lookup(each.value, "container_port", var.container_port)
container_cpu = lookup(each.value, "container_cpu", var.container_cpu)
container_memory = lookup(each.value, "container_memory", var.container_memory)
service_desired_count = lookup(each.value, "service_desired_count", var.service_desired_count)
container_environment = concat(var.common_service_vars, lookup(each.value, "vars", []))
container_image = module.ecr[each.key].aws_ecr_repository_url
container_secrets = [for secretKey in keys(each.value.secretMap): {name = secretKey, valueFrom = lookup(module.secrets.secrets, each.value.secretMap[secretKey])}]
container_secrets_arns = module.secrets.application_secrets_arn
}