Skip to content

Commit

Permalink
Add Google HC Datasource (#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]>
  • Loading branch information
upodroid authored Mar 18, 2021
1 parent 8d4c0ed commit e9e78ae
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 19 deletions.
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)
}
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 mmv1/third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,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
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.
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.

0 comments on commit e9e78ae

Please sign in to comment.