forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Google HC Datasource (hashicorp#4515)
* 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
1 parent
c132a7f
commit 8f9109b
Showing
7 changed files
with
124 additions
and
19 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,3 @@ | ||
```release-note:new-datasource | ||
`google_compute_health_check` | ||
``` |
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,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) | ||
} |
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,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) | ||
} |
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
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
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,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. |
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