Skip to content

Commit f0af8b7

Browse files
Added "endpointTypes" support to compute router nat resource (#10338) (#17771)
[upstream:e93e811188d812d43d993ba8af9dcb351a630001] Signed-off-by: Modular Magician <[email protected]>
1 parent 8a0013b commit f0af8b7

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

.changelog/10338.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added 'endpoint_types' field to 'google_compute_router_nat' resource
3+
```

google/services/compute/resource_compute_router_nat.go

+31
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@ Mutually exclusive with enableEndpointIndependentMapping.`,
249249
Description: `Enable endpoint independent mapping.
250250
For more information see the [official documentation](https://cloud.google.com/nat/docs/overview#specs-rfcs).`,
251251
},
252+
"endpoint_types": {
253+
Type: schema.TypeList,
254+
Computed: true,
255+
Optional: true,
256+
ForceNew: true,
257+
Description: `Specifies the endpoint Types supported by the NAT Gateway.
258+
Supported values include:
259+
'ENDPOINT_TYPE_VM', 'ENDPOINT_TYPE_SWG',
260+
'ENDPOINT_TYPE_MANAGED_PROXY_LB'.`,
261+
MinItems: 1,
262+
Elem: &schema.Schema{
263+
Type: schema.TypeString,
264+
},
265+
},
252266
"icmp_idle_timeout_sec": {
253267
Type: schema.TypeInt,
254268
Optional: true,
@@ -575,6 +589,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
575589
} else if v, ok := d.GetOkExists("log_config"); ok || !reflect.DeepEqual(v, logConfigProp) {
576590
obj["logConfig"] = logConfigProp
577591
}
592+
endpointTypesProp, err := expandNestedComputeRouterNatEndpointTypes(d.Get("endpoint_types"), d, config)
593+
if err != nil {
594+
return err
595+
} else if v, ok := d.GetOkExists("endpoint_types"); !tpgresource.IsEmptyValue(reflect.ValueOf(endpointTypesProp)) && (ok || !reflect.DeepEqual(v, endpointTypesProp)) {
596+
obj["endpointTypes"] = endpointTypesProp
597+
}
578598
rulesProp, err := expandNestedComputeRouterNatRules(d.Get("rules"), d, config)
579599
if err != nil {
580600
return err
@@ -751,6 +771,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro
751771
if err := d.Set("log_config", flattenNestedComputeRouterNatLogConfig(res["logConfig"], d, config)); err != nil {
752772
return fmt.Errorf("Error reading RouterNat: %s", err)
753773
}
774+
if err := d.Set("endpoint_types", flattenNestedComputeRouterNatEndpointTypes(res["endpointTypes"], d, config)); err != nil {
775+
return fmt.Errorf("Error reading RouterNat: %s", err)
776+
}
754777
if err := d.Set("rules", flattenNestedComputeRouterNatRules(res["rules"], d, config)); err != nil {
755778
return fmt.Errorf("Error reading RouterNat: %s", err)
756779
}
@@ -1209,6 +1232,10 @@ func flattenNestedComputeRouterNatLogConfigFilter(v interface{}, d *schema.Resou
12091232
return v
12101233
}
12111234

1235+
func flattenNestedComputeRouterNatEndpointTypes(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1236+
return v
1237+
}
1238+
12121239
func flattenNestedComputeRouterNatRules(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
12131240
if v == nil {
12141241
return v
@@ -1455,6 +1482,10 @@ func expandNestedComputeRouterNatLogConfigFilter(v interface{}, d tpgresource.Te
14551482
return v, nil
14561483
}
14571484

1485+
func expandNestedComputeRouterNatEndpointTypes(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1486+
return v, nil
1487+
}
1488+
14581489
func expandNestedComputeRouterNatRules(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
14591490
v = v.(*schema.Set).List()
14601491
l := v.([]interface{})

google/services/compute/resource_compute_router_nat_test.go

+94
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,66 @@ func TestAccComputeRouterNat_withNatRules(t *testing.T) {
357357
})
358358
}
359359

360+
func TestAccComputeRouterNat_withEndpointTypes(t *testing.T) {
361+
t.Parallel()
362+
363+
testId := acctest.RandString(t, 10)
364+
routerName := fmt.Sprintf("tf-test-router-nat-%s", testId)
365+
testResourceName := "google_compute_router_nat.foobar"
366+
367+
acctest.VcrTest(t, resource.TestCase{
368+
PreCheck: func() { acctest.AccTestPreCheck(t) },
369+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
370+
CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t),
371+
Steps: []resource.TestStep{
372+
{
373+
Config: testAccComputeRouterNatBasic(routerName),
374+
Check: resource.ComposeTestCheckFunc(
375+
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_VM"),
376+
),
377+
},
378+
{
379+
ResourceName: testResourceName,
380+
ImportState: true,
381+
ImportStateVerify: true,
382+
},
383+
{
384+
Config: testAccComputeRouterNatUpdateEndpointType(routerName, "ENDPOINT_TYPE_SWG"),
385+
Check: resource.ComposeTestCheckFunc(
386+
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_SWG"),
387+
),
388+
},
389+
{
390+
ResourceName: testResourceName,
391+
ImportState: true,
392+
ImportStateVerify: true,
393+
},
394+
{
395+
Config: testAccComputeRouterNatUpdateEndpointType(routerName, "ENDPOINT_TYPE_VM"),
396+
Check: resource.ComposeTestCheckFunc(
397+
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_VM"),
398+
),
399+
},
400+
{
401+
ResourceName: testResourceName,
402+
ImportState: true,
403+
ImportStateVerify: true,
404+
},
405+
{
406+
Config: testAccComputeRouterNatUpdateEndpointType(routerName, "ENDPOINT_TYPE_MANAGED_PROXY_LB"),
407+
Check: resource.ComposeTestCheckFunc(
408+
resource.TestCheckResourceAttr(testResourceName, "endpoint_types.0", "ENDPOINT_TYPE_MANAGED_PROXY_LB"),
409+
),
410+
},
411+
{
412+
ResourceName: testResourceName,
413+
ImportState: true,
414+
ImportStateVerify: true,
415+
},
416+
},
417+
})
418+
}
419+
360420
func testAccCheckComputeRouterNatDestroyProducer(t *testing.T) func(s *terraform.State) error {
361421
return func(s *terraform.State) error {
362422
config := acctest.GoogleProviderConfig(t)
@@ -559,6 +619,40 @@ resource "google_compute_router_nat" "foobar" {
559619
`, routerName, routerName, routerName, routerName, routerName)
560620
}
561621

622+
func testAccComputeRouterNatUpdateEndpointType(routerName string, endpointType string) string {
623+
return fmt.Sprintf(`
624+
resource "google_compute_network" "foobar" {
625+
name = "%[1]s-net"
626+
}
627+
628+
resource "google_compute_subnetwork" "foobar" {
629+
name = "%[1]s-subnet"
630+
network = google_compute_network.foobar.self_link
631+
ip_cidr_range = "10.0.0.0/16"
632+
region = "us-central1"
633+
}
634+
635+
resource "google_compute_router" "foobar" {
636+
name = "%[1]s"
637+
region = google_compute_subnetwork.foobar.region
638+
network = google_compute_network.foobar.self_link
639+
}
640+
641+
resource "google_compute_router_nat" "foobar" {
642+
name = "%[1]s"
643+
router = google_compute_router.foobar.name
644+
region = google_compute_router.foobar.region
645+
nat_ip_allocate_option = "AUTO_ONLY"
646+
source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
647+
endpoint_types = [ "%[2]s" ]
648+
log_config {
649+
enable = true
650+
filter = "ERRORS_ONLY"
651+
}
652+
}
653+
`, routerName, endpointType)
654+
}
655+
562656
func testAccComputeRouterNatUpdateToNatIPsId(routerName string) string {
563657
return fmt.Sprintf(`
564658
resource "google_compute_router" "foobar" {

website/docs/r/compute_router_nat.html.markdown

+7
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ The following arguments are supported:
351351
Configuration for logging on NAT
352352
Structure is [documented below](#nested_log_config).
353353

354+
* `endpoint_types` -
355+
(Optional)
356+
Specifies the endpoint Types supported by the NAT Gateway.
357+
Supported values include:
358+
`ENDPOINT_TYPE_VM`, `ENDPOINT_TYPE_SWG`,
359+
`ENDPOINT_TYPE_MANAGED_PROXY_LB`.
360+
354361
* `rules` -
355362
(Optional)
356363
A list of rules associated with this NAT.

0 commit comments

Comments
 (0)