-
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.
Browse files
Browse the repository at this point in the history
* added the data_source_compute_router_nat with test and docs * changes in test file * minor fix Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
ef7a097
commit 3105cd0
Showing
5 changed files
with
154 additions
and
0 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_router_nat | ||
``` |
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) | ||
} |
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
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. |