-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vpc and subnets moved to base from infra deptrack in its own state
- Loading branch information
Showing
25 changed files
with
441 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cf-apitoken: ENC[AES256_GCM,data:A2YLlySRGyu+ep7z3BzDncW1NNaQZNE6cgTuT5gOY1ABevCzsn4GvQ==,iv:XLfigdcS6frnGgZF8aNkwd44NuzpRoyDJVSmwmICnxI=,tag:qPXXFaJuB1cA0YiD6QNpUA==,type:str] | ||
sops: | ||
kms: | ||
- arn: arn:aws:kms:eu-central-1:754489498669:key/215a7274-5652-4521-8a88-b18e02b8f13e | ||
created_at: "2024-04-22T11:26:03Z" | ||
enc: AQICAHiDjTyDzev9deXqMt8qn7IIVL95PjWZTOOP+RjKHUtt0AGB9x1TONOwrvyTm8MFZsdEAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMbN0DMeuAO5lF4MCYAgEQgDv/bkLvMrGB6MKBVBUH7DrYBYFAVjfNHDFp24p+sz1CENoWPEukBJ29LokE7qvxBqxop7d+Ft7oRjfxIg== | ||
aws_profile: "" | ||
gcp_kms: [] | ||
azure_kv: [] | ||
hc_vault: [] | ||
age: [] | ||
lastmodified: "2024-04-22T11:26:08Z" | ||
mac: ENC[AES256_GCM,data:9qXuXGLkR9zMAXewMuFmSnPF8Ecga6aJ/9DixPCkeEd/3Ku/N2RbkPTERV5F5SzpFq0n7ObXZnbjTDJKsMGdj7f5t7Vl9Ou+civ/m97IJO4cFaCPGMBiipVRzmJrGXkLTG/VqC/e4+Hpi0DrKJ9B55qwwkbAoxzvEEpmaI9cOY8=,iv:4fKo4a3QdXgy8lbYYVRnT0+bm/F+CwqRoxslnBD5Lpw=,tag:nguzQpfCz2kCUTIpZDNxTQ==,type:str] | ||
pgp: [] | ||
unencrypted_suffix: _unencrypted | ||
version: 3.8.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# DNS and wildcard certificate for *.dev.tyk.technology | ||
|
||
provider "cloudflare" { | ||
api_token = data.sops_file.secrets.data["cf-apitoken"] | ||
# account_id = "35b8134b47c7d01ee8198bb2b82a8dc5" | ||
} | ||
|
||
resource "cloudflare_record" "dev_tyk_tech" { | ||
for_each = toset(aws_route53_zone.dev_tyk_tech.name_servers) | ||
depends_on = [aws_route53_zone.dev_tyk_tech] | ||
|
||
# This is the tyk.technology zone | ||
zone_id = "f3ee9e1c1e0e47f8ab60fae66d39aa8f" | ||
name = "dev" | ||
type = "NS" | ||
value = each.value | ||
} | ||
|
||
resource "aws_route53_zone" "dev_tyk_tech" { | ||
name = "dev.tyk.technology" | ||
} | ||
|
||
# One wildcard cert | ||
|
||
resource "aws_acm_certificate" "dev_tyk_tech" { | ||
domain_name = "*.dev.tyk.technology" | ||
validation_method = "DNS" | ||
} | ||
|
||
resource "aws_route53_record" "dev_tyk_tech" { | ||
for_each = { | ||
for dvo in aws_acm_certificate.dev_tyk_tech.domain_validation_options : dvo.domain_name => { | ||
name = dvo.resource_record_name | ||
record = dvo.resource_record_value | ||
type = dvo.resource_record_type | ||
} | ||
} | ||
|
||
allow_overwrite = true | ||
name = each.value.name | ||
records = [each.value.record] | ||
ttl = 60 | ||
type = each.value.type | ||
zone_id = aws_route53_zone.dev_tyk_tech.zone_id | ||
} | ||
|
||
resource "aws_acm_certificate_validation" "dev_tyk_tech" { | ||
certificate_arn = aws_acm_certificate.dev_tyk_tech.arn | ||
validation_record_fqdns = [for record in aws_route53_record.dev_tyk_tech : record.fqdn] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
locals { | ||
pg_port = 5432 | ||
} | ||
|
||
module "rds_sg" { | ||
source = "terraform-aws-modules/security-group/aws" | ||
|
||
name = "deptrack-db" | ||
description = "RDS PostgreSQL" | ||
vpc_id = module.vpc.vpc_id | ||
|
||
# ingress | ||
ingress_with_cidr_blocks = [ | ||
{ | ||
from_port = local.pg_port | ||
to_port = local.pg_port | ||
protocol = "tcp" | ||
description = "PostgreSQL access from within VPC" | ||
cidr_blocks = module.vpc.vpc_cidr_block | ||
}, | ||
] | ||
} | ||
|
||
resource "random_password" "rds_master" { | ||
length = 16 | ||
lower = false | ||
} | ||
|
||
module "rds" { | ||
source = "terraform-aws-modules/rds/aws" | ||
|
||
identifier = "postgres15" | ||
|
||
# All available versions: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html#PostgreSQL.Concepts | ||
engine = "postgres" | ||
engine_version = "15" | ||
family = "postgres15" # DB parameter group | ||
major_engine_version = "15" # DB option group | ||
instance_class = "db.t4g.medium" | ||
allocated_storage = 10 | ||
max_allocated_storage = 50 | ||
|
||
# NOTE: Do NOT use 'user' as the value for 'username' as it throws: | ||
# "Error creating DB Instance: InvalidParameterValue: MasterUsername | ||
# user cannot be used as it is a reserved word used by the engine" | ||
username = "master" | ||
# The password is stored in the state | ||
password = random_password.rds_master.result | ||
port = local.pg_port | ||
|
||
create_db_subnet_group = false | ||
multi_az = true | ||
db_subnet_group_name = module.vpc.database_subnet_group_name | ||
vpc_security_group_ids = [module.rds_sg.security_group_id] | ||
|
||
maintenance_window = "Mon:00:00-Mon:03:00" | ||
backup_window = "03:00-06:00" | ||
enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"] | ||
create_cloudwatch_log_group = true | ||
|
||
backup_retention_period = 1 | ||
skip_final_snapshot = true | ||
# TODO: turn on deletion protection when stable | ||
deletion_protection = false | ||
|
||
performance_insights_enabled = true | ||
performance_insights_retention_period = 7 | ||
create_monitoring_role = true | ||
monitoring_interval = 60 | ||
monitoring_role_name = "rds-monitoring" | ||
monitoring_role_use_name_prefix = false | ||
monitoring_role_description = "Role to ship enhanced monitoring to CloudWatch" | ||
|
||
parameters = [ | ||
{ | ||
name = "autovacuum" | ||
value = 1 | ||
}, | ||
{ | ||
name = "client_encoding" | ||
value = "utf8" | ||
} | ||
] | ||
|
||
db_option_group_tags = { | ||
"Sensitive" = "low" | ||
} | ||
db_parameter_group_tags = { | ||
"Sensitive" = "low" | ||
} | ||
} | ||
|
||
resource "aws_ssm_parameter" "rds_master" { | ||
name = "/${local.name}/rds/master" | ||
type = "SecureString" | ||
description = "Password for the RDS master user" | ||
value = random_password.rds_master.result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
provider "sops" {} | ||
|
||
data "sops_file" "secrets" { | ||
source_file = "secrets.yaml" | ||
source_file = "base-secrets.yaml" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
locals { | ||
cidr = "10.91.0.0/16" | ||
} | ||
|
||
data "aws_availability_zones" "available" { | ||
state = "available" | ||
} | ||
|
||
module "private_subnets" { | ||
source = "hashicorp/subnets/cidr" | ||
|
||
base_cidr_block = cidrsubnet(local.cidr, 4, 1) | ||
networks = [ | ||
{ name = "privaz1", new_bits = 4 }, | ||
{ name = "privaz2", new_bits = 4 }, | ||
{ name = "privaz3", new_bits = 4 }, | ||
] | ||
} | ||
|
||
module "db_subnets" { | ||
source = "hashicorp/subnets/cidr" | ||
|
||
base_cidr_block = cidrsubnet(local.cidr, 4, 8) | ||
networks = [ | ||
{ name = "pubaz1", new_bits = 4 }, | ||
{ name = "pubaz2", new_bits = 4 }, | ||
{ name = "pubaz3", new_bits = 4 }, | ||
] | ||
} | ||
|
||
module "public_subnets" { | ||
source = "hashicorp/subnets/cidr" | ||
|
||
base_cidr_block = cidrsubnet(local.cidr, 4, 15) | ||
networks = [ | ||
{ name = "pubaz1", new_bits = 4 }, | ||
{ name = "pubaz2", new_bits = 4 }, | ||
{ name = "pubaz3", new_bits = 4 }, | ||
] | ||
} | ||
|
||
module "vpc" { | ||
source = "terraform-aws-modules/vpc/aws" | ||
|
||
name = "infra" | ||
cidr = local.cidr | ||
|
||
azs = data.aws_availability_zones.available.names | ||
private_subnets = module.private_subnets.networks[*].cidr_block | ||
private_subnet_tags = { Type = "private" } | ||
database_subnets = module.db_subnets.networks[*].cidr_block | ||
database_subnet_tags = { Type = "rds" } | ||
public_subnets = module.public_subnets.networks[*].cidr_block | ||
public_subnet_tags = { Type = "public" } | ||
|
||
create_database_subnet_group = true | ||
enable_nat_gateway = true | ||
single_nat_gateway = true | ||
map_public_ip_on_launch = true | ||
|
||
# Need DNS to address EFS by name | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
for s in $(aws ecs list-services --cluster $1 | jq -r ".serviceArns[]") | ||
do | ||
aws ecs update-service --cluster $1 --service $s --desired-count 0 > ${1}.log | ||
aws ecs delete-service --cluster $1 --service $s >> ${1}.log | ||
done | ||
echo Waiting for services to become inactive for $1 ... | ||
aws ecs wait services-inactive --cluster $1 --services tyk tyk-analytics tyk-pump redis | ||
aws ecs delete-cluster --cluster $1 >> ${1}.log || cat $1.log | ||
rm ${1}.log |
Oops, something went wrong.