Skip to content

Commit

Permalink
Added "endpointTypes" support to compute router nat resource (#10338) (
Browse files Browse the repository at this point in the history
…#7190)

[upstream:e93e811188d812d43d993ba8af9dcb351a630001]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Apr 4, 2024
1 parent 1ec163e commit fdaad4b
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/10338.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added 'endpoint_types' field to 'google_compute_router_nat' resource
```
31 changes: 31 additions & 0 deletions google-beta/services/compute/resource_compute_router_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,20 @@ Mutually exclusive with enableEndpointIndependentMapping.`,
Description: `Enable endpoint independent mapping.
For more information see the [official documentation](https://cloud.google.com/nat/docs/overview#specs-rfcs).`,
},
"endpoint_types": {
Type: schema.TypeList,
Computed: true,
Optional: true,
ForceNew: true,
Description: `Specifies the endpoint Types supported by the NAT Gateway.
Supported values include:
'ENDPOINT_TYPE_VM', 'ENDPOINT_TYPE_SWG',
'ENDPOINT_TYPE_MANAGED_PROXY_LB'.`,
MinItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"icmp_idle_timeout_sec": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -634,6 +648,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("log_config"); ok || !reflect.DeepEqual(v, logConfigProp) {
obj["logConfig"] = logConfigProp
}
endpointTypesProp, err := expandNestedComputeRouterNatEndpointTypes(d.Get("endpoint_types"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("endpoint_types"); !tpgresource.IsEmptyValue(reflect.ValueOf(endpointTypesProp)) && (ok || !reflect.DeepEqual(v, endpointTypesProp)) {
obj["endpointTypes"] = endpointTypesProp
}
rulesProp, err := expandNestedComputeRouterNatRules(d.Get("rules"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -843,6 +863,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("log_config", flattenNestedComputeRouterNatLogConfig(res["logConfig"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
if err := d.Set("endpoint_types", flattenNestedComputeRouterNatEndpointTypes(res["endpointTypes"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
if err := d.Set("rules", flattenNestedComputeRouterNatRules(res["rules"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
Expand Down Expand Up @@ -1331,6 +1354,10 @@ func flattenNestedComputeRouterNatLogConfigFilter(v interface{}, d *schema.Resou
return v
}

func flattenNestedComputeRouterNatEndpointTypes(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenNestedComputeRouterNatRules(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -1599,6 +1626,10 @@ func expandNestedComputeRouterNatLogConfigFilter(v interface{}, d tpgresource.Te
return v, nil
}

func expandNestedComputeRouterNatEndpointTypes(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNestedComputeRouterNatRules(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
v = v.(*schema.Set).List()
l := v.([]interface{})
Expand Down
94 changes: 94 additions & 0 deletions google-beta/services/compute/resource_compute_router_nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,66 @@ func TestAccComputeRouterNat_withNatRules(t *testing.T) {
})
}

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

testId := acctest.RandString(t, 10)
routerName := fmt.Sprintf("tf-test-router-nat-%s", testId)
testResourceName := "google_compute_router_nat.foobar"

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRouterNatBasic(routerName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_VM"),
),
},
{
ResourceName: testResourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRouterNatUpdateEndpointType(routerName, "ENDPOINT_TYPE_SWG"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_SWG"),
),
},
{
ResourceName: testResourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRouterNatUpdateEndpointType(routerName, "ENDPOINT_TYPE_VM"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_VM"),
),
},
{
ResourceName: testResourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccComputeRouterNatUpdateEndpointType(routerName, "ENDPOINT_TYPE_MANAGED_PROXY_LB"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_MANAGED_PROXY_LB"),
),
},
{
ResourceName: testResourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

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

Expand Down Expand Up @@ -811,6 +871,40 @@ resource "google_compute_router_nat" "foobar" {
`, routerName, routerName, routerName, routerName, routerName)
}

func testAccComputeRouterNatUpdateEndpointType(routerName string, endpointType string) string {
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
name = "%[1]s-net"
}
resource "google_compute_subnetwork" "foobar" {
name = "%[1]s-subnet"
network = google_compute_network.foobar.self_link
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
}
resource "google_compute_router" "foobar" {
name = "%[1]s"
region = google_compute_subnetwork.foobar.region
network = google_compute_network.foobar.self_link
}
resource "google_compute_router_nat" "foobar" {
name = "%[1]s"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
nat_ip_allocate_option = "AUTO_ONLY"
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
endpoint_types = [ "%[2]s" ]
log_config {
enable = true
filter = "ERRORS_ONLY"
}
}
`, routerName, endpointType)
}

func testAccComputeRouterNatUpdateToNatIPsId(routerName string) string {
return fmt.Sprintf(`
resource "google_compute_router" "foobar" {
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/compute_router_nat.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ The following arguments are supported:
Configuration for logging on NAT
Structure is [documented below](#nested_log_config).

* `endpoint_types` -
(Optional)
Specifies the endpoint Types supported by the NAT Gateway.
Supported values include:
`ENDPOINT_TYPE_VM`, `ENDPOINT_TYPE_SWG`,
`ENDPOINT_TYPE_MANAGED_PROXY_LB`.

* `rules` -
(Optional)
A list of rules associated with this NAT.
Expand Down

0 comments on commit fdaad4b

Please sign in to comment.