Skip to content

Commit

Permalink
enhance subnetwork resource with PRIVATE_NAT purpose in docs and test (
Browse files Browse the repository at this point in the history
…#8952) (#6366)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 25, 2023
1 parent 0e57e2c commit aaf0238
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changelog/8952.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
```release-note:none
```
3 changes: 2 additions & 1 deletion google-beta/services/compute/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,11 @@ access Google APIs and services by using Private Google Access.`,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The purpose of the resource. This field can be either 'PRIVATE_RFC_1918', 'REGIONAL_MANAGED_PROXY', 'GLOBAL_MANAGED_PROXY', or 'PRIVATE_SERVICE_CONNECT'.
Description: `The purpose of the resource. This field can be either 'PRIVATE_RFC_1918', 'REGIONAL_MANAGED_PROXY', 'GLOBAL_MANAGED_PROXY', 'PRIVATE_SERVICE_CONNECT' or 'PRIVATE_NAT'([Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)).
A subnet with purpose set to 'REGIONAL_MANAGED_PROXY' is a user-created subnetwork that is reserved for regional Envoy-based load balancers.
A subnetwork in a given region with purpose set to 'GLOBAL_MANAGED_PROXY' is a proxy-only subnet and is shared between all the cross-regional Envoy-based load balancers.
A subnetwork with purpose set to 'PRIVATE_SERVICE_CONNECT' reserves the subnet for hosting a Private Service Connect published service.
A subnetwork with purpose set to 'PRIVATE_NAT' is used as source range for Private NAT gateways.
Note that 'REGIONAL_MANAGED_PROXY' is the preferred setting for all regional Envoy load balancers.
If unspecified, the purpose defaults to 'PRIVATE_RFC_1918'.`,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,52 @@ resource "google_compute_network" "custom-test" {
`, context)
}

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

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

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeSubnetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeSubnetwork_subnetworkPurposePrivateNatExample(context),
},
{
ResourceName: "google_compute_subnetwork.subnetwork-purpose-private-nat",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"network", "region"},
},
},
})
}

func testAccComputeSubnetwork_subnetworkPurposePrivateNatExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_compute_subnetwork" "subnetwork-purpose-private-nat" {
provider = google-beta
name = "tf-test-subnet-purpose-test-subnetwork%{random_suffix}"
region = "us-west2"
ip_cidr_range = "192.168.1.0/24"
purpose = "PRIVATE_NAT"
network = google_compute_network.custom-test.id
}
resource "google_compute_network" "custom-test" {
provider = google-beta
name = "tf-test-subnet-purpose-test-network%{random_suffix}"
auto_create_subnetworks = false
}
`, context)
}

func testAccCheckComputeSubnetworkDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
29 changes: 28 additions & 1 deletion website/docs/r/compute_subnetwork.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ resource "google_compute_network" "custom-test" {
enable_ula_internal_ipv6 = true
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=subnetwork_purpose_private_nat&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Subnetwork Purpose Private Nat


```hcl
resource "google_compute_subnetwork" "subnetwork-purpose-private-nat" {
provider = google-beta
name = "subnet-purpose-test-subnetwork"
region = "us-west2"
ip_cidr_range = "192.168.1.0/24"
purpose = "PRIVATE_NAT"
network = google_compute_network.custom-test.id
}
resource "google_compute_network" "custom-test" {
provider = google-beta
name = "subnet-purpose-test-network"
auto_create_subnetworks = false
}
```

## Argument Reference

Expand Down Expand Up @@ -223,10 +249,11 @@ The following arguments are supported:

* `purpose` -
(Optional)
The purpose of the resource. This field can be either `PRIVATE_RFC_1918`, `REGIONAL_MANAGED_PROXY`, `GLOBAL_MANAGED_PROXY`, or `PRIVATE_SERVICE_CONNECT`.
The purpose of the resource. This field can be either `PRIVATE_RFC_1918`, `REGIONAL_MANAGED_PROXY`, `GLOBAL_MANAGED_PROXY`, `PRIVATE_SERVICE_CONNECT` or `PRIVATE_NAT`([Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)).
A subnet with purpose set to `REGIONAL_MANAGED_PROXY` is a user-created subnetwork that is reserved for regional Envoy-based load balancers.
A subnetwork in a given region with purpose set to `GLOBAL_MANAGED_PROXY` is a proxy-only subnet and is shared between all the cross-regional Envoy-based load balancers.
A subnetwork with purpose set to `PRIVATE_SERVICE_CONNECT` reserves the subnet for hosting a Private Service Connect published service.
A subnetwork with purpose set to `PRIVATE_NAT` is used as source range for Private NAT gateways.
Note that `REGIONAL_MANAGED_PROXY` is the preferred setting for all regional Envoy load balancers.
If unspecified, the purpose defaults to `PRIVATE_RFC_1918`.

Expand Down

0 comments on commit aaf0238

Please sign in to comment.