Skip to content

Commit

Permalink
update to add special groups without prefixes to map
Browse files Browse the repository at this point in the history
  • Loading branch information
megan07 committed Aug 14, 2020
1 parent 624e12a commit 35b05b7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
36 changes: 25 additions & 11 deletions templates/terraform/constants/bigquery_dataset_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ var bigqueryAccessRoleToPrimitiveMap = map[string]string {
}

var bigqueryAccessIamMemberToTypeMap = map[string]string{
"serviceAccount": "user_by_email",
"user": "user_by_email",
"group": "group_by_email",
"domain": "domain",
"specialGroup": "special_group",
"serviceAccount": "user_by_email",
"user": "user_by_email",
"group": "group_by_email",
"domain": "domain",
"specialGroup": "special_group",
"allUsers": "iam_member",
"projectOwners": "special_group",
"projectReaders": "special_group",
"projectWriters": "special_group",
"allAuthenticatedUsers": "special_group",
}

func resourceBigQueryDatasetAccessRoleDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
Expand All @@ -32,21 +37,30 @@ func customDiffBigQueryDatasetAccess(d *schema.ResourceDiff, meta interface{}) e
_, configValue := d.GetChange("iam_member")

parts := strings.Split(configValue.(string), ":")
if len(parts) != 2 {
if len(parts) > 2 {
return nil
}

var key string
var value string
if k, ok := bigqueryAccessIamMemberToTypeMap[parts[0]]; !ok {
return nil
key = "iam_member"
} else {
key = k
}

if err := d.Clear("iam_member"); err != nil {
return err
}
if len(parts) == 1 {
value = parts[0]
} else {
value = parts[1]
}
value := parts[1]

if key == "iam_member" {
return nil
}

if err := d.Clear("iam_member"); err != nil {
return err
}
return d.SetNew(key, value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ func TestAccBigQueryDatasetAccess_allUsers(t *testing.T) {
})
}

func TestAccBigQueryDatasetAccess_allAuthenticatedUsers(t *testing.T) {
t.Parallel()

datasetID := fmt.Sprintf("tf_test_%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccBigQueryDatasetAccess_allAuthenticatedUsers(datasetID),
},
},
})
}

func testAccCheckBigQueryDatasetAccessPresent(t *testing.T, n string, expected map[string]interface{}) resource.TestCheckFunc {
return testAccCheckBigQueryDatasetAccess(t, n, expected, true)
}
Expand Down Expand Up @@ -354,3 +370,17 @@ resource "google_bigquery_dataset" "dataset" {
}
`, datasetID)
}

func testAccBigQueryDatasetAccess_allAuthenticatedUsers(datasetID string) string {
return fmt.Sprintf(`
resource "google_bigquery_dataset_access" "dns_query_sink" {
dataset_id = google_bigquery_dataset.dataset.dataset_id
role = "roles/bigquery.dataEditor"
iam_member = "allAuthenticatedUsers"
}
resource "google_bigquery_dataset" "dataset" {
dataset_id = "%s"
}
`, datasetID)
}

0 comments on commit 35b05b7

Please sign in to comment.