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

Add support for google_storage_object_access_control #2256

Merged
merged 1 commit into from
Oct 17, 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
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func Provider() terraform.ResourceProvider {
GeneratedFilestoreResourcesMap,
GeneratedRedisResourcesMap,
GeneratedResourceManagerResourcesMap,
GeneratedStorageResourcesMap,
GeneratedMonitoringResourcesMap,
map[string]*schema.Resource{
"google_app_engine_application": resourceAppEngineApplication(),
Expand Down
21 changes: 21 additions & 0 deletions google/provider_storage_gen.go
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 google/resource_google_storage_object_access_control_test.go
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{
{
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{
{
Config: testGoogleStorageObjectAccessControlBasic(bucketName, objectName, "READER", "allUsers"),
},
{
ResourceName: "google_storage_object_access_control.default",
ImportState: true,
ImportStateVerify: true,
},
{
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)
}
Loading