-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for google_storage_object_access_control
- Loading branch information
1 parent
40ebce2
commit 732a2bb
Showing
5 changed files
with
641 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
// | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// This file is automatically generated by Magic Modules and manual | ||
// changes will be clobbered when the file is regenerated. | ||
// | ||
// Please read more about how to change this file in | ||
// .github/CONTRIBUTING.md. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
package google | ||
|
||
import "github.com/hashicorp/terraform/helper/schema" | ||
|
||
var GeneratedStorageResourcesMap = map[string]*schema.Resource{ | ||
"google_storage_object_access_control": resourceStorageObjectAccessControl(), | ||
} |
125 changes: 125 additions & 0 deletions
125
google/resource_google_storage_object_access_control_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccStorageObjectAccessControl_basic(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: testAccStorageObjectAccessControlDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testGoogleStorageObjectAccessControlBasic(bucketName, objectName, "READER", "allUsers"), | ||
}, | ||
{ | ||
ResourceName: "google_storage_object_access_control.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccStorageObjectAccessControl_update(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: testAccStorageObjectAccessControlDestroy, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testGoogleStorageObjectAccessControlBasic(bucketName, objectName, "READER", "allUsers"), | ||
}, | ||
{ | ||
ResourceName: "google_storage_object_access_control.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
resource.TestStep{ | ||
Config: testGoogleStorageObjectAccessControlBasic(bucketName, objectName, "OWNER", "allUsers"), | ||
}, | ||
{ | ||
ResourceName: "google_storage_object_access_control.default", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccStorageObjectAccessControlDestroy(s *terraform.State) error { | ||
config := testAccProvider.Meta().(*Config) | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "google_storage_bucket_acl" { | ||
continue | ||
} | ||
|
||
bucket := rs.Primary.Attributes["bucket"] | ||
object := rs.Primary.Attributes["object"] | ||
entity := rs.Primary.Attributes["entity"] | ||
|
||
rePairs, err := config.clientStorage.ObjectAccessControls.List(bucket, object).Do() | ||
if err != nil { | ||
return fmt.Errorf("Can't list role entity acl for object %s in bucket %s", object, bucket) | ||
} | ||
|
||
for _, v := range rePairs.Items { | ||
if v.Entity == entity { | ||
return fmt.Errorf("found entity %s as role entity acl entry for object %s in bucket %s", entity, object, bucket) | ||
} | ||
} | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
func testGoogleStorageObjectAccessControlBasic(bucketName, objectName, role, entity 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_access_control" "default" { | ||
object = "${google_storage_bucket_object.object.name}" | ||
bucket = "${google_storage_bucket.bucket.name}" | ||
role = "%s" | ||
entity = "%s" | ||
} | ||
`, bucketName, objectName, tfObjectAcl.Name(), role, entity) | ||
} |
Oops, something went wrong.