-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the data_source_compute_router_nat (#7058)
* added the data_source_compute_router_nat with test and docs * changes in test file * minor fix
- Loading branch information
1 parent
4bddee4
commit 1964a71
Showing
4 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
mmv1/third_party/terraform/data_sources/data_source_google_compute_router_nat.go
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,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) | ||
} |
73 changes: 73 additions & 0 deletions
73
mmv1/third_party/terraform/tests/data_source_google_compute_router_nat_test.go
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,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) | ||
|
||
} |
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
44 changes: 44 additions & 0 deletions
44
mmv1/third_party/terraform/website/docs/d/compute_router_nat.html.markdown
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,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. |