Skip to content

Commit 8780714

Browse files
fix: Backup - set IAM conditions conditionally (#616)
Co-authored-by: Imran Nayer <[email protected]>
1 parent 83bbaa3 commit 8780714

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

modules/backup/main.tf

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,20 @@ resource "google_project_iam_member" "sql_backup_serviceaccount_sql_admin" {
4242
member = "serviceAccount:${google_service_account.sql_backup_serviceaccount[0].email}"
4343
role = local.role_name
4444
project = var.project_id
45-
condition {
46-
title = "Limit access to instance ${var.sql_instance}"
47-
expression = <<-EOT
48-
(resource.type == "sqladmin.googleapis.com/Instance" &&
49-
resource.name == "projects/${var.project_id}/instances/${var.sql_instance}")
50-
EOT
45+
# It is not possible to limit access to a specific instance when exports are enabled.
46+
# The export workflow needs to be able to list databases for the database instance.
47+
# It currently is not possible to define a condition that limits access to these
48+
# sub-resources/database resources. Only Instances and BackupRuns are supported:
49+
# https://cloud.google.com/iam/docs/conditions-resource-attributes#resource-type
50+
dynamic "condition" {
51+
for_each = var.enable_export_backup ? [] : [1]
52+
content {
53+
title = "Limit access to instance ${var.sql_instance}"
54+
expression = <<-EOT
55+
(resource.type == "sqladmin.googleapis.com/Instance" &&
56+
resource.name == "projects/${var.project_id}/instances/${var.sql_instance}")
57+
EOT
58+
}
5159
}
5260
}
5361

0 commit comments

Comments
 (0)