Skip to content

Commit 7deab12

Browse files
authored
Setup separate VPCs per each env (#4290)
1 parent 92f5794 commit 7deab12

File tree

24 files changed

+206
-154
lines changed

24 files changed

+206
-154
lines changed

infrastructure/applications/.terraform.lock.hcl

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
locals {
22
is_prod = terraform.workspace == "production"
3-
deploy_pretix = local.is_prod
4-
5-
# AMI
6-
# Built from https://github.com/aws/amazon-ecs-ami
7-
# Using 8GB as storage.
8-
ecs_arm_ami = "ami-0bd650c1ca04cc1a4" # make al2023arm
93
}
104

115
# Applications
126

137
module "pretix" {
148
source = "./pretix"
159
count = 1
16-
ecs_arm_ami = local.ecs_arm_ami
1710
server_ip = module.cluster.server_ip
1811
cluster_id = module.cluster.cluster_id
1912
logs_group_name = module.cluster.logs_group_name
13+
database_settings = module.database.database_settings
2014
}
2115

2216
module "pycon_backend" {
2317
source = "./pycon_backend"
24-
ecs_arm_ami = local.ecs_arm_ami
2518
cluster_id = module.cluster.cluster_id
2619
security_group_id = module.cluster.security_group_id
2720
server_ip = module.cluster.server_ip
2821
logs_group_name = module.cluster.logs_group_name
2922
iam_role_arn = module.cluster.iam_role_arn
23+
database_settings = module.database.database_settings
24+
vpc_id = module.vpc.vpc_id
25+
public_1a_subnet_id = module.vpc.public_1a_subnet_id
26+
configuration_set_name = module.emails.configuration_set_name
3027

3128
providers = {
32-
aws = aws
3329
aws.us = aws.us
3430
}
3531
}
@@ -41,49 +37,44 @@ module "pycon_frontend" {
4137
server_ip = module.cluster.server_ip
4238
cf_domain_name = module.cluster.cf_domain_name
4339
cf_hosted_zone_id = module.cluster.cf_hosted_zone_id
44-
45-
providers = {
46-
aws = aws
47-
aws.us = aws.us
48-
}
4940
}
5041

5142
module "clamav" {
5243
source = "./clamav"
5344
cluster_id = module.cluster.cluster_id
5445
logs_group_name = module.cluster.logs_group_name
55-
56-
providers = {
57-
aws = aws
58-
aws.us = aws.us
59-
}
6046
}
6147

6248
# Other resources
6349

6450
module "database" {
6551
source = "./database"
52+
private_subnets_ids = module.vpc.private_subnets_ids
53+
vpc_id = module.vpc.vpc_id
6654
}
6755

6856
module "emails" {
6957
source = "./emails"
7058

7159
providers = {
72-
aws = aws
7360
aws.us = aws.us
7461
}
7562
}
7663

7764
module "cluster" {
7865
source = "./cluster"
79-
ecs_arm_ami = local.ecs_arm_ami
66+
vpc_id = module.vpc.vpc_id
67+
public_1a_subnet_id = module.vpc.public_1a_subnet_id
8068

8169
providers = {
82-
aws = aws
8370
aws.us = aws.us
8471
}
8572
}
8673

74+
module "vpc" {
75+
source = "./vpc"
76+
}
77+
8778
output "server_public_ip" {
8879
value = module.cluster.server_public_ip
8980
}

infrastructure/applications/cluster/cloudfront.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ resource "aws_cloudfront_distribution" "application" {
7373
cache_policy_id = data.aws_cloudfront_cache_policy.origin_cache_control_headers.id
7474
origin_request_policy_id = data.aws_cloudfront_origin_request_policy.all_viewer.id
7575

76-
min_ttl = 0
77-
default_ttl = 86400
78-
max_ttl = 31536000
7976
compress = true
8077
viewer_protocol_policy = "redirect-to-https"
8178
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
configuration_aliases = [aws.us]
6+
}
7+
}
8+
}

infrastructure/applications/cluster/security.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
resource "aws_security_group" "server" {
2-
name = "${terraform.workspace}-server"
3-
description = "${terraform.workspace} server"
4-
vpc_id = data.aws_vpc.default.id
2+
name = "pythonit-${terraform.workspace}-server"
3+
description = "pythonit-${terraform.workspace} server"
4+
vpc_id = var.vpc_id
5+
6+
tags = {
7+
Name = "pythonit-${terraform.workspace}-server"
8+
}
59
}
610

711
resource "aws_security_group_rule" "out_all" {

infrastructure/applications/cluster/server.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ resource "aws_eip" "server" {
1111
}
1212

1313
resource "aws_instance" "server" {
14-
ami = "ami-0d683ccb0045afce1"
14+
ami = "ami-0ce51086755ce7709"
1515
instance_type = local.is_prod ? "t4g.large" : "t4g.small"
16-
subnet_id = data.aws_subnet.public_1a.id
16+
subnet_id = var.public_1a_subnet_id
1717
availability_zone = "eu-central-1a"
1818
vpc_security_group_ids = [
1919
aws_security_group.server.id,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
variable "ecs_arm_ami" {}
1+
variable "vpc_id" {}
2+
variable "public_1a_subnet_id" {}

infrastructure/applications/cluster/vpc.tf

Lines changed: 0 additions & 20 deletions
This file was deleted.

infrastructure/applications/config.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
aws = {
44
source = "hashicorp/aws"
5-
version = "5.70.0"
5+
version = "5.82.2"
66
configuration_aliases = [aws.us]
77
}
88
}

infrastructure/applications/database/db.tf

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ locals {
33
is_prod = terraform.workspace == "production"
44
}
55

6-
data "aws_db_subnet_group" "rds" {
7-
name = "pythonit-rds-subnet"
8-
}
9-
10-
data "aws_security_group" "rds" {
11-
name = "pythonit-rds-security-group"
12-
}
13-
146
resource "aws_db_instance" "database" {
157
allocated_storage = 20
168
storage_type = "gp3"
@@ -31,9 +23,19 @@ resource "aws_db_instance" "database" {
3123
deletion_protection = local.is_prod
3224
storage_encrypted = true
3325

34-
db_subnet_group_name = data.aws_db_subnet_group.rds.name
35-
vpc_security_group_ids = [data.aws_security_group.rds.id]
26+
db_subnet_group_name = aws_db_subnet_group.rds.name
27+
vpc_security_group_ids = [aws_security_group.rds.id]
3628

3729
performance_insights_enabled = true
3830
performance_insights_retention_period = 7
3931
}
32+
33+
output "database_settings" {
34+
value = {
35+
address = aws_db_instance.database.address
36+
port = aws_db_instance.database.port
37+
username = aws_db_instance.database.username
38+
password = module.common_secrets.value.database_password
39+
db_name = aws_db_instance.database.db_name
40+
}
41+
}

0 commit comments

Comments
 (0)