Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLT-697:Apply shared terraform for database to BCDA test #164

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

christopher-maboh
Copy link
Contributor

@christopher-maboh christopher-maboh commented Jan 16, 2025

🎫 Ticket

PLT-697

🛠 Changes

BCDA was added to app in api-res-plan workflow

ℹ️ Context

switching out management of database infra from bcda-ops to platform

🧪 Validation

See terraform plans in checks.

@christopher-maboh christopher-maboh requested a review from gsf January 16, 2025 19:02
@christopher-maboh christopher-maboh requested a review from a team as a code owner January 16, 2025 19:02
@christopher-maboh christopher-maboh removed the request for review from gsf January 21, 2025 14:30
@christopher-maboh christopher-maboh requested a review from gsf January 22, 2025 17:27
@christopher-maboh
Copy link
Contributor Author

one of the bcda environment fails (bcda-opensbx) fails due to environment naming conflict. ab2d has ab2d-sbx and bcda has bcda-opensbx. no backend configuration doe bcda-opensbx but for bcda-sbx.

Also AB2D has some minor changes as a result to this integration

Copy link
Member

@gsf gsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that in the terraform plans, new resources will be created in BCDA environments. Instead, existing resources should be imported into the tfstate, resulting in the fewest changes possible.

"bcda-${var.env}-vpn-public",
"bcda-${var.env}-remote-management",
"bcda-${var.env}-enterprise-tools"
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these called "gedit" security groups?

var.app == "bcda" && var.env != "opensbx" ? ["${var.app}-${var.env}-az1-data", "${var.app}-${var.env}-az2-data", "${var.app}-${var.env}-az3-data"] : []
])
}
}
Copy link
Member

@gsf gsf Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than "count = var.app" on these subnet resources, there should be one data "aws_subnets" "db" resource that has a ternary on the filter values for each app. Also, we can drop the "az3-data" subnet from bcda. The only database in that us-east-1c subnet is dev and it can be restored in another subnet after the change is applied.

username = data.aws_secretsmanager_secret_version.database_user.secret_string
password = data.aws_secretsmanager_secret_version.database_password.secret_string
kms_key_id = var.app == "ab2d" && length(data.aws_kms_alias.main_kms) > 0 ? data.aws_kms_alias.main_kms[0].target_key_arn : null
multi_az = var.app == "bcda" ? true : local.db_name == "ab2d-east-prod"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the prod environment in each app should be multi-az.

multi_az = var.app == "bcda" ? true : local.db_name == "ab2d-east-prod"
vpc_security_group_ids = var.app == "bcda" ? concat([aws_security_group.sg_database.id], local.gedit_security_group_ids) : [aws_security_group.sg_database.id]
username = var.app == "bcda" && length(data.aws_secretsmanager_secret_version.database_secret_version) > 0 ? jsondecode(data.aws_secretsmanager_secret_version.database_secret_version[0].secret_string)["username"] : var.app == "ab2d" && length(data.aws_secretsmanager_secret_version.database_user) > 0 ? data.aws_secretsmanager_secret_version.database_user[0].secret_string : null
password = var.app == "bcda" && length(data.aws_secretsmanager_secret_version.database_secret_version) > 0 ? jsondecode(data.aws_secretsmanager_secret_version.database_secret_version[0].secret_string)["password"] : var.app == "ab2d" && length(data.aws_secretsmanager_secret_version.database_user) > 0 ? data.aws_secretsmanager_secret_version.database_user[0].secret_string : null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional on username and password is difficult to read and will only get worse if we continue in this direction with dpc. Instead, try creating username and password secrets for BCDA via the AWS console under this naming scheme: ${var.app}/${var.env}/db/username and ${var.app}/${var.env}/db/password. Use a ternary on the name for data "aws_secretsmanager_secret" "db_password" and data "aws_secretsmanager_secret" "db_password" resources for all three apps.

@christopher-maboh
Copy link
Contributor Author

I see that in the terraform plans, new resources will be created in BCDA environments. Instead, existing resources should be imported into the tfstate, resulting in the fewest changes possible.

I have imported aws_db_instance.api, aws_db_subnet_group.subnet_group, aws_route53_record.rds[0] and aws_route53_zone.local_zone[0] in test environment. I haven't imported aws_security_group.sg_database because it hasn't been created in bcda account. I also haven't imported aws_vpc_security_group_ingress_rule.db_access_from_mgmt and aws_vpc_security_group_ingress_rule.db_access_from_jenkins_agent because it involves aws_security_group.sg_database and the security group ID is unknown since it hasn't been created yet in the bcda account

@christopher-maboh
Copy link
Contributor Author

I also noticed the difference in naming convention for "${local.db_name}-rds-parameter-group-v16" as in environment its like this dev-rds-parameter-group-v16 (doesn't have application name) and so I haven't yet imported the resource

also terraform plan for bcda-prod fails because I haven't yet created ${var.app}/${var.env}/db/password for prod because I initial omitted a letter in the password upon creating it and so I had to delete and re-create but AWS has a 7 day wait period to do so. I recreate it on Monday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants