Skip to content

Commit

Permalink
feat: add conversion between iam and primitive roles (#62)
Browse files Browse the repository at this point in the history
* add conversion between iam and primitive roles

* fmt
  • Loading branch information
umairidris authored Apr 28, 2020
1 parent 7d64e2c commit f454638
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

locals {
tables = { for table in var.tables : table["table_id"] => table }
iam_to_primitive = {
"roles/bigquery.dataOwner" : "OWNER"
"roles/bigquery.dataEditor" : "EDITOR"
"roles/bigquery.dataViewer" : "READER"
}
}

resource "google_bigquery_dataset" "main" {
Expand All @@ -31,7 +36,10 @@ resource "google_bigquery_dataset" "main" {
dynamic "access" {
for_each = var.access
content {
role = access.value.role
# BigQuery API converts IAM to primitive roles in its backend.
# This causes Terraform to show a diff on every plan that uses IAM equivalent roles.
# Thus, do the conversion between IAM to primitive role here to prevent the diff.
role = lookup(local.iam_to_primitive, access.value.role, access.value.role)

domain = lookup(access.value, "domain", null)
group_by_email = lookup(access.value, "group_by_email", null)
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ variable "access" {

# At least one owner access is required.
default = [{
role = "OWNER"
role = "roles/bigquery.dataOwner"
special_group = "projectOwners"
}]
}
Expand Down

0 comments on commit f454638

Please sign in to comment.