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 #9379

Merged
Merged
11 changes: 11 additions & 0 deletions mmv1/products/compute/RouterNat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ custom_code: !ruby/object:Provider::Terraform::CustomCode
constants: 'templates/terraform/constants/router_nat.go.erb'
pre_create: 'templates/terraform/constants/router_nat_validate_action_active_range.go.erb'
pre_update: 'templates/terraform/constants/router_nat_validate_action_active_range.go.erb'
# encoder: 'templates/terraform/encoders/router_nat.go.erb'
custom_diff: [
'resourceComputeRouterNatDrainNatIpsCustomDiff',
]
Expand Down Expand Up @@ -448,3 +449,13 @@ properties:
- :PUBLIC
- :PRIVATE
default_value: :PUBLIC
- !ruby/object:Api::Type::Enum
name: 'autoNetworkTier'
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.
values:
- :PREMIUM
- :STANDARD
default_from_api: true
32 changes: 32 additions & 0 deletions mmv1/templates/terraform/encoders/router_nat.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<%# The license inside this block applies to this file.
# Copyright 2020 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return nil, err
}

projectID, err := tpgresource.GetProject(d, meta.(*transport_tpg.Config))
if err != nil {
return nil, err
}

project, err := config.NewComputeClient(userAgent).Projects.Get(projectID).Do()
if err != nil {
return nil, transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("Project data for project %q", projectID))
}

obj["autoNetworkTier"] = project.DefaultNetworkTier
return obj, nil
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,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,
},
},
})
}

<% unless version == 'ga' -%>
func TestAccComputeRouterNat_withPrivateNat(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -1700,7 +1725,7 @@ resource "google_compute_router_nat" "foobar" {
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
type = "PRIVATE"
type = "PRIVATE"
enable_dynamic_port_allocation = false
enable_endpoint_independent_mapping = false
min_ports_per_vm = 32
Expand Down Expand Up @@ -1789,7 +1814,7 @@ resource "google_compute_router_nat" "foobar" {
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
type = "PRIVATE"
type = "PRIVATE"
enable_dynamic_port_allocation = false
enable_endpoint_independent_mapping = false
min_ports_per_vm = 32
Expand All @@ -1810,7 +1835,7 @@ resource "google_compute_router_nat" "foobar" {
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
type = "PRIVATE"
type = "PRIVATE"
enable_dynamic_port_allocation = false
enable_endpoint_independent_mapping = false
min_ports_per_vm = 32
Expand Down Expand Up @@ -1841,7 +1866,7 @@ resource "google_compute_router_nat" "foobar" {
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
type = "PRIVATE"
type = "PRIVATE"
enable_dynamic_port_allocation = false
enable_endpoint_independent_mapping = false
min_ports_per_vm = 32
Expand Down Expand Up @@ -1869,7 +1894,7 @@ resource "google_compute_router_nat" "foobar" {
router = google_compute_router.foobar.name
region = google_compute_router.foobar.region
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
type = "PRIVATE"
type = "PRIVATE"
enable_dynamic_port_allocation = false
enable_endpoint_independent_mapping = false
min_ports_per_vm = 32
Expand All @@ -1891,3 +1916,19 @@ resource "google_compute_router_nat" "foobar" {
}

<% end -%>

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)
}