Skip to content

Commit

Permalink
Add Google HC Datasource (hashicorp#4515)
Browse files Browse the repository at this point in the history
* mark field as updatable

Co-authored-by: upodroid <[email protected]>

* add google hc ds

Co-authored-by: upodroid <[email protected]>
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician and upodroid committed Mar 18, 2021
1 parent c132a7f commit 8f9109b
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .changelog/4515.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-datasource
`google_compute_health_check`
```
29 changes: 29 additions & 0 deletions google/data_source_compute_health_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package google

import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

func dataSourceGoogleComputeHealthCheck() *schema.Resource {
// Generate datasource schema from resource
dsSchema := datasourceSchemaFromResourceSchema(resourceComputeHealthCheck().Schema)

// Set 'Required' schema elements
addRequiredFieldsToSchema(dsSchema, "name")

// Set 'Optional' schema elements
addOptionalFieldsToSchema(dsSchema, "project")

return &schema.Resource{
Read: dataSourceGoogleComputeHealthCheckRead,
Schema: dsSchema,
}
}

func dataSourceGoogleComputeHealthCheckRead(d *schema.ResourceData, meta interface{}) error {
id, err := replaceVars(d, meta.(*Config), "projects/{{project}}/global/healthChecks/{{name}}")
if err != nil {
return err
}
d.SetId(id)

return resourceComputeHealthCheckRead(d, meta)
}
51 changes: 51 additions & 0 deletions google/data_source_compute_health_check_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package google

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccComputeHealthCheckDatasource_basic(t *testing.T) {
t.Parallel()

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccComputeHealthCheckDatasourceConfig(randString(t, 10)),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_compute_health_check.hc", "google_compute_health_check.hc"),
),
},
},
})
}

func testAccComputeHealthCheckDatasourceConfig(suffix string) string {
return fmt.Sprintf(`
resource "google_compute_health_check" "hc" {
name = "tf-test-%s"
description = "Health check via tcp"
timeout_sec = 1
check_interval_sec = 1
healthy_threshold = 4
unhealthy_threshold = 5
tcp_health_check {
port_name = "health-check-port"
port_specification = "USE_NAMED_PORT"
request = "ARE YOU HEALTHY?"
proxy_header = "NONE"
response = "I AM HEALTHY"
}
}
data "google_compute_health_check" "hc" {
name = google_compute_health_check.hc.name
}
`, suffix)
}
1 change: 1 addition & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ func Provider() *schema.Provider {
"google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(),
"google_compute_global_address": dataSourceGoogleComputeGlobalAddress(),
"google_compute_global_forwarding_rule": dataSourceGoogleComputeGlobalForwardingRule(),
"google_compute_health_check": dataSourceGoogleComputeHealthCheck(),
"google_compute_image": dataSourceGoogleComputeImage(),
"google_compute_instance": dataSourceGoogleComputeInstance(),
"google_compute_instance_group": dataSourceGoogleComputeInstanceGroup(),
Expand Down
20 changes: 1 addition & 19 deletions website/docs/d/compute_backend_bucket.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,4 @@ The following arguments are supported:

## 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.
See [google_compute_backend_bucket](https://www.terraform.io/docs/providers/google/r/compute_backend_bucket.html) resource for details of the available attributes.
35 changes: 35 additions & 0 deletions website/docs/d/compute_health_check.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
subcategory: "Compute Engine"
layout: "google"
page_title: "Google: google_compute_health_check"
sidebar_current: "docs-google-datasource-compute-health-check"
description: |-
Get information about a HealthCheck.
---

# google\_compute\_health\_check

Get information about a HealthCheck.

## Example Usage

```tf
data "google_compute_health_check" "health_chceck" {
name = "my-hc"
}
```

## 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

See [google_compute_health_check](https://www.terraform.io/docs/providers/google/r/compute_health_check.html) resource for details of the available attributes.
4 changes: 4 additions & 0 deletions website/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1560,6 +1560,10 @@
<a href="/docs/providers/google/d/compute_global_forwarding_rule.html">google_compute_global_forwarding_rule</a>
</li>

<li>
<a href="/docs/providers/google/d/compute_health_check.html">google_compute_health_check</a>
</li>

<li>
<a href="/docs/providers/google/d/compute_image.html">google_compute_image</a>
</li>
Expand Down

0 comments on commit 8f9109b

Please sign in to comment.