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

[Issue #1943] Fix variable access #1945

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions infra/analytics/metabase/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ module "service" {
ssm_param_name = "/metabase/${var.environment_name}/db_pass"
},
]

app_access_policy_arn = null
migrator_access_policy_arn = null

db_vars = {
security_group_ids = data.aws_rds_cluster.db_cluster.vpc_security_group_ids
app_access_policy_arn = null
migrator_access_policy_arn = null
security_group_ids = data.aws_rds_cluster.db_cluster.vpc_security_group_ids
connection_info = {
host = data.aws_rds_cluster.db_cluster.endpoint
port = data.aws_rds_cluster.db_cluster.port
Expand Down
7 changes: 4 additions & 3 deletions infra/api/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ module "service" {

cert_arn = local.domain != null ? data.aws_acm_certificate.cert[0].arn : null

app_access_policy_arn = data.aws_iam_policy.app_db_access_policy[0].arn
migrator_access_policy_arn = data.aws_iam_policy.migrator_db_access_policy[0].arn

db_vars = module.app_config.has_database ? {
security_group_ids = data.aws_rds_cluster.db_cluster[0].vpc_security_group_ids
app_access_policy_arn = data.aws_iam_policy.app_db_access_policy[0].arn
migrator_access_policy_arn = data.aws_iam_policy.migrator_db_access_policy[0].arn
security_group_ids = data.aws_rds_cluster.db_cluster[0].vpc_security_group_ids
connection_info = {
host = data.aws_rds_cluster.db_cluster[0].endpoint
port = data.aws_rds_cluster.db_cluster[0].port
Expand Down
7 changes: 4 additions & 3 deletions infra/frontend/service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ module "service" {
cert_arn = terraform.workspace == "default" ? data.aws_acm_certificate.cert[0].arn : null
hostname = module.app_config.hostname

app_access_policy_arn = null
migrator_access_policy_arn = null

db_vars = module.app_config.has_database ? {
security_group_ids = data.aws_rds_cluster.db_cluster[0].vpc_security_group_ids
app_access_policy_arn = data.aws_iam_policy.app_db_access_policy[0].arn
migrator_access_policy_arn = data.aws_iam_policy.migrator_db_access_policy[0].arn
security_group_ids = data.aws_rds_cluster.db_cluster[0].vpc_security_group_ids
connection_info = {
host = data.aws_rds_cluster.db_cluster[0].endpoint
port = data.aws_rds_cluster.db_cluster[0].port
Expand Down
8 changes: 4 additions & 4 deletions infra/modules/service/database-access.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ resource "aws_vpc_security_group_ingress_rule" "db_ingress_from_service" {
}

resource "aws_iam_role_policy_attachment" "app_service_db_access" {
count = var.db_vars != null && var.db_vars.app_access_policy_arn != null ? 1 : 0
count = var.app_access_policy_arn != null ? 1 : 0

role = aws_iam_role.app_service.name
policy_arn = var.db_vars.app_access_policy_arn
policy_arn = var.app_access_policy_arn
}

resource "aws_iam_role_policy_attachment" "migrator_db_access" {
count = var.db_vars != null && var.db_vars.migrator_access_policy_arn != null ? 1 : 0
count = var.migrator_access_policy_arn != null ? 1 : 0

role = aws_iam_role.migrator_task[0].name
policy_arn = var.db_vars.migrator_access_policy_arn
policy_arn = var.migrator_access_policy_arn
}
16 changes: 13 additions & 3 deletions infra/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ variable "secrets" {
variable "db_vars" {
description = "Variables for integrating the app service with a database"
type = object({
security_group_ids = list(string)
app_access_policy_arn = string
migrator_access_policy_arn = string
security_group_ids = list(string)
connection_info = object({
host = string
port = string
Expand All @@ -101,6 +99,18 @@ variable "db_vars" {
default = null
}

variable "app_access_policy_arn" {
description = "The ARN of the IAM policy to attach to the app service role for database access"
type = string
default = null
}

variable "migrator_access_policy_arn" {
description = "The ARN of the IAM policy to attach to the migrator task role for database access"
type = string
default = null
}

variable "extra_policies" {
description = "Map of extra IAM policies to attach to the service's task role. The map's keys define the resource name in terraform."
type = map(string)
Expand Down
Loading