Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the data_source_compute_router_nat #7058

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package google

import (
"fmt"

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

func dataSourceGoogleComputeRouterNat() *schema.Resource {

dsSchema := datasourceSchemaFromResourceSchema(resourceComputeRouterNat().Schema)

addRequiredFieldsToSchema(dsSchema, "name", "router")
addOptionalFieldsToSchema(dsSchema, "project", "region")

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

}

func dataSourceGoogleComputeRouterNatRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

id, err := replaceVars(d, config, "{{project}}/{{region}}/{{router}}/{{name}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)

return resourceComputeRouterNatRead(d, meta)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package google

import (
"testing"

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

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

context := map[string]interface{}{
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDataSourceGoogleComputeRouterNat_basic(context),
Check: resource.ComposeTestCheckFunc(
checkDataSourceStateMatchesResourceState("data.google_compute_router_nat.foo", "google_compute_router_nat.nat"),
),
},
},
})
}

func testAccDataSourceGoogleComputeRouterNat_basic(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_network" "net" {
name = "my-network%{random_suffix}"
}

resource "google_compute_subnetwork" "subnet" {
name = "my-subnetwork%{random_suffix}"
network = google_compute_network.net.id
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
}

resource "google_compute_router" "router" {
name = "my-router%{random_suffix}"
region = google_compute_subnetwork.subnet.region
network = google_compute_network.net.id

bgp {
asn = 64514
}
}

resource "google_compute_router_nat" "nat" {
name = "my-router-nat%{random_suffix}"
router = google_compute_router.router.name
region = google_compute_router.router.region
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"

log_config {
enable = true
filter = "ERRORS_ONLY"
}
}

data "google_compute_router_nat" "foo" {
name = google_compute_router_nat.nat.name
router = google_compute_router_nat.nat.router
region = google_compute_router.router.region
}`, context)

}
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 @@ -242,6 +242,7 @@ func Provider() *schema.Provider {
"google_compute_region_ssl_certificate": dataSourceGoogleRegionComputeSslCertificate(),
"google_compute_resource_policy": dataSourceGoogleComputeResourcePolicy(),
"google_compute_router": dataSourceGoogleComputeRouter(),
"google_compute_router_nat": dataSourceGoogleComputeRouterNat(),
"google_compute_router_status": dataSourceGoogleComputeRouterStatus(),
"google_compute_snapshot": dataSourceGoogleComputeSnapshot(),
"google_compute_ssl_certificate": dataSourceGoogleComputeSslCertificate(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
subcategory: "Compute Engine"
page_title: "Google: google_compute_router_nat"
description: |-
Get information about a Google Compute Router NAT.
---

# google\_compute\_router\_nat

To get more information about Snapshot, see:

* [API documentation](https://cloud.google.com/compute/docs/reference/rest/v1/routers)
* How-to Guides
* [Official Documentation](https://cloud.google.com/router/docs/)

## Example Usage

```hcl
data "google_compute_router_nat" "foo" {
name = "my-nat"
router = "my-router"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) Name of the NAT service. The name must be 1-63 characters long and
comply with RFC1035.

* `router` - (Required)
The name of the Cloud Router in which this NAT will be configured.

- - -

* `project` - (Optional) The ID of the project in which the resource belongs.
If it is not provided, the provider project is used.

* `region` - (Optional) Region where the router and NAT reside.

## Attributes Reference

See [google_compute_router_nat](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_router_nat) resource for details of the available attributes.