Skip to content

Commit

Permalink
Add support for enableIndependentEndpointMapping to router nat (#4324)
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick authored Dec 17, 2020
1 parent b801e05 commit 4601ff7
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
7 changes: 7 additions & 0 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12979,6 +12979,13 @@ objects:
- :ERRORS_ONLY
- :TRANSLATIONS_ONLY
- :ALL
- !ruby/object:Api::Type::Boolean
name: enableEndpointIndependentMapping
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_value: true
send_empty_value: true
- !ruby/object:Api::Resource
name: 'RouterBgpPeer'
base_url: projects/{{project}}/regions/{{region}}/routers/{{router}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,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,
},
},
})
}

<% unless version == 'ga' -%>
func TestAccComputeRouterNat_withNatIpsAndDrainNatIps(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -417,6 +456,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)
}

<% unless version == 'ga' -%>
func testAccComputeRouterNatBaseResourcesWithNatIps(routerName string) string {
return fmt.Sprintf(`
Expand Down

0 comments on commit 4601ff7

Please sign in to comment.