Skip to content

Commit

Permalink
Add a datasource for google_compute_backend_bucket (#3142) (#5720)
Browse files Browse the repository at this point in the history
* Add a datasource for google_compute_backend_bucket

* Rename serviceName to backendBucketName

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Feb 19, 2020
1 parent a5c6f97 commit 42a48dd
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .changelog/3142.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_compute_backend_bucket`
```
4 changes: 2 additions & 2 deletions google/data_source_google_compute_backend_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ func dataSourceGoogleComputeBackendBucket() *schema.Resource {
func dataSourceComputeBackendBucketRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

serviceName := d.Get("name").(string)
backendBucketName := 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))
d.SetId(fmt.Sprintf("projects/%s/global/backendBuckets/%s", project, backendBucketName))

return resourceComputeBackendBucketRead(d, meta)
}
10 changes: 4 additions & 6 deletions google/data_source_google_compute_backend_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestAccDataSourceComputeBackendBucket_basic(t *testing.T) {
t.Parallel()

serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
backendBucketName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
bucketName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))

resource.Test(t, resource.TestCase{
Expand All @@ -20,29 +20,27 @@ func TestAccDataSourceComputeBackendBucket_basic(t *testing.T) {
CheckDestroy: testAccCheckComputeBackendBucketDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataSourceComputeBackendBucket_basic(serviceName, bucketName),
Config: testAccDataSourceComputeBackendBucket_basic(backendBucketName, bucketName),
Check: checkDataSourceStateMatchesResourceState("data.google_compute_backend_bucket.baz", "google_compute_backend_bucket.foobar"),
},
},
})
}

func testAccDataSourceComputeBackendBucket_basic(serviceName, bucketName string) string {
func testAccDataSourceComputeBackendBucket_basic(backendBucketName, 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)
`, backendBucketName, bucketName)
}
2 changes: 1 addition & 1 deletion google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ func Provider() terraform.ResourceProvider {
"google_cloudfunctions_function": dataSourceGoogleCloudFunctionsFunction(),
"google_composer_image_versions": dataSourceGoogleComposerImageVersions(),
"google_compute_address": dataSourceGoogleComputeAddress(),
"google_compute_backend_bucket": dataSourceGoogleComputeBackendBucket(),
"google_compute_backend_service": dataSourceGoogleComputeBackendService(),
"google_compute_backend_bucket": dataSourceGoogleComputeBackendBucket(),
"google_compute_default_service_account": dataSourceGoogleComputeDefaultServiceAccount(),
"google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(),
"google_compute_global_address": dataSourceGoogleComputeGlobalAddress(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
subcategory: "Compute Engine"
layout: "google"
page_title: "Google: google_compute_backend_bucket"
sidebar_current: "docs-google-datasource-compute-backend-bucket"
description: |-
Get information about a BackendBucket.
---

# google\_compute\_backend\_bucket

Get information about a BackendBucket.

## Example Usage

```tf
data "google_compute_backend_bucket" "my-backend-bucket" {
name = "my-backend"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Name of the resource.

- - -

* `project` - (Optional) The ID of the project in which the resource belongs. If it
is not provided, the provider project is used.

## Attributes Reference

In addition to the arguments listed above, the following attributes are exported:

* `bucket_name` - Cloud Storage bucket name.

* `cdn_policy` - Cloud CDN configuration for this Backend Bucket. Structure is documented below.

* `description` - An optional textual description of the resource; provided by the client when the resource is created.

* `enable_cdn` - Whether Cloud CDN is enabled for this BackendBucket.

* `id` - an identifier for the resource with format `projects/{{project}}/global/backendBuckets/{{name}}`

* `creation_timestamp` - Creation timestamp in RFC3339 text format.

* `self_link` - The URI of the created resource.

The `cdn_policy` block supports:

* `signed_url_cache_max_age_sec` - Maximum number of seconds the response to a signed URL request will be considered fresh. After this time period, the response will be revalidated before being served. When serving responses to signed URL requests, Cloud CDN will internally behave as though all responses from this backend had a "Cache-Control: public, max-age=[TTL]" header, regardless of any existing Cache-Control header. The actual headers served in responses will not be altered.
3 changes: 3 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
<li<%= sidebar_current("docs-google-datasource-compute-backend-service") %>>
<a href="/docs/providers/google/d/datasource_google_compute_backend_service.html">google_compute_backend_service</a>
</li>
<li<%= sidebar_current("docs-google-datasource-compute-backend-bucket") %>>
<a href="/docs/providers/google/d/datasource_google_compute_backend_bucket.html">google_compute_backend_bucket</a>
</li>
<li<%= sidebar_current("docs-google-datasource-compute-default-service-account") %>>
<a href="/docs/providers/google/d/google_compute_default_service_account.html">google_compute_default_service_account</a>
</li>
Expand Down

0 comments on commit 42a48dd

Please sign in to comment.