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

Make google resource storage bucket importable #14047 #14455

Merged
merged 1 commit into from
May 15, 2017
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
18 changes: 12 additions & 6 deletions builtin/providers/google/resource_storage_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func resourceStorageBucket() *schema.Resource {
Read: resourceStorageBucketRead,
Update: resourceStorageBucketUpdate,
Delete: resourceStorageBucketDelete,
Importer: &schema.ResourceImporter{
State: resourceStorageBucketStateImporter,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -154,12 +157,8 @@ func resourceStorageBucketCreate(d *schema.ResourceData, meta interface{}) error

log.Printf("[DEBUG] Created bucket %v at location %v\n\n", res.Name, res.SelfLink)

// Assign the bucket ID as the resource ID
d.Set("self_link", res.SelfLink)
d.Set("url", fmt.Sprintf("gs://%s", bucket))
d.SetId(res.Id)

return nil
return resourceStorageBucketRead(d, meta)
}

func resourceStorageBucketUpdate(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -228,8 +227,10 @@ func resourceStorageBucketRead(d *schema.ResourceData, meta interface{}) error {

// Update the bucket ID according to the resource ID
d.Set("self_link", res.SelfLink)
d.Set("url", fmt.Sprintf("gs://%s", bucket))
d.Set("storage_class", res.StorageClass)
d.Set("location", res.Location)
d.SetId(res.Id)

return nil
}

Expand Down Expand Up @@ -289,3 +290,8 @@ func resourceStorageBucketDelete(d *schema.ResourceData, meta interface{}) error

return nil
}

func resourceStorageBucketStateImporter(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
d.Set("name", d.Id())
return []*schema.ResourceData{d}, nil
}
25 changes: 23 additions & 2 deletions builtin/providers/google/resource_storage_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ func TestAccStorageStorageClass(t *testing.T) {
),
},
{
Config: testGoogleStorageBucketsReaderStorageClass(bucketName, "REGIONAL", "us-central1"),
Config: testGoogleStorageBucketsReaderStorageClass(bucketName, "REGIONAL", "US-CENTRAL1"),
Check: resource.ComposeTestCheckFunc(
testAccCheckCloudStorageBucketExists(
"google_storage_bucket.bucket", bucketName),
resource.TestCheckResourceAttr(
"google_storage_bucket.bucket", "storage_class", "REGIONAL"),
resource.TestCheckResourceAttr(
"google_storage_bucket.bucket", "location", "us-central1"),
"google_storage_bucket.bucket", "location", "US-CENTRAL1"),
),
},
},
Expand Down Expand Up @@ -136,6 +136,27 @@ func TestAccStorageBucketUpdate(t *testing.T) {
})
}

func TestAccStorageBucketImport(t *testing.T) {
bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccGoogleStorageDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testGoogleStorageBucketsReaderDefaults(bucketName),
},
resource.TestStep{
ResourceName: "google_storage_bucket.bucket",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"force_destroy"},
},
},
})
}

func TestAccStorageForceDestroy(t *testing.T) {
bucketName := fmt.Sprintf("tf-test-acl-bucket-%d", acctest.RandInt())

Expand Down