Skip to content

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

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
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/services/compute/resource_compute_router_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,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 @@ -575,6 +589,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 @@ -751,6 +771,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 @@ -1209,6 +1232,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 @@ -1455,6 +1482,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/services/compute/resource_compute_router_nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,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 testAccCheckComputeRouterNatDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)
Expand Down Expand Up @@ -559,6 +619,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