Skip to content

Commit cf185d9

Browse files
Add fields for custom ranges for interconnect attachment (#14106) (#10092)
[upstream:844aac8472ba65afa501f62815a12e52882f9ef5] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent b62ec7d commit cf185d9

5 files changed

+221
-0
lines changed

.changelog/14106.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `candidate_cloud_router_ip_address`, `candidate_customer_router_ip_address`, `candidate_cloud_router_ipv6_address`, and `candidate_customer_router_ipv6_address` fields to `google_compute_interconnect_attachment` resource (beta)
3+
```

google-beta/services/compute/resource_compute_interconnect_attachment.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,34 @@ For attachments of type DEDICATED, the user can set the bandwidth.
116116
For attachments of type PARTNER, the Google Partner that is operating the interconnect must set the bandwidth.
117117
Output only for PARTNER type, mutable for PARTNER_PROVIDER and DEDICATED,
118118
Defaults to BPS_10G Possible values: ["BPS_50M", "BPS_100M", "BPS_200M", "BPS_300M", "BPS_400M", "BPS_500M", "BPS_1G", "BPS_2G", "BPS_5G", "BPS_10G", "BPS_20G", "BPS_50G", "BPS_100G"]`,
119+
},
120+
"candidate_cloud_router_ip_address": {
121+
Type: schema.TypeString,
122+
Optional: true,
123+
ForceNew: true,
124+
Description: `Single IPv4 address + prefix length to be configured on the cloud router interface for this
125+
interconnect attachment. Example: 203.0.113.1/29`,
126+
},
127+
"candidate_cloud_router_ipv6_address": {
128+
Type: schema.TypeString,
129+
Optional: true,
130+
ForceNew: true,
131+
Description: `Single IPv6 address + prefix length to be configured on the cloud router interface for this
132+
interconnect attachment. Example: 2001:db8::1/125`,
133+
},
134+
"candidate_customer_router_ip_address": {
135+
Type: schema.TypeString,
136+
Optional: true,
137+
ForceNew: true,
138+
Description: `Single IPv4 address + prefix length to be configured on the customer router interface for this
139+
interconnect attachment. Example: 203.0.113.2/29`,
140+
},
141+
"candidate_customer_router_ipv6_address": {
142+
Type: schema.TypeString,
143+
Optional: true,
144+
ForceNew: true,
145+
Description: `Single IPv6 address + prefix length to be configured on the customer router interface for this
146+
interconnect attachment. Example: 2001:db8::2/125`,
119147
},
120148
"candidate_subnets": {
121149
Type: schema.TypeList,
@@ -474,6 +502,30 @@ func resourceComputeInterconnectAttachmentCreate(d *schema.ResourceData, meta in
474502
} else if v, ok := d.GetOkExists("label_fingerprint"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelFingerprintProp)) && (ok || !reflect.DeepEqual(v, labelFingerprintProp)) {
475503
obj["labelFingerprint"] = labelFingerprintProp
476504
}
505+
candidateCloudRouterIpAddressProp, err := expandComputeInterconnectAttachmentCandidateCloudRouterIpAddress(d.Get("candidate_cloud_router_ip_address"), d, config)
506+
if err != nil {
507+
return err
508+
} else if v, ok := d.GetOkExists("candidate_cloud_router_ip_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(candidateCloudRouterIpAddressProp)) && (ok || !reflect.DeepEqual(v, candidateCloudRouterIpAddressProp)) {
509+
obj["candidateCloudRouterIpAddress"] = candidateCloudRouterIpAddressProp
510+
}
511+
candidateCustomerRouterIpAddressProp, err := expandComputeInterconnectAttachmentCandidateCustomerRouterIpAddress(d.Get("candidate_customer_router_ip_address"), d, config)
512+
if err != nil {
513+
return err
514+
} else if v, ok := d.GetOkExists("candidate_customer_router_ip_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(candidateCustomerRouterIpAddressProp)) && (ok || !reflect.DeepEqual(v, candidateCustomerRouterIpAddressProp)) {
515+
obj["candidateCustomerRouterIpAddress"] = candidateCustomerRouterIpAddressProp
516+
}
517+
candidateCloudRouterIpv6AddressProp, err := expandComputeInterconnectAttachmentCandidateCloudRouterIpv6Address(d.Get("candidate_cloud_router_ipv6_address"), d, config)
518+
if err != nil {
519+
return err
520+
} else if v, ok := d.GetOkExists("candidate_cloud_router_ipv6_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(candidateCloudRouterIpv6AddressProp)) && (ok || !reflect.DeepEqual(v, candidateCloudRouterIpv6AddressProp)) {
521+
obj["candidateCloudRouterIpv6Address"] = candidateCloudRouterIpv6AddressProp
522+
}
523+
candidateCustomerRouterIpv6AddressProp, err := expandComputeInterconnectAttachmentCandidateCustomerRouterIpv6Address(d.Get("candidate_customer_router_ipv6_address"), d, config)
524+
if err != nil {
525+
return err
526+
} else if v, ok := d.GetOkExists("candidate_customer_router_ipv6_address"); !tpgresource.IsEmptyValue(reflect.ValueOf(candidateCustomerRouterIpv6AddressProp)) && (ok || !reflect.DeepEqual(v, candidateCustomerRouterIpv6AddressProp)) {
527+
obj["candidateCustomerRouterIpv6Address"] = candidateCustomerRouterIpv6AddressProp
528+
}
477529
labelsProp, err := expandComputeInterconnectAttachmentEffectiveLabels(d.Get("effective_labels"), d, config)
478530
if err != nil {
479531
return err
@@ -724,6 +776,18 @@ func resourceComputeInterconnectAttachmentRead(d *schema.ResourceData, meta inte
724776
if err := d.Set("label_fingerprint", flattenComputeInterconnectAttachmentLabelFingerprint(res["labelFingerprint"], d, config)); err != nil {
725777
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
726778
}
779+
if err := d.Set("candidate_cloud_router_ip_address", flattenComputeInterconnectAttachmentCandidateCloudRouterIpAddress(res["candidateCloudRouterIpAddress"], d, config)); err != nil {
780+
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
781+
}
782+
if err := d.Set("candidate_customer_router_ip_address", flattenComputeInterconnectAttachmentCandidateCustomerRouterIpAddress(res["candidateCustomerRouterIpAddress"], d, config)); err != nil {
783+
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
784+
}
785+
if err := d.Set("candidate_cloud_router_ipv6_address", flattenComputeInterconnectAttachmentCandidateCloudRouterIpv6Address(res["candidateCloudRouterIpv6Address"], d, config)); err != nil {
786+
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
787+
}
788+
if err := d.Set("candidate_customer_router_ipv6_address", flattenComputeInterconnectAttachmentCandidateCustomerRouterIpv6Address(res["candidateCustomerRouterIpv6Address"], d, config)); err != nil {
789+
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
790+
}
727791
if err := d.Set("terraform_labels", flattenComputeInterconnectAttachmentTerraformLabels(res["labels"], d, config)); err != nil {
728792
return fmt.Errorf("Error reading InterconnectAttachment: %s", err)
729793
}
@@ -1133,6 +1197,22 @@ func flattenComputeInterconnectAttachmentLabelFingerprint(v interface{}, d *sche
11331197
return v
11341198
}
11351199

1200+
func flattenComputeInterconnectAttachmentCandidateCloudRouterIpAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1201+
return v
1202+
}
1203+
1204+
func flattenComputeInterconnectAttachmentCandidateCustomerRouterIpAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1205+
return v
1206+
}
1207+
1208+
func flattenComputeInterconnectAttachmentCandidateCloudRouterIpv6Address(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1209+
return v
1210+
}
1211+
1212+
func flattenComputeInterconnectAttachmentCandidateCustomerRouterIpv6Address(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
1213+
return v
1214+
}
1215+
11361216
func flattenComputeInterconnectAttachmentTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
11371217
if v == nil {
11381218
return v
@@ -1239,6 +1319,22 @@ func expandComputeInterconnectAttachmentLabelFingerprint(v interface{}, d tpgres
12391319
return v, nil
12401320
}
12411321

1322+
func expandComputeInterconnectAttachmentCandidateCloudRouterIpAddress(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1323+
return v, nil
1324+
}
1325+
1326+
func expandComputeInterconnectAttachmentCandidateCustomerRouterIpAddress(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1327+
return v, nil
1328+
}
1329+
1330+
func expandComputeInterconnectAttachmentCandidateCloudRouterIpv6Address(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1331+
return v, nil
1332+
}
1333+
1334+
func expandComputeInterconnectAttachmentCandidateCustomerRouterIpv6Address(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1335+
return v, nil
1336+
}
1337+
12421338
func expandComputeInterconnectAttachmentEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
12431339
if v == nil {
12441340
return map[string]string{}, nil

google-beta/services/compute/resource_compute_interconnect_attachment_generated_meta.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ api_resource_type_kind: 'InterconnectAttachment'
77
fields:
88
- field: 'admin_enabled'
99
- field: 'bandwidth'
10+
- field: 'candidate_cloud_router_ip_address'
11+
- field: 'candidate_cloud_router_ipv6_address'
12+
- field: 'candidate_customer_router_ip_address'
13+
- field: 'candidate_customer_router_ipv6_address'
1014
- field: 'candidate_subnets'
1115
- field: 'cloud_router_ip_address'
1216
- field: 'cloud_router_ipv6_address'

google-beta/services/compute/resource_compute_interconnect_attachment_generated_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,65 @@ resource "google_compute_network" "network" {
211211
`, context)
212212
}
213213

214+
func TestAccComputeInterconnectAttachment_computeInterconnectAttachmentCustomRangesExample(t *testing.T) {
215+
t.Parallel()
216+
217+
context := map[string]interface{}{
218+
"random_suffix": acctest.RandString(t, 10),
219+
}
220+
221+
acctest.VcrTest(t, resource.TestCase{
222+
PreCheck: func() { acctest.AccTestPreCheck(t) },
223+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
224+
CheckDestroy: testAccCheckComputeInterconnectAttachmentDestroyProducer(t),
225+
Steps: []resource.TestStep{
226+
{
227+
Config: testAccComputeInterconnectAttachment_computeInterconnectAttachmentCustomRangesExample(context),
228+
},
229+
{
230+
ResourceName: "google_compute_interconnect_attachment.custom-ranges-interconnect-attachment",
231+
ImportState: true,
232+
ImportStateVerify: true,
233+
ImportStateVerifyIgnore: []string{"candidate_subnets", "labels", "region", "router", "subnet_length", "terraform_labels"},
234+
},
235+
},
236+
})
237+
}
238+
239+
func testAccComputeInterconnectAttachment_computeInterconnectAttachmentCustomRangesExample(context map[string]interface{}) string {
240+
return acctest.Nprintf(`
241+
resource "google_compute_interconnect_attachment" "custom-ranges-interconnect-attachment" {
242+
name = "tf-test-test-custom-ranges-interconnect-attachment%{random_suffix}"
243+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
244+
type = "PARTNER"
245+
router = google_compute_router.foobar.id
246+
mtu = 1500
247+
stack_type = "IPV4_IPV6"
248+
labels = { mykey = "myvalue" }
249+
candidate_cloud_router_ip_address = "192.169.0.1/29"
250+
candidate_customer_router_ip_address = "192.169.0.2/29"
251+
candidate_cloud_router_ipv6_address = "748d:2f23:6651:9455:828b:ca81:6fe0:fed1/125"
252+
candidate_customer_router_ipv6_address = "748d:2f23:6651:9455:828b:ca81:6fe0:fed2/125"
253+
provider = google-beta
254+
}
255+
256+
resource "google_compute_router" "foobar" {
257+
name = "tf-test-test-router%{random_suffix}"
258+
network = google_compute_network.foobar.name
259+
bgp {
260+
asn = 16550
261+
}
262+
provider = google-beta
263+
}
264+
265+
resource "google_compute_network" "foobar" {
266+
name = "tf-test-test-network%{random_suffix}"
267+
auto_create_subnetworks = false
268+
provider = google-beta
269+
}
270+
`, context)
271+
}
272+
214273
func testAccCheckComputeInterconnectAttachmentDestroyProducer(t *testing.T) func(s *terraform.State) error {
215274
return func(s *terraform.State) error {
216275
for name, rs := range s.RootModule().Resources {

website/docs/r/compute_interconnect_attachment.html.markdown

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,45 @@ resource "google_compute_network" "network" {
105105
auto_create_subnetworks = false
106106
}
107107
```
108+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
109+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md&cloudshell_working_dir=compute_interconnect_attachment_custom_ranges&open_in_editor=main.tf" target="_blank">
110+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
111+
</a>
112+
</div>
113+
## Example Usage - Compute Interconnect Attachment Custom Ranges
114+
115+
116+
```hcl
117+
resource "google_compute_interconnect_attachment" "custom-ranges-interconnect-attachment" {
118+
name = "test-custom-ranges-interconnect-attachment"
119+
edge_availability_domain = "AVAILABILITY_DOMAIN_1"
120+
type = "PARTNER"
121+
router = google_compute_router.foobar.id
122+
mtu = 1500
123+
stack_type = "IPV4_IPV6"
124+
labels = { mykey = "myvalue" }
125+
candidate_cloud_router_ip_address = "192.169.0.1/29"
126+
candidate_customer_router_ip_address = "192.169.0.2/29"
127+
candidate_cloud_router_ipv6_address = "748d:2f23:6651:9455:828b:ca81:6fe0:fed1/125"
128+
candidate_customer_router_ipv6_address = "748d:2f23:6651:9455:828b:ca81:6fe0:fed2/125"
129+
provider = google-beta
130+
}
131+
132+
resource "google_compute_router" "foobar" {
133+
name = "test-router"
134+
network = google_compute_network.foobar.name
135+
bgp {
136+
asn = 16550
137+
}
138+
provider = google-beta
139+
}
140+
141+
resource "google_compute_network" "foobar" {
142+
name = "test-network"
143+
auto_create_subnetworks = false
144+
provider = google-beta
145+
}
146+
```
108147

109148
## Argument Reference
110149

@@ -249,6 +288,26 @@ The following arguments are supported:
249288
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
250289
Please refer to the field `effective_labels` for all of the labels present on the resource.
251290

291+
* `candidate_cloud_router_ip_address` -
292+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
293+
Single IPv4 address + prefix length to be configured on the cloud router interface for this
294+
interconnect attachment. Example: 203.0.113.1/29
295+
296+
* `candidate_customer_router_ip_address` -
297+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
298+
Single IPv4 address + prefix length to be configured on the customer router interface for this
299+
interconnect attachment. Example: 203.0.113.2/29
300+
301+
* `candidate_cloud_router_ipv6_address` -
302+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
303+
Single IPv6 address + prefix length to be configured on the cloud router interface for this
304+
interconnect attachment. Example: 2001:db8::1/125
305+
306+
* `candidate_customer_router_ipv6_address` -
307+
(Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
308+
Single IPv6 address + prefix length to be configured on the customer router interface for this
309+
interconnect attachment. Example: 2001:db8::2/125
310+
252311
* `region` -
253312
(Optional)
254313
Region where the regional interconnect attachment resides.

0 commit comments

Comments
 (0)