-
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.
features: add data_source_google_compute_backend_bucket (#5700)
Link #5690
- Loading branch information
Showing
3 changed files
with
86 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,37 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func dataSourceGoogleComputeBackendBucket() *schema.Resource { | ||
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeBackendBucket().Schema) | ||
|
||
// Set 'Required' schema elements | ||
addRequiredFieldsToSchema(dsSchema, "name") | ||
|
||
// Set 'Optional' schema elements | ||
addOptionalFieldsToSchema(dsSchema, "project") | ||
|
||
return &schema.Resource{ | ||
Read: dataSourceComputeBackendBucketRead, | ||
Schema: dsSchema, | ||
} | ||
} | ||
|
||
func dataSourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
serviceName := d.Get("name").(string) | ||
|
||
project, err := getProject(d, config) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(fmt.Sprintf("projects/%s/global/backendBuckets/%s", project, serviceName)) | ||
|
||
return resourceComputeBackendBucketRead(d, meta) | ||
} |
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,48 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceComputeBackendBucket_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
bucketName := fmt.Sprintf("tf-test-%s", acctest.RandString(10)) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckComputeBackendBucketDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceComputeBackendBucket_basic(serviceName, bucketName), | ||
Check: checkDataSourceStateMatchesResourceState("data.google_compute_backend_bucket.baz", "google_compute_backend_bucket.foobar"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceComputeBackendBucket_basic(serviceName, bucketName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_compute_backend_bucket" "foobar" { | ||
name = "%s" | ||
description = "Contains beautiful images" | ||
bucket_name = google_storage_bucket.image_bucket.name | ||
enable_cdn = true | ||
} | ||
resource "google_storage_bucket" "image_bucket" { | ||
name = "%s" | ||
location = "EU" | ||
} | ||
data "google_compute_backend_bucket" "baz" { | ||
name = google_compute_backend_bucket.foobar.name | ||
} | ||
`, serviceName, 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