diff --git a/.changelog/4324.txt b/.changelog/4324.txt new file mode 100644 index 00000000000..1e45ecd4ffe --- /dev/null +++ b/.changelog/4324.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: added support for `enable_independent_endpoint_mapping` to `google_compute_router_nat` resource +``` diff --git a/google/resource_compute_router_nat.go b/google/resource_compute_router_nat.go index b89bd94728b..56c985dabe7 100644 --- a/google/resource_compute_router_nat.go +++ b/google/resource_compute_router_nat.go @@ -173,6 +173,13 @@ valid static external IPs that have been assigned to the NAT.`, }, // Default schema.HashSchema is used. }, + "enable_endpoint_independent_mapping": { + Type: schema.TypeBool, + Optional: true, + Description: `Specifies if endpoint independent mapping is enabled. This is enabled by default. For more information +see the [official documentation](https://cloud.google.com/nat/docs/overview#specs-rfcs).`, + Default: true, + }, "icmp_idle_timeout_sec": { Type: schema.TypeInt, Optional: true, @@ -380,6 +387,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er } else if v, ok := d.GetOkExists("log_config"); !isEmptyValue(reflect.ValueOf(logConfigProp)) && (ok || !reflect.DeepEqual(v, logConfigProp)) { obj["logConfig"] = logConfigProp } + enableEndpointIndependentMappingProp, err := expandNestedComputeRouterNatEnableEndpointIndependentMapping(d.Get("enable_endpoint_independent_mapping"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enable_endpoint_independent_mapping"); ok || !reflect.DeepEqual(v, enableEndpointIndependentMappingProp) { + obj["enableEndpointIndependentMapping"] = enableEndpointIndependentMappingProp + } lockName, err := replaceVars(d, config, "router/{{region}}/{{router}}") if err != nil { @@ -521,6 +534,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("enable_endpoint_independent_mapping", flattenNestedComputeRouterNatEnableEndpointIndependentMapping(res["enableEndpointIndependentMapping"], d, config)); err != nil { + return fmt.Errorf("Error reading RouterNat: %s", err) + } return nil } @@ -607,6 +623,12 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er } else if v, ok := d.GetOkExists("log_config"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, logConfigProp)) { obj["logConfig"] = logConfigProp } + enableEndpointIndependentMappingProp, err := expandNestedComputeRouterNatEnableEndpointIndependentMapping(d.Get("enable_endpoint_independent_mapping"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enable_endpoint_independent_mapping"); ok || !reflect.DeepEqual(v, enableEndpointIndependentMappingProp) { + obj["enableEndpointIndependentMapping"] = enableEndpointIndependentMappingProp + } lockName, err := replaceVars(d, config, "router/{{region}}/{{router}}") if err != nil { @@ -892,6 +914,10 @@ func flattenNestedComputeRouterNatLogConfigFilter(v interface{}, d *schema.Resou return v } +func flattenNestedComputeRouterNatEnableEndpointIndependentMapping(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return v +} + func expandNestedComputeRouterNatName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { return v, nil } @@ -1047,6 +1073,10 @@ func expandNestedComputeRouterNatLogConfigFilter(v interface{}, d TerraformResou return v, nil } +func expandNestedComputeRouterNatEnableEndpointIndependentMapping(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + func flattenNestedComputeRouterNat(d *schema.ResourceData, meta interface{}, res map[string]interface{}) (map[string]interface{}, error) { var v interface{} var ok bool diff --git a/google/resource_compute_router_nat_test.go b/google/resource_compute_router_nat_test.go index 515193378e1..c6c88d73b70 100644 --- a/google/resource_compute_router_nat_test.go +++ b/google/resource_compute_router_nat_test.go @@ -120,6 +120,45 @@ func TestAccComputeRouterNat_withManualIpAndSubnetConfiguration(t *testing.T) { }) } +func TestAccComputeRouterNat_withDisabledIndependentEndpointMapping(t *testing.T) { + t.Parallel() + + testId := randString(t, 10) + routerName := fmt.Sprintf("tf-test-router-nat-%s", testId) + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRouterNatWithDisabledIndependentEndpointMapping(routerName, true), + }, + { + ResourceName: "google_compute_router_nat.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeRouterNatWithDisabledIndependentEndpointMapping(routerName, false), + }, + { + ResourceName: "google_compute_router_nat.foobar", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccComputeRouterNatWithDisabledIndependentEndpointMapping(routerName, true), + }, + { + ResourceName: "google_compute_router_nat.foobar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckComputeRouterNatDestroyProducer(t *testing.T) func(s *terraform.State) error { return func(s *terraform.State) error { config := googleProviderConfig(t) @@ -364,6 +403,50 @@ resource "google_compute_router_nat" "foobar" { `, routerName, routerName, routerName, routerName, routerName) } +func testAccComputeRouterNatWithDisabledIndependentEndpointMapping(routerName string, enabled bool) string { + return fmt.Sprintf(` +resource "google_compute_network" "foobar" { + name = "%s-net" + auto_create_subnetworks = "false" +} + +resource "google_compute_subnetwork" "foobar" { + name = "%s-subnet" + network = google_compute_network.foobar.self_link + ip_cidr_range = "10.0.0.0/16" + region = "us-central1" +} + +resource "google_compute_address" "foobar" { + name = "router-nat-%s-addr" + region = google_compute_subnetwork.foobar.region +} + +resource "google_compute_router" "foobar" { + name = "%s" + region = google_compute_subnetwork.foobar.region + network = google_compute_network.foobar.self_link + bgp { + asn = 64514 + } +} + +resource "google_compute_router_nat" "foobar" { + name = "%s" + router = google_compute_router.foobar.name + region = google_compute_router.foobar.region + nat_ip_allocate_option = "MANUAL_ONLY" + nat_ips = [google_compute_address.foobar.self_link] + source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS" + subnetwork { + name = google_compute_subnetwork.foobar.name + source_ip_ranges_to_nat = ["ALL_IP_RANGES"] + } + enable_endpoint_independent_mapping = %t +} +`, routerName, routerName, routerName, routerName, routerName, enabled) +} + func testAccComputeRouterNatKeepRouter(routerName string) string { return fmt.Sprintf(` resource "google_compute_network" "foobar" { diff --git a/website/docs/r/compute_router_nat.html.markdown b/website/docs/r/compute_router_nat.html.markdown index fe742e41006..6884abf5df7 100644 --- a/website/docs/r/compute_router_nat.html.markdown +++ b/website/docs/r/compute_router_nat.html.markdown @@ -194,6 +194,11 @@ The following arguments are supported: Configuration for logging on NAT Structure is documented below. +* `enable_endpoint_independent_mapping` - + (Optional) + Specifies if endpoint independent mapping is enabled. This is enabled by default. For more information + see the [official documentation](https://cloud.google.com/nat/docs/overview#specs-rfcs). + * `region` - (Optional) Region where the router and NAT reside.