-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.tf
114 lines (103 loc) · 5.02 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
105
106
107
108
109
110
111
112
113
114
locals {
availability_zones = slice(data.aws_availability_zones.available.names, 0, min(var.max_number_availability_zones, length(data.aws_availability_zones.available.names)))
all_pub_subnets = merge({"management" = {env = "management", az = local.availability_zones[0], cidr_block_index = 0}}, {for pair in setproduct(var.environments, local.availability_zones) : "${pair[0]}-${pair[1]}" => {env = pair[0], az = pair[1], cidr_block_index = 1 + index(local.availability_zones, pair[1]) + (var.cidr_block_index[pair[0]]) * length(local.availability_zones)}})
all_priv_subnets = {for pair in setproduct(var.environments, local.availability_zones) : "${pair[0]}-${pair[1]}" => {env = pair[0], az = pair[1], cidr_block_index = index(local.availability_zones, pair[1]) + (var.cidr_block_index[pair[0]]) * length(local.availability_zones)}}
}
module "ubuntu-bionic-ami" {
source = "git::https://github.com/mojaloop/iac-shared-modules.git//aws/ami-ubuntu?ref=v1.0.45"
release = "18.04"
}
module "ubuntu-focal-ami" {
source = "git::https://github.com/mojaloop/iac-shared-modules.git//aws/ami-ubuntu?ref=v1.0.45"
release = "20.04"
}
module "vpc" {
source = "github.com/cloudposse/terraform-aws-vpc.git?ref=0.18.1"
namespace = var.tenant
name = "vpc"
cidr_block = var.cidr_block
tags = merge({}, var.tags)
}
data "aws_availability_zones" "available" {
state = "available"
}
module "public_subnets" {
source = "./modules/named-subnets"
namespace = var.tenant
name = var.tenant
subnet_az_map = local.all_pub_subnets
vpc_id = module.vpc.vpc_id
cidr_block = cidrsubnet(var.cidr_block, 1, 0)
max_subnets = 128
type = "public"
igw_id = module.vpc.igw_id
tags = merge({}, var.tags)
}
module "private_subnets" {
source = "./modules/named-subnets"
namespace = var.tenant
name = var.tenant
subnet_az_map = local.all_priv_subnets
vpc_id = module.vpc.vpc_id
cidr_block = cidrsubnet(var.cidr_block, 1, 1)
max_subnets = 128
type = "private"
ngw_id = module.public_subnets.ngw_id
tags = merge({}, var.tags)
}
module "gitlab" {
source = "git::https://github.com/mojaloop/iac-shared-modules.git//aws/gitlab?ref=v2.1.13"
ami = var.use_latest_ami ? module.ubuntu-focal-ami.id : var.gitlab_ami_list[var.region]
instance_type = "t2.large"
gitlab_runner_size = "c5.2xlarge"
domain = var.domain
namespace = var.tenant
fqdn = "gitlab.${var.tenant}.${var.domain}"
vpc_id = module.vpc.vpc_id
zone_id = aws_route53_zone.tenant_public.zone_id
security_groups = []
subnets = [module.public_subnets.named_subnet_ids["management"]["id"]]
tags = merge({}, var.tags)
user_data = chomp(file("${path.module}/templates/userdata"))
use_letsencrypt_staging = var.gitlab_use_staging_letsencrypt
tenant = var.tenant
enable_github_oauth = var.enable_github_oauth
github_oauth_id = var.github_oauth_id
github_oauth_secret = var.github_oauth_secret
smtp_server_enable = var.smtp_server_enable
smtp_server_address = "email-smtp.${var.region}.amazonaws.com"
smtp_server_port = 587
smtp_server_user = var.smtp_server_enable ? module.ses[0].access_key_id : "user"
smtp_server_pw = var.smtp_server_enable ? module.ses[0].ses_smtp_password : "pass"
smtp_server_mail_domain = "${lower(var.tenant)}.${var.domain}"
gitlab_version = var.gitlab_version
}
module "nexus" {
source = "git::https://github.com/mojaloop/iac-shared-modules.git//aws/nexus?ref=v2.1.17"
ami = var.use_latest_ami ? module.ubuntu-focal-ami.id : var.nexus_ami_list[var.region]
instance_type = var.nexus_instance_type
domain = var.domain
namespace = var.tenant
vpc_id = module.vpc.vpc_id
zone_id = aws_route53_zone.tenant_public.zone_id
security_groups = []
subnets = [module.public_subnets.named_subnet_ids["management"]["id"]]
tags = merge({}, var.tags)
nexus_admin_password = var.nexus_admin_password
docker_repo_listening_port = var.nexus_docker_repo_listening_port
tenant = var.tenant
}
module "ses" {
count = var.smtp_server_enable ? 1 : 0
source = "cloudposse/ses/aws"
version = "~> 0.22.0"
domain = "${lower(var.tenant)}.${var.domain}"
iam_access_key_max_age = 0
name = "tenant-${var.tenant}-ses"
ses_group_enabled = false
ses_user_enabled = true
verify_dkim = true
verify_domain = true
zone_id = aws_route53_zone.tenant_public.id
tags = merge({}, var.tags)
}