Skip to content

Commit b8d7ea4

Browse files
matheusaleixo-citBBBmau
authored andcommitted
Added support for NAT64 when configuring Router NAT (GoogleCloudPlatform#13522)
1 parent f10e430 commit b8d7ea4

File tree

4 files changed

+309
-1
lines changed

4 files changed

+309
-1
lines changed

mmv1/products/compute/RouterNat.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,36 @@ properties:
257257
is_set: true
258258
item_type:
259259
type: String
260+
- name: 'sourceSubnetworkIpRangesToNat64'
261+
type: Enum
262+
description: |
263+
Specify the Nat option for NAT64, which can take one of the following values:
264+
ALL_IPV6_SUBNETWORKS: All of the IP ranges in every Subnetwork are allowed to Nat.
265+
LIST_OF_IPV6_SUBNETWORKS: A list of Subnetworks are allowed to Nat (specified in the field nat64Subnetwork below).
266+
Note that if this field contains NAT64_ALL_V6_SUBNETWORKS no other Router.Nat section in this region can also enable NAT64 for any Subnetworks in this network.
267+
Other Router.Nat sections can still be present to enable NAT44 only.
268+
enum_values:
269+
- 'ALL_IPV6_SUBNETWORKS'
270+
- 'LIST_OF_IPV6_SUBNETWORKS'
271+
- name: 'nat64Subnetwork'
272+
type: Array
273+
description: |
274+
One or more subnetwork NAT configurations whose traffic should be translated by NAT64 Gateway.
275+
Only used if `source_subnetwork_ip_ranges_to_nat64` is set to `LIST_OF_IPV6_SUBNETWORKS`
276+
api_name: nat64Subnetworks
277+
is_set: true
278+
send_empty_value: true
279+
set_hash_func: computeRouterNatSubnetworkHash
280+
item_type:
281+
type: NestedObject
282+
properties:
283+
- name: 'name'
284+
type: ResourceRef
285+
description: 'Self-link of the subnetwork resource that will use NAT64'
286+
required: true
287+
custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
288+
resource: 'Subnetwork'
289+
imports: 'selfLink'
260290
- name: 'minPortsPerVm'
261291
type: Integer
262292
description: |

mmv1/products/dns/Policy.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ properties:
103103
update_url: 'projects/{{project}}/policies/{{name}}'
104104
update_verb: 'PATCH'
105105
default_value: "Managed by Terraform"
106+
- name: 'dns64Config'
107+
type: NestedObject
108+
default_from_api: true
109+
description: Configurations related to DNS64 for this Policy.
110+
properties:
111+
- name: 'scope'
112+
type: NestedObject
113+
description: The scope to which DNS64 config will be applied to.
114+
required: true
115+
properties:
116+
- name: 'allQueries'
117+
type: Boolean
118+
description: Controls whether DNS64 is enabled globally at the network level.
119+
send_empty_value: true
106120
- name: 'enableInboundForwarding'
107121
type: Boolean
108122
description: |

mmv1/third_party/terraform/services/compute/resource_compute_router_nat_test.go

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,38 @@ func testAccCheckComputeRouterNatDelete(t *testing.T, n string) resource.TestChe
797797
}
798798
}
799799

800+
func TestAccComputeRouterNat_withNat64Configuration(t *testing.T) {
801+
t.Parallel()
802+
803+
context := map[string]interface{}{
804+
"random_suffix": acctest.RandString(t, 10),
805+
}
806+
807+
acctest.VcrTest(t, resource.TestCase{
808+
PreCheck: func() { acctest.AccTestPreCheck(t) },
809+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
810+
CheckDestroy: testAccCheckComputeRouterNatDestroyProducer(t),
811+
Steps: []resource.TestStep{
812+
{
813+
Config: testAccComputeRouterNatWithNat64Configuration(context),
814+
},
815+
{
816+
ResourceName: "google_compute_router_nat.foobar",
817+
ImportState: true,
818+
ImportStateVerify: true,
819+
},
820+
{
821+
Config: testAccComputeRouterNatWithNat64ConfigurationUpdate(context),
822+
},
823+
{
824+
ResourceName: "google_compute_router_nat.foobar",
825+
ImportState: true,
826+
ImportStateVerify: true,
827+
},
828+
},
829+
})
830+
}
831+
800832
func testAccComputeRouterNatBasic(routerName string) string {
801833
return fmt.Sprintf(`
802834
resource "google_compute_network" "foobar" {
@@ -2047,3 +2079,136 @@ resource "google_compute_router_nat" "foobar" {
20472079
}
20482080
`, testAccComputeRouterNatBaseResourcesWithPrivateNatSubnetworks(routerName, hubName), routerName)
20492081
}
2082+
2083+
func testAccComputeRouterNatWithNat64Configuration(context map[string]interface{}) string {
2084+
return acctest.Nprintf(`
2085+
resource "google_dns_policy" "foobar" {
2086+
name = "tf-test-example-policy%{random_suffix}"
2087+
enable_inbound_forwarding = false
2088+
enable_logging = false
2089+
2090+
dns64_config {
2091+
scope {
2092+
all_queries = true
2093+
}
2094+
}
2095+
networks {
2096+
network_url = google_compute_network.foobar.id
2097+
}
2098+
}
2099+
2100+
resource "google_compute_network" "foobar" {
2101+
name = "tf-test-network%{random_suffix}"
2102+
enable_ula_internal_ipv6 = true
2103+
auto_create_subnetworks = false
2104+
}
2105+
2106+
resource "google_compute_subnetwork" "foobar" {
2107+
name = "tf-test-subnetwork-%{random_suffix}"
2108+
network = google_compute_network.foobar.self_link
2109+
ip_cidr_range = "10.0.0.0/16"
2110+
region = "us-central1"
2111+
}
2112+
2113+
resource "google_compute_subnetwork" "foobar2" {
2114+
name = "tf-test-subnetwork-2-%{random_suffix}"
2115+
network = google_compute_network.foobar.self_link
2116+
ip_cidr_range = "10.182.0.0/20"
2117+
ipv6_access_type = "EXTERNAL"
2118+
stack_type = "IPV4_IPV6"
2119+
region = "us-central1"
2120+
}
2121+
2122+
resource "google_compute_router" "foobar" {
2123+
name = "tf-test-router%{random_suffix}"
2124+
region = google_compute_subnetwork.foobar.region
2125+
network = google_compute_network.foobar.self_link
2126+
bgp {
2127+
asn = 64514
2128+
}
2129+
}
2130+
2131+
resource "google_compute_router_nat" "foobar" {
2132+
name = "tf-test-router-nat%{random_suffix}"
2133+
router = google_compute_router.foobar.name
2134+
region = google_compute_router.foobar.region
2135+
nat_ip_allocate_option = "AUTO_ONLY"
2136+
2137+
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
2138+
subnetwork {
2139+
name = google_compute_subnetwork.foobar.name
2140+
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
2141+
}
2142+
2143+
source_subnetwork_ip_ranges_to_nat64 = "ALL_IPV6_SUBNETWORKS"
2144+
}
2145+
`, context)
2146+
}
2147+
2148+
func testAccComputeRouterNatWithNat64ConfigurationUpdate(context map[string]interface{}) string {
2149+
return acctest.Nprintf(`
2150+
resource "google_dns_policy" "foobar" {
2151+
name = "tf-test-example-policy%{random_suffix}"
2152+
enable_inbound_forwarding = false
2153+
enable_logging = false
2154+
2155+
dns64_config {
2156+
scope {
2157+
all_queries = true
2158+
}
2159+
}
2160+
networks {
2161+
network_url = google_compute_network.foobar.id
2162+
}
2163+
}
2164+
2165+
resource "google_compute_network" "foobar" {
2166+
name = "tf-test-network%{random_suffix}"
2167+
enable_ula_internal_ipv6 = true
2168+
auto_create_subnetworks = false
2169+
}
2170+
2171+
resource "google_compute_subnetwork" "foobar" {
2172+
name = "tf-test-subnetwork-%{random_suffix}"
2173+
network = google_compute_network.foobar.self_link
2174+
ip_cidr_range = "10.0.0.0/16"
2175+
region = "us-central1"
2176+
}
2177+
2178+
resource "google_compute_subnetwork" "foobar2" {
2179+
name = "tf-test-subnetwork-2-%{random_suffix}"
2180+
network = google_compute_network.foobar.self_link
2181+
ip_cidr_range = "10.182.0.0/20"
2182+
ipv6_access_type = "EXTERNAL"
2183+
stack_type = "IPV4_IPV6"
2184+
region = "us-central1"
2185+
}
2186+
2187+
resource "google_compute_router" "foobar" {
2188+
name = "tf-test-router%{random_suffix}"
2189+
region = google_compute_subnetwork.foobar.region
2190+
network = google_compute_network.foobar.self_link
2191+
bgp {
2192+
asn = 64514
2193+
}
2194+
}
2195+
2196+
resource "google_compute_router_nat" "foobar" {
2197+
name = "tf-test-router-nat%{random_suffix}"
2198+
router = google_compute_router.foobar.name
2199+
region = google_compute_router.foobar.region
2200+
nat_ip_allocate_option = "AUTO_ONLY"
2201+
2202+
source_subnetwork_ip_ranges_to_nat = "LIST_OF_SUBNETWORKS"
2203+
subnetwork {
2204+
name = google_compute_subnetwork.foobar.name
2205+
source_ip_ranges_to_nat = ["ALL_IP_RANGES"]
2206+
}
2207+
2208+
source_subnetwork_ip_ranges_to_nat64 = "LIST_OF_IPV6_SUBNETWORKS"
2209+
nat64_subnetwork {
2210+
name = google_compute_subnetwork.foobar2.name
2211+
}
2212+
}
2213+
`, context)
2214+
}

mmv1/third_party/terraform/services/dns/resource_dns_policy_test.go

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ package dns_test
22

33
import (
44
"fmt"
5-
"github.com/hashicorp/terraform-provider-google/google/acctest"
65
"testing"
76

7+
"github.com/hashicorp/terraform-provider-google/google/acctest"
8+
89
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
910
)
1011

@@ -70,3 +71,101 @@ resource "google_compute_network" "network-2" {
7071
}
7172
`, suffix, forwarding, first_nameserver, second_nameserver, network, suffix, suffix)
7273
}
74+
75+
func TestAccDNSPolicy_dnsPolicyDns64(t *testing.T) {
76+
t.Parallel()
77+
78+
context := map[string]interface{}{
79+
"random_suffix": acctest.RandString(t, 10),
80+
}
81+
82+
acctest.VcrTest(t, resource.TestCase{
83+
PreCheck: func() { acctest.AccTestPreCheck(t) },
84+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
85+
CheckDestroy: testAccCheckDNSPolicyDestroyProducer(t),
86+
Steps: []resource.TestStep{
87+
{
88+
Config: testAccDNSPolicy_dnsPolicyDns64(context),
89+
},
90+
{
91+
ResourceName: "google_dns_policy.example-policy",
92+
ImportState: true,
93+
ImportStateVerify: true,
94+
},
95+
{
96+
Config: testAccDNSPolicy_dnsPolicyDns64Update(context),
97+
},
98+
{
99+
ResourceName: "google_dns_policy.example-policy",
100+
ImportState: true,
101+
ImportStateVerify: true,
102+
},
103+
},
104+
})
105+
}
106+
107+
func testAccDNSPolicy_dnsPolicyDns64(context map[string]interface{}) string {
108+
return acctest.Nprintf(`
109+
resource "google_dns_policy" "example-policy" {
110+
name = "tf-test-example-policy%{random_suffix}"
111+
enable_inbound_forwarding = false
112+
113+
enable_logging = true
114+
115+
dns64_config {
116+
scope {
117+
all_queries = true
118+
}
119+
}
120+
121+
networks {
122+
network_url = google_compute_network.network-1.id
123+
}
124+
networks {
125+
network_url = google_compute_network.network-2.id
126+
}
127+
}
128+
129+
resource "google_compute_network" "network-1" {
130+
name = "tf-test-network-1%{random_suffix}"
131+
auto_create_subnetworks = false
132+
}
133+
134+
resource "google_compute_network" "network-2" {
135+
name = "tf-test-network-2%{random_suffix}"
136+
auto_create_subnetworks = false
137+
}
138+
`, context)
139+
}
140+
141+
func testAccDNSPolicy_dnsPolicyDns64Update(context map[string]interface{}) string {
142+
return acctest.Nprintf(`
143+
resource "google_dns_policy" "example-policy" {
144+
name = "tf-test-example-policy%{random_suffix}"
145+
enable_inbound_forwarding = false
146+
147+
enable_logging = true
148+
149+
dns64_config {
150+
scope {}
151+
}
152+
153+
networks {
154+
network_url = google_compute_network.network-1.id
155+
}
156+
networks {
157+
network_url = google_compute_network.network-2.id
158+
}
159+
}
160+
161+
resource "google_compute_network" "network-1" {
162+
name = "tf-test-network-1%{random_suffix}"
163+
auto_create_subnetworks = false
164+
}
165+
166+
resource "google_compute_network" "network-2" {
167+
name = "tf-test-network-2%{random_suffix}"
168+
auto_create_subnetworks = false
169+
}
170+
`, context)
171+
}

0 commit comments

Comments
 (0)