fleet/infrastructure/sandbox/SharedInfrastructure/rds.tf
Zachary Winnerman 9338fcbcbd
Fleet Sandbox (#5079)
* Add code for the shared infra part of the demo environment

* Checkin

* checkin

* Checkin for pre-provisioner, got terraform working

* Checkin with the pre-deployer working, now blocked by helm chart

* Add interface for helm

* Add some initial code for the JIT Provisioner lambda

Lots of code taken from https://gitlab.com/hmajid2301/articles/-/tree/master/41.%20Create%20a%20webapp%20with%20fizz

* Update helm chart to work with shared infra (#5621)

* Update helm chart to work with shared infra

* Update helm chart README to reflect changes.

* Checkin

* Checkin

* Checkin, Pre-provisioner actually works

* PreProvisioner is now complete

* Make changes to the JIT provisioner based off of actually learning how
to do stuff

* checkin

* Check in, broken currently

* Add all code except provisioning and emailing user

* Checkin

* Checkin, fixed kubernetes

* Checkin

* Forgot a file

* Finish jit provisioner, need to test now

* Checkin, switching to nginx ingress

* Fleets are now actually accessible

* JITProvisioner now returns working fleet instances

* Deprovisioner code done, just need a few bugs fixed

* Fix the deprovisioner so it works now and re-ip

* fixup

* Finished testing the deprovisioner

* Added monitoring and fixed some bugs

* Add stuff for #6548

* fixed per luke's suggestion

* Fix for inactive task definition arns

* move everything to the prod account

* Bump fleet version and fix a couple of bugs

* Fix a couple of bugs

* Lots of security fixes and a few bug fixes

* Rename demo to sandbox to match product's naming

* Revert "Update helm chart to work with shared infra (#5621)"

This reverts commit 610bbd1c00.

Co-authored-by: Robert Fairburn <8029478+rfairburn@users.noreply.github.com>
2022-07-19 13:56:53 -05:00

95 lines
3 KiB
HCL

resource "random_password" "database_password" {
length = 16
special = false
}
resource "aws_kms_key" "main" {
description = "${var.prefix}-${random_pet.db_secret_postfix.id}"
deletion_window_in_days = 10
enable_key_rotation = true
}
resource "random_pet" "db_secret_postfix" {
length = 1
}
resource "aws_secretsmanager_secret" "database_password_secret" {
name = "/fleet/database/password/master-2-${random_pet.db_secret_postfix.id}"
kms_key_id = aws_kms_key.main.id
}
resource "aws_secretsmanager_secret_version" "database_password_secret_version" {
secret_id = aws_secretsmanager_secret.database_password_secret.id
secret_string = random_password.database_password.result
}
resource "aws_secretsmanager_secret" "mysql" {
name = "/fleet/database/password/mysql-${random_pet.db_secret_postfix.id}"
kms_key_id = aws_kms_key.main.id
}
output "mysql_secret" {
value = aws_secretsmanager_secret.mysql
}
resource "aws_secretsmanager_secret_version" "mysql" {
secret_id = aws_secretsmanager_secret.mysql.id
secret_string = jsonencode({
endpoint = module.main.cluster_endpoint
username = module.main.cluster_master_username
password = module.main.cluster_master_password
})
}
module "main" {
source = "terraform-aws-modules/rds-aurora/aws"
version = "6.2.0"
name = var.prefix
engine = "aurora-mysql"
engine_version = "5.7.mysql_aurora.2.10.0"
engine_mode = "serverless"
storage_encrypted = true
master_username = "fleet"
master_password = random_password.database_password.result
create_random_password = false
enable_http_endpoint = false
performance_insights_enabled = true
vpc_id = var.vpc.vpc_id
subnets = var.vpc.database_subnets
create_security_group = true
allowed_security_groups = var.allowed_security_groups
allowed_cidr_blocks = ["10.0.0.0/8"]
kms_key_id = aws_kms_key.main.arn
performance_insights_kms_key_id = aws_kms_key.main.arn
monitoring_interval = 60
apply_immediately = true
skip_final_snapshot = true
db_parameter_group_name = aws_db_parameter_group.main.id
db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.main.id
scaling_configuration = {
auto_pause = true
min_capacity = 2
max_capacity = 16
seconds_until_auto_pause = 300
timeout_action = "ForceApplyCapacityChange"
}
}
resource "aws_db_parameter_group" "main" {
name = "${var.prefix}-aurora-db-mysql-parameter-group"
family = "aurora-mysql5.7"
description = "${var.prefix}-aurora-db-mysql-parameter-group"
}
resource "aws_rds_cluster_parameter_group" "main" {
name = "${var.prefix}-aurora-mysql-cluster-parameter-group"
family = "aurora-mysql5.7"
description = "${var.prefix}-aurora-mysql-cluster-parameter-group"
}