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

use customizediff to allow all role-entity pairs to be unordered #1787

Merged
merged 1 commit into from
Jul 24, 2018
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
4 changes: 2 additions & 2 deletions google/resource_storage_bucket_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func resourceStorageBucketAcl() *schema.Resource {
Read: resourceStorageBucketAclRead,
Update: resourceStorageBucketAclUpdate,
Delete: resourceStorageBucketAclDelete,
CustomizeDiff: resourceStorageBucketAclCustomizeDiff,
CustomizeDiff: resourceStorageRoleEntityCustomizeDiff,

Schema: map[string]*schema.Schema{
"bucket": &schema.Schema{
Expand Down Expand Up @@ -49,7 +49,7 @@ func resourceStorageBucketAcl() *schema.Resource {
}
}

func resourceStorageBucketAclCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error {
func resourceStorageRoleEntityCustomizeDiff(diff *schema.ResourceDiff, meta interface{}) error {
keys := diff.GetChangedKeysPrefix("role_entity")
if len(keys) < 1 {
return nil
Expand Down
12 changes: 7 additions & 5 deletions google/resource_storage_default_object_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

func resourceStorageDefaultObjectAcl() *schema.Resource {
return &schema.Resource{
Create: resourceStorageDefaultObjectAclCreate,
Read: resourceStorageDefaultObjectAclRead,
Update: resourceStorageDefaultObjectAclUpdate,
Delete: resourceStorageDefaultObjectAclDelete,
Create: resourceStorageDefaultObjectAclCreate,
Read: resourceStorageDefaultObjectAclRead,
Update: resourceStorageDefaultObjectAclUpdate,
Delete: resourceStorageDefaultObjectAclDelete,
CustomizeDiff: resourceStorageRoleEntityCustomizeDiff,

Schema: map[string]*schema.Schema{
"bucket": &schema.Schema{
Expand All @@ -24,7 +25,8 @@ func resourceStorageDefaultObjectAcl() *schema.Resource {

"role_entity": &schema.Schema{
Type: schema.TypeList,
Required: true,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
MinItems: 1,
},
Expand Down
31 changes: 31 additions & 0 deletions google/resource_storage_default_object_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ func TestAccStorageDefaultObjectAcl_downgrade(t *testing.T) {
})
}

// Test that we allow the API to reorder our role entities without perma-diffing.
func TestAccStorageDefaultObjectAcl_unordered(t *testing.T) {
t.Parallel()

bucketName := testBucketName()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccStorageDefaultObjectAclDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testGoogleStorageDefaultObjectAclUnordered(bucketName),
},
},
})
}

func testAccCheckGoogleStorageDefaultObjectAcl(bucket, roleEntityS string) resource.TestCheckFunc {
return func(s *terraform.State) error {
roleEntity, _ := getRoleEntityPair(roleEntityS)
Expand Down Expand Up @@ -185,3 +203,16 @@ resource "google_storage_default_object_acl" "acl" {
}
`, bucketName, roleEntity1, roleEntity2)
}

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

resource "google_storage_default_object_acl" "acl" {
bucket = "${google_storage_bucket.bucket.name}"
role_entity = ["%s", "%s", "%s", "%s", "%s"]
}
`, bucketName, roleEntityBasic1, roleEntityViewers, roleEntityOwners, roleEntityBasic2, roleEntityEditors)
}
10 changes: 6 additions & 4 deletions google/resource_storage_object_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (

func resourceStorageObjectAcl() *schema.Resource {
return &schema.Resource{
Create: resourceStorageObjectAclCreate,
Read: resourceStorageObjectAclRead,
Update: resourceStorageObjectAclUpdate,
Delete: resourceStorageObjectAclDelete,
Create: resourceStorageObjectAclCreate,
Read: resourceStorageObjectAclRead,
Update: resourceStorageObjectAclUpdate,
Delete: resourceStorageObjectAclDelete,
CustomizeDiff: resourceStorageRoleEntityCustomizeDiff,

Schema: map[string]*schema.Schema{
"bucket": &schema.Schema{
Expand All @@ -38,6 +39,7 @@ func resourceStorageObjectAcl() *schema.Resource {
"role_entity": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
Expand Down
46 changes: 45 additions & 1 deletion google/resource_storage_object_acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
//"google.golang.org/api/storage/v1"
)

var tfObjectAcl, errObjectAcl = ioutil.TempFile("", "tf-gce-test")
Expand Down Expand Up @@ -177,6 +176,31 @@ func TestAccStorageObjectAcl_predefined(t *testing.T) {
})
}

// Test that we allow the API to reorder our role entities without perma-diffing.
func TestAccStorageObjectAcl_unordered(t *testing.T) {
t.Parallel()

bucketName := testBucketName()
objectName := testAclObjectName()
objectData := []byte("data data data")
ioutil.WriteFile(tfObjectAcl.Name(), objectData, 0644)
resource.Test(t, resource.TestCase{
PreCheck: func() {
if errObjectAcl != nil {
panic(errObjectAcl)
}
testAccPreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccStorageObjectAclDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testGoogleStorageObjectAclUnordered(bucketName, objectName),
},
},
})
}

func testAccCheckGoogleStorageObjectAcl(bucket, object, roleEntityS string) resource.TestCheckFunc {
return func(s *terraform.State) error {
roleEntity, _ := getRoleEntityPair(roleEntityS)
Expand Down Expand Up @@ -336,3 +360,23 @@ resource "google_storage_object_acl" "acl" {
}
`, bucketName, objectName, tfObjectAcl.Name())
}

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

resource "google_storage_bucket_object" "object" {
name = "%s"
bucket = "${google_storage_bucket.bucket.name}"
source = "%s"
}

resource "google_storage_object_acl" "acl" {
object = "${google_storage_bucket_object.object.name}"
bucket = "${google_storage_bucket.bucket.name}"
role_entity = ["%s", "%s", "%s", "%s", "%s"]
}
`, bucketName, objectName, tfObjectAcl.Name(), roleEntityBasic1, roleEntityViewers, roleEntityOwners, roleEntityBasic2, roleEntityEditors)
}