diff --git a/mmv1/third_party/terraform/data_sources/data_source_google_storage_bucket.go b/mmv1/third_party/terraform/data_sources/data_source_google_storage_bucket.go new file mode 100644 index 000000000000..2f44369e682a --- /dev/null +++ b/mmv1/third_party/terraform/data_sources/data_source_google_storage_bucket.go @@ -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) +} diff --git a/mmv1/third_party/terraform/tests/data_source_google_storage_bucket_test.go b/mmv1/third_party/terraform/tests/data_source_google_storage_bucket_test.go new file mode 100644 index 000000000000..704afdf4f9ed --- /dev/null +++ b/mmv1/third_party/terraform/tests/data_source_google_storage_bucket_test.go @@ -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) +} diff --git a/mmv1/third_party/terraform/utils/provider.go.erb b/mmv1/third_party/terraform/utils/provider.go.erb index ba06f61565dc..d83b30c3d88e 100644 --- a/mmv1/third_party/terraform/utils/provider.go.erb +++ b/mmv1/third_party/terraform/utils/provider.go.erb @@ -290,6 +290,7 @@ func Provider() *schema.Provider { "google_sql_ca_certs": dataSourceGoogleSQLCaCerts(), "google_sql_backup_run": dataSourceSqlBackupRun(), "google_sql_database_instance": dataSourceSqlDatabaseInstance(), + "google_storage_bucket": dataSourceGoogleStorageBucket(), "google_storage_bucket_object": dataSourceGoogleStorageBucketObject(), "google_storage_bucket_object_content": dataSourceGoogleStorageBucketObjectContent(), "google_storage_object_signed_url": dataSourceGoogleSignedUrl(), diff --git a/mmv1/third_party/terraform/website/docs/d/storage_bucket.html.markdown b/mmv1/third_party/terraform/website/docs/d/storage_bucket.html.markdown new file mode 100644 index 000000000000..c00d0be1b499 --- /dev/null +++ b/mmv1/third_party/terraform/website/docs/d/storage_bucket.html.markdown @@ -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.