Skip to content
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

add autoNetworkTier to Router NAT #18055

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
32 changes: 32 additions & 0 deletions google/services/compute/resource_compute_router_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ ranges in every Subnetwork are allowed to Nat.
contains ALL_SUBNETWORKS_ALL_IP_RANGES or
ALL_SUBNETWORKS_ALL_PRIMARY_IP_RANGES, then there should not be any
other RouterNat section in any Router for this network in this region. Possible values: ["ALL_SUBNETWORKS_ALL_IP_RANGES", "ALL_SUBNETWORKS_ALL_PRIMARY_IP_RANGES", "LIST_OF_SUBNETWORKS"]`,
},
"auto_network_tier": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"PREMIUM", "STANDARD", ""}),
Description: `The network tier to use when automatically reserving NAT IP addresses.
Must be one of: PREMIUM, STANDARD. If not specified, then the current
project-level default tier is used. Possible values: ["PREMIUM", "STANDARD"]`,
},
"drain_nat_ips": {
Type: schema.TypeSet,
Expand Down Expand Up @@ -608,6 +617,12 @@ func resourceComputeRouterNatCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("enable_endpoint_independent_mapping"); ok || !reflect.DeepEqual(v, enableEndpointIndependentMappingProp) {
obj["enableEndpointIndependentMapping"] = enableEndpointIndependentMappingProp
}
autoNetworkTierProp, err := expandNestedComputeRouterNatAutoNetworkTier(d.Get("auto_network_tier"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("auto_network_tier"); !tpgresource.IsEmptyValue(reflect.ValueOf(autoNetworkTierProp)) && (ok || !reflect.DeepEqual(v, autoNetworkTierProp)) {
obj["autoNetworkTier"] = autoNetworkTierProp
}

lockName, err := tpgresource.ReplaceVars(d, config, "router/{{region}}/{{router}}")
if err != nil {
Expand Down Expand Up @@ -785,6 +800,9 @@ func resourceComputeRouterNatRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("enable_endpoint_independent_mapping", flattenNestedComputeRouterNatEnableEndpointIndependentMapping(res["enableEndpointIndependentMapping"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}
if err := d.Set("auto_network_tier", flattenNestedComputeRouterNatAutoNetworkTier(res["autoNetworkTier"], d, config)); err != nil {
return fmt.Errorf("Error reading RouterNat: %s", err)
}

return nil
}
Expand Down Expand Up @@ -901,6 +919,12 @@ func resourceComputeRouterNatUpdate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("enable_endpoint_independent_mapping"); ok || !reflect.DeepEqual(v, enableEndpointIndependentMappingProp) {
obj["enableEndpointIndependentMapping"] = enableEndpointIndependentMappingProp
}
autoNetworkTierProp, err := expandNestedComputeRouterNatAutoNetworkTier(d.Get("auto_network_tier"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("auto_network_tier"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, autoNetworkTierProp)) {
obj["autoNetworkTier"] = autoNetworkTierProp
}

lockName, err := tpgresource.ReplaceVars(d, config, "router/{{region}}/{{router}}")
if err != nil {
Expand Down Expand Up @@ -1325,6 +1349,10 @@ func flattenNestedComputeRouterNatEnableEndpointIndependentMapping(v interface{}
return v
}

func flattenNestedComputeRouterNatAutoNetworkTier(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func expandNestedComputeRouterNatName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down Expand Up @@ -1616,6 +1644,10 @@ func expandNestedComputeRouterNatEnableEndpointIndependentMapping(v interface{},
return v, nil
}

func expandNestedComputeRouterNatAutoNetworkTier(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.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
Expand Down
109 changes: 109 additions & 0 deletions google/services/compute/resource_compute_router_nat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,31 @@ func TestAccComputeRouterNat_withEndpointTypes(t *testing.T) {
})
}

func TestAccComputeRouterNat_AutoNetworkTier(t *testing.T) {
t.Parallel()

testId := acctest.RandString(t, 10)
routerName := fmt.Sprintf("tf-test-router-private-nat-%s", testId)
hubName := fmt.Sprintf("%s-hub", routerName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeRouterNatWitAutoNetworkTier(routerName, hubName),
},
{
// implicitly full ImportStateId
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 := acctest.GoogleProviderConfig(t)
Expand Down Expand Up @@ -1303,3 +1328,87 @@ resource "google_compute_router_nat" "foobar" {
}
`, routerName, routerName, routerName, routerName)
}

func testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks(routerName, hubName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "foobar" {
name = "%s-net"
auto_create_subnetworks = "false"
}

resource "google_compute_subnetwork" "subnet1" {
name = "%s-subnet1"
network = google_compute_network.foobar.self_link
ip_cidr_range = "10.0.0.0/16"
region = "us-central1"
purpose = "PRIVATE_NAT"
}

resource "google_compute_subnetwork" "subnet2" {
name = "%s-subnet2"
network = google_compute_network.foobar.self_link
ip_cidr_range = "10.10.1.0/24"
region = "us-central1"
purpose = "PRIVATE_NAT"
}

resource "google_compute_subnetwork" "subnet3" {
name = "%s-subnet3"
network = google_compute_network.foobar.self_link
ip_cidr_range = "10.158.1.0/24"
region = "us-central1"
purpose = "PRIVATE_NAT"
}

resource "google_compute_subnetwork" "subnet4" {
name = "%s-subnet4"
network = google_compute_network.foobar.self_link
ip_cidr_range = "10.168.1.0/24"
region = "us-central1"
purpose = "PRIVATE_NAT"
}

resource "google_network_connectivity_hub" "foobar" {
name = "%s"
description = "vpc hub for inter vpc nat"
}

resource "google_network_connectivity_spoke" "primary" {
name = "%s-spoke"
location = "global"
description = "vpc spoke for inter vpc nat"
hub = google_network_connectivity_hub.foobar.id
linked_vpc_network {
exclude_export_ranges = [
"10.10.0.0/16"
]
uri = google_compute_network.foobar.self_link
}
}

resource "google_compute_router" "foobar" {
name = "%s"
region = google_compute_subnetwork.subnet1.region
network = google_compute_network.foobar.self_link
depends_on = [
google_network_connectivity_spoke.primary
]
}
`, routerName, routerName, routerName, routerName, routerName, hubName, routerName, routerName)
}

func testAccComputeRouterNatWitAutoNetworkTier(routerName, hubName string) string {
return fmt.Sprintf(`
%s

resource "google_compute_router_nat" "foobar" {
name = "%s"
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region

source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES"
nat_ip_allocate_option = "AUTO_ONLY"
auto_network_tier = "PREMIUM"
}
`, testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks(routerName, hubName), routerName)
}
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 @@ -377,6 +377,13 @@ The following arguments are supported:
Default value is `PUBLIC`.
Possible values are: `PUBLIC`, `PRIVATE`.

* `auto_network_tier` -
(Optional)
The network tier to use when automatically reserving NAT IP addresses.
Must be one of: PREMIUM, STANDARD. If not specified, then the current
project-level default tier is used.
Possible values are: `PREMIUM`, `STANDARD`.

* `region` -
(Optional)
Region where the router and NAT reside.
Expand Down