Skip to content

Added "endpointTypes" support to compute router nat resource #10338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mmv1/products/compute/RouterNat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ properties:
- :ERRORS_ONLY
- :TRANSLATIONS_ONLY
- :ALL
- !ruby/object:Api::Type::Array
name: 'endpointTypes'
immutable: true
min_size: 1
description: |
Specifies the endpoint Types supported by the NAT Gateway.
Supported values include:
`ENDPOINT_TYPE_VM`, `ENDPOINT_TYPE_SWG`,
`ENDPOINT_TYPE_MANAGED_PROXY_LB`.
default_from_api: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Using "default_from_api" here since "default_value" does not support array values.

item_type: Api::Type::String
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a string type here instead of a enum (as the API specifies) to follow the same implementation used for the "sourceIpRangesToNat" field in this resource.

- !ruby/object:Api::Type::Array
name: rules
description: 'A list of rules associated with this NAT.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,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,
},
},
})
}

<% unless version == 'ga' -%>
func TestAccComputeRouterNat_withPrivateNat(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -817,6 +877,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
Loading