diff --git a/mmv1/third_party/terraform/data_sources/data_source_google_compute_ha_vpn_gateway.go b/mmv1/third_party/terraform/data_sources/data_source_google_compute_ha_vpn_gateway.go new file mode 100644 index 000000000000..7d69fed83e9b --- /dev/null +++ b/mmv1/third_party/terraform/data_sources/data_source_google_compute_ha_vpn_gateway.go @@ -0,0 +1,43 @@ +package google + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func dataSourceGoogleComputeHaVpnGateway() *schema.Resource { + dsSchema := datasourceSchemaFromResourceSchema(resourceComputeHaVpnGateway().Schema) + + // Set 'Required' schema elements + addRequiredFieldsToSchema(dsSchema, "name") + + // Set 'Optional' schema elements + addOptionalFieldsToSchema(dsSchema, "project") + addOptionalFieldsToSchema(dsSchema, "region") + + return &schema.Resource{ + Read: dataSourceGoogleComputeHaVpnGatewayRead, + Schema: dsSchema, + } +} + +func dataSourceGoogleComputeHaVpnGatewayRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*Config) + + name := d.Get("name").(string) + + project, err := getProject(d, config) + if err != nil { + return err + } + + region, err := getRegion(d, config) + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("projects/%s/regions/%s/vpnGateways/%s", project, region, name)) + + return resourceComputeHaVpnGatewayRead(d, meta) +} diff --git a/mmv1/third_party/terraform/tests/data_source_google_compute_ha_vpn_gateway_test.go b/mmv1/third_party/terraform/tests/data_source_google_compute_ha_vpn_gateway_test.go new file mode 100644 index 000000000000..39090e8874cc --- /dev/null +++ b/mmv1/third_party/terraform/tests/data_source_google_compute_ha_vpn_gateway_test.go @@ -0,0 +1,43 @@ +package google + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDataSourceComputeHaVpnGateway(t *testing.T) { + t.Parallel() + + gwName := fmt.Sprintf("tf-%s", randString(t, 10)) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceComputeHaVpnGatewayConfig(gwName), + Check: checkDataSourceStateMatchesResourceState("data.google_compute_ha_vpn_gateway.ha_gateway", "google_compute_ha_vpn_gateway.ha_gateway"), + }, + }, + }) +} + +func testAccDataSourceComputeHaVpnGatewayConfig(gwName string) string { + return fmt.Sprintf(` +resource "google_compute_ha_vpn_gateway" "ha_gateway" { + name = "%s" + network = google_compute_network.network1.id +} + +resource "google_compute_network" "network1" { + name = "%s" + auto_create_subnetworks = false +} + +data "google_compute_ha_vpn_gateway" "ha_gateway" { + name = google_compute_ha_vpn_gateway.ha_gateway.name +} +`, gwName, gwName) +} diff --git a/mmv1/third_party/terraform/utils/provider.go.erb b/mmv1/third_party/terraform/utils/provider.go.erb index d2323a52a1e3..3307371ec39a 100644 --- a/mmv1/third_party/terraform/utils/provider.go.erb +++ b/mmv1/third_party/terraform/utils/provider.go.erb @@ -185,6 +185,7 @@ func Provider() *schema.Provider { "google_compute_forwarding_rule": dataSourceGoogleComputeForwardingRule(), "google_compute_global_address": dataSourceGoogleComputeGlobalAddress(), "google_compute_global_forwarding_rule": dataSourceGoogleComputeGlobalForwardingRule(), + "google_compute_ha_vpn_gateway": dataSourceGoogleComputeHaVpnGateway(), "google_compute_health_check": dataSourceGoogleComputeHealthCheck(), "google_compute_image": dataSourceGoogleComputeImage(), "google_compute_instance": dataSourceGoogleComputeInstance(), diff --git a/mmv1/third_party/terraform/website/docs/d/compute_ha_vpn_gateway.html.markdown b/mmv1/third_party/terraform/website/docs/d/compute_ha_vpn_gateway.html.markdown new file mode 100644 index 000000000000..d9c628170910 --- /dev/null +++ b/mmv1/third_party/terraform/website/docs/d/compute_ha_vpn_gateway.html.markdown @@ -0,0 +1,38 @@ +--- +subcategory: "Compute Engine" +layout: "google" +page_title: "Google: google_compute_ha_vpn_gateway" +sidebar_current: "docs-google-datasource-compute-ha-vpn-gateway" +description: |- + Get a HA VPN Gateway within GCE. +--- + +# google\_compute\_forwarding\_rule + +Get a HA VPN Gateway within GCE from its name. + +## Example Usage + +```tf +data "google_compute_ha_vpn_gateway" "gateway" { + name = "foobar" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the forwarding rule. + + +- - - + +* `project` - (Optional) The project in which the resource belongs. If it + is not provided, the provider project is used. + +* `region` - (Optional) The region in which the resource belongs. If it + is not provided, the project region is used. + +## Attributes Reference +See [google_compute_ha_vpn_gateway](https://www.terraform.io/docs/providers/google/r/compute_ha_vpn_gateway.html) resource for details of the available attributes.