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

Improve storage bucket acls #2955

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
stop project-owner from causing a diff
  • Loading branch information
chrisst authored and modular-magician committed Jan 22, 2020
commit dfb2be5671df6bc110cdc5666f77331eea0ea4e1
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func resourceStorageRoleEntityCustomizeDiff(diff *schema.ResourceDiff, meta inte
conf := map[string]struct{}{}
for i := 0; i < count; i++ {
old, new := diff.GetChange(fmt.Sprintf("role_entity.%d", i))

// project-owners- is explicitly stripped from the roles that this
// resource will delete
if strings.Contains(old.(string), "OWNER:project-owners-") {
continue
}

state[old.(string)] = struct{}{}
conf[new.(string)] = struct{}{}
}
Expand Down
32 changes: 32 additions & 0 deletions third_party/terraform/tests/resource_storage_bucket_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ func TestAccStorageBucketAcl_unordered(t *testing.T) {
})
}

// Test that project owner doesn't get removed or cause a diff
func TestAccStorageBucketAcl_RemoveOwner(t *testing.T) {
t.Parallel()

bucketName := testBucketName()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccStorageBucketAclDestroy,
Steps: []resource.TestStep{
{
Config: testGoogleStorageBucketsAclRemoveOwner(bucketName),
},
},
})
}

func testAccCheckGoogleStorageBucketAclDelete(bucket, roleEntityS string) resource.TestCheckFunc {
return func(s *terraform.State) error {
roleEntity, _ := getRoleEntityPair(roleEntityS)
Expand Down Expand Up @@ -283,3 +300,18 @@ resource "google_storage_bucket_acl" "acl" {
}
`, bucketName)
}

func testGoogleStorageBucketsAclRemoveOwner(bucketName string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "bucket" {
name = "%s"
}

resource "google_storage_bucket_acl" "acl" {
bucket = google_storage_bucket.bucket.name
role_entity = [
"READER:[email protected]"
]
}
`, bucketName)
}