-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added storage bucket datasource (#5251)
* addeed storage bucket datasource * fix typo
- Loading branch information
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
mmv1/third_party/terraform/data_sources/data_source_google_storage_bucket.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,25 @@ | ||
package google | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleStorageBucket() *schema.Resource { | ||
|
||
dsSchema := datasourceSchemaFromResourceSchema(resourceStorageBucket().Schema) | ||
|
||
addRequiredFieldsToSchema(dsSchema, "name") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceGoogleStorageBucketRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceGoogleStorageBucketRead(d *schema.ResourceData, meta interface{}) error { | ||
|
||
bucket := d.Get("name").(string) | ||
d.SetId(bucket) | ||
|
||
return resourceStorageBucketRead(d, meta) | ||
} |
43 changes: 43 additions & 0 deletions
43
mmv1/third_party/terraform/tests/data_source_google_storage_bucket_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,43 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceGoogleStorageBucket_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
bucket := "tf-bucket-" + randString(t, 10) | ||
|
||
vcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccStorageBucketDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceGoogleStorageBucketConfig(bucket), | ||
Check: resource.ComposeTestCheckFunc( | ||
checkDataSourceStateMatchesResourceStateWithIgnores("data.google_storage_bucket.bar", "google_storage_bucket.foo", map[string]struct{}{"force_destroy": {}}), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceGoogleStorageBucketConfig(bucketName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_storage_bucket" "foo" { | ||
name = "%s" | ||
} | ||
data "google_storage_bucket" "bar" { | ||
name = google_storage_bucket.foo.name | ||
depends_on = [ | ||
google_storage_bucket.foo, | ||
] | ||
} | ||
`, bucketName) | ||
} |
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
34 changes: 34 additions & 0 deletions
34
mmv1/third_party/terraform/website/docs/d/storage_bucket.html.markdown
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,34 @@ | ||
--- | ||
subcategory: "Cloud Storage" | ||
layout: "google" | ||
page_title: "Google: google_storage_bucket" | ||
sidebar_current: "docs-google-datasource-storage-bucket" | ||
description: |- | ||
Get information about a Google Cloud Storage bucket. | ||
--- | ||
|
||
# google\_storage\_bucket | ||
|
||
Gets an existing bucket in Google Cloud Storage service (GCS). | ||
See [the official documentation](https://cloud.google.com/storage/docs/key-terms#buckets) | ||
and | ||
[API](https://cloud.google.com/storage/docs/json_api/v1/buckets). | ||
|
||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "google_storage_bucket" "my-bucket" { | ||
name = "my-bucket" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the bucket. | ||
|
||
## Attributes Reference | ||
|
||
See [google_storage_bucket](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/storage_bucket#argument-reference) resource for details of the available attributes. |