diff --git a/.changelog/4515.txt b/.changelog/4515.txt new file mode 100644 index 00000000000..a992f4a4fed --- /dev/null +++ b/.changelog/4515.txt @@ -0,0 +1,3 @@ +```release-note:new-datasource +`google_compute_health_check` +``` diff --git a/google/data_source_compute_health_check.go b/google/data_source_compute_health_check.go new file mode 100644 index 00000000000..cc25ae6d606 --- /dev/null +++ b/google/data_source_compute_health_check.go @@ -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) +} diff --git a/google/data_source_compute_health_check_test.go b/google/data_source_compute_health_check_test.go new file mode 100644 index 00000000000..1b576d1e4b7 --- /dev/null +++ b/google/data_source_compute_health_check_test.go @@ -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) +} diff --git a/google/provider.go b/google/provider.go index 8003037bced..09b95d6ed67 100644 --- a/google/provider.go +++ b/google/provider.go @@ -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(), diff --git a/website/docs/d/compute_backend_bucket.html.markdown b/website/docs/d/compute_backend_bucket.html.markdown index 68b71399124..eeaa0e79903 100644 --- a/website/docs/d/compute_backend_bucket.html.markdown +++ b/website/docs/d/compute_backend_bucket.html.markdown @@ -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. diff --git a/website/docs/d/compute_health_check.html.markdown b/website/docs/d/compute_health_check.html.markdown new file mode 100644 index 00000000000..243ed1c4222 --- /dev/null +++ b/website/docs/d/compute_health_check.html.markdown @@ -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. diff --git a/website/google.erb b/website/google.erb index 269bd1c7709..f60b0b29f91 100644 --- a/website/google.erb +++ b/website/google.erb @@ -1560,6 +1560,10 @@ google_compute_global_forwarding_rule +