Skip to content

Commit 4ec5f5e

Browse files
Added IPv6 support for Internal Ranges in Terraform. (#13626) (#22401)
[upstream:4002beb93f0622f8e7ee4509ca6fa2e8ec5c508b] Signed-off-by: Modular Magician <[email protected]>
1 parent 36e0c67 commit 4ec5f5e

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

.changelog/13626.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
networkconnectivity: added IPv6 support to `google_network_connectivity_internal_range` resource
3+
```

google/services/networkconnectivity/resource_network_connectivity_internal_range.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ Only IPv4 CIDR ranges are supported.`,
9797
},
9898
},
9999
"ip_cidr_range": {
100-
Type: schema.TypeString,
101-
Computed: true,
102-
Optional: true,
103-
Description: `The IP range that this internal range defines.`,
100+
Type: schema.TypeString,
101+
Computed: true,
102+
Optional: true,
103+
Description: `The IP range that this internal range defines.
104+
NOTE: IPv6 ranges are limited to usage=EXTERNAL_TO_VPC and peering=FOR_SELF
105+
NOTE: For IPv6 Ranges this field is compulsory, i.e. the address range must be specified explicitly.`,
104106
},
105107
"labels": {
106108
Type: schema.TypeMap,
@@ -152,7 +154,9 @@ For example /projects/{project}/regions/{region}/subnetworks/{subnet}`,
152154
Type: schema.TypeInt,
153155
Optional: true,
154156
Description: `An alternate to ipCidrRange. Can be set when trying to create a reservation that automatically finds a free range of the given size.
155-
If both ipCidrRange and prefixLength are set, there is an error if the range sizes do not match. Can also be used during updates to change the range size.`,
157+
If both ipCidrRange and prefixLength are set, there is an error if the range sizes do not match. Can also be used during updates to change the range size.
158+
NOTE: For IPv6 this field only works if ip_cidr_range is set as well, and both fields must match. In other words, with IPv6 this field only works as
159+
a redundant parameter.`,
156160
},
157161
"target_cidr_range": {
158162
Type: schema.TypeList,

google/services/networkconnectivity/resource_network_connectivity_internal_range_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,58 @@ resource "google_compute_network" "default" {
284284
}
285285
`, context)
286286
}
287+
288+
func TestAccNetworkConnectivityInternalRange_networkConnectivityInternalRangesIPv6Example_full(t *testing.T) {
289+
t.Parallel()
290+
291+
context := map[string]interface{}{
292+
"random_suffix": acctest.RandString(t, 10),
293+
}
294+
295+
resourceName := "google_network_connectivity_internal_range.default"
296+
297+
acctest.VcrTest(t, resource.TestCase{
298+
PreCheck: func() { acctest.AccTestPreCheck(t) },
299+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
300+
CheckDestroy: testAccCheckNetworkConnectivityInternalRangeDestroyProducer(t),
301+
Steps: []resource.TestStep{
302+
{
303+
Config: testAccNetworkConnectivityInternalRange_networkConnectivityInternalRangesIPv6Example_full(context),
304+
Check: resource.ComposeTestCheckFunc(
305+
resource.TestCheckResourceAttr(
306+
resourceName, "description", "Test internal range IPv6"),
307+
resource.TestCheckResourceAttr(
308+
resourceName, "ip_cidr_range", "1234:0:1:1::/64"),
309+
resource.TestCheckResourceAttr(
310+
resourceName, "usage", "EXTERNAL_TO_VPC"),
311+
resource.TestCheckResourceAttr(
312+
resourceName, "peering", "FOR_SELF"),
313+
),
314+
},
315+
{
316+
ResourceName: resourceName,
317+
ImportState: true,
318+
ImportStateVerify: true,
319+
ImportStateVerifyIgnore: []string{"name", "network", "labels", "terraform_labels"},
320+
},
321+
},
322+
})
323+
}
324+
325+
func testAccNetworkConnectivityInternalRange_networkConnectivityInternalRangesIPv6Example_full(context map[string]interface{}) string {
326+
return acctest.Nprintf(`
327+
resource "google_network_connectivity_internal_range" "default" {
328+
name = "basic%{random_suffix}"
329+
description = "Test internal range IPv6"
330+
network = google_compute_network.default.name
331+
ip_cidr_range = "1234:0:1:1::/64"
332+
usage = "EXTERNAL_TO_VPC"
333+
peering = "FOR_SELF"
334+
}
335+
336+
resource "google_compute_network" "default" {
337+
name = "tf-test-internal-ranges%{random_suffix}"
338+
auto_create_subnetworks = false
339+
}
340+
`, context)
341+
}

website/docs/r/network_connectivity_internal_range.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,15 @@ The following arguments are supported:
225225
* `ip_cidr_range` -
226226
(Optional)
227227
The IP range that this internal range defines.
228+
NOTE: IPv6 ranges are limited to usage=EXTERNAL_TO_VPC and peering=FOR_SELF
229+
NOTE: For IPv6 Ranges this field is compulsory, i.e. the address range must be specified explicitly.
228230

229231
* `prefix_length` -
230232
(Optional)
231233
An alternate to ipCidrRange. Can be set when trying to create a reservation that automatically finds a free range of the given size.
232234
If both ipCidrRange and prefixLength are set, there is an error if the range sizes do not match. Can also be used during updates to change the range size.
235+
NOTE: For IPv6 this field only works if ip_cidr_range is set as well, and both fields must match. In other words, with IPv6 this field only works as
236+
a redundant parameter.
233237

234238
* `target_cidr_range` -
235239
(Optional)

0 commit comments

Comments
 (0)