Skip to content

Commit c1e0ce0

Browse files
NandiniAgrawal15NickElliot
authored andcommitted
Add Terraform Support for WireGroups. (GoogleCloudPlatform#13944)
Co-authored-by: Nick Elliot <[email protected]>
1 parent 44e1d5a commit c1e0ce0

File tree

6 files changed

+426
-0
lines changed

6 files changed

+426
-0
lines changed
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
# Copyright 2024 Google Inc.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
---
15+
name: 'WireGroup'
16+
kind: 'compute#wireGroup'
17+
description: |
18+
The WireGroup resource represents a group of redundant wires between interconnects in two different metros. Each WireGroup belongs to a CrossSiteNetwork. A wire group defines endpoints and the wires which exist between them.
19+
20+
references:
21+
guides:
22+
'Create a WireGroup': 'https://cloud.google.com/network-connectivity/docs/interconnect/how-to/cross-site/modify-network#add-wire-group'
23+
api: 'https://cloud.google.com/compute/docs/reference/rest/beta/wireGroups'
24+
min_version: beta
25+
docs:
26+
id_format: 'projects/{{project}}/global/crossSiteNetworks/{{cross_site_network}}/wireGroups/{{name}}'
27+
base_url: 'projects/{{project}}/global/crossSiteNetworks/{{cross_site_network}}/wireGroups'
28+
self_link: 'projects/{{project}}/global/crossSiteNetworks/{{cross_site_network}}/wireGroups/{{name}}'
29+
update_verb: 'PATCH'
30+
update_mask: true
31+
import_format:
32+
- 'projects/{{project}}/global/crossSiteNetworks/{{cross_site_network}}/wireGroups/{{name}}'
33+
timeouts:
34+
insert_minutes: 20
35+
update_minutes: 20
36+
delete_minutes: 20
37+
async:
38+
actions: ['create', 'delete', 'update']
39+
type: 'OpAsync'
40+
operation:
41+
base_url: '{{op_id}}'
42+
result:
43+
resource_inside_response: false
44+
custom_code:
45+
test_check_destroy: 'templates/terraform/custom_check_destroy/wire_group.go.tmpl'
46+
examples:
47+
- name: 'compute_wire_group_basic'
48+
primary_resource_id: 'example-test-wire-group'
49+
vars:
50+
name: 'test-wire-group'
51+
description: 'Example Wire Group'
52+
cross_site_network: 'test-cross-site-network'
53+
min_version: 'beta'
54+
test_env_vars:
55+
project: 'PROJECT_NAME'
56+
parameters:
57+
- name: 'crossSiteNetwork'
58+
type: ResourceRef
59+
description: Required cross site network to which wire group belongs.
60+
required: true
61+
immutable: true
62+
url_param_only: true
63+
resource: 'CrossSiteNetwork'
64+
imports: 'name'
65+
diff_suppress_func: 'tpgresource.CompareResourceNames'
66+
custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl'
67+
min_version: beta
68+
properties:
69+
- name: 'description'
70+
type: String
71+
description: |
72+
An optional description of this resource. Provide this property when you create the resource.
73+
- name: 'creationTimestamp'
74+
type: Time
75+
description: |
76+
Creation timestamp in RFC3339 text format.
77+
output: true
78+
- name: 'name'
79+
type: String
80+
description: |
81+
Name of the resource. Provided by the client when the resource is created. The name must be
82+
1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters
83+
long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first
84+
character must be a lowercase letter, and all following characters must be a dash,
85+
lowercase letter, or digit, except the last character, which cannot be a dash.
86+
required: true
87+
validation:
88+
regex: '^[a-z]([-a-z0-9]*[a-z0-9])?$'
89+
- name: endpoints
90+
type: KeyValuePairs
91+
description: |
92+
Endpoints grouped by location, each mapping to interconnect configurations.
93+
properties:
94+
- name: interconnects
95+
type: KeyValuePairs
96+
description: |
97+
Map of interconnect details.
98+
properties:
99+
- name: interconnect
100+
type: string
101+
- name: vlan_tags
102+
type: Array
103+
description: |
104+
VLAN tags for the interconnect.
105+
item_type:
106+
type: integer
107+
- name: adminEnabled
108+
type: boolean
109+
description: |
110+
Indicates whether the wire group is administratively enabled.
111+
- name: wireGroupProperties
112+
type: NestedObject
113+
description: |
114+
Properties specific to the wire group.
115+
properties:
116+
- name: type
117+
type: enum
118+
description: |
119+
Type of wire group (enum).
120+
WIRE: a single pseudowire over two Interconnect connections with no redundancy.
121+
REDUNDANT: two pseudowires over four Interconnect connections, with two connections in one metro and two connections in another metro.
122+
BOX_AND_CROSS: four pseudowires over four Interconnect connections, with two connections in one metro and two connections in another metro.
123+
enum_values:
124+
- 'WIRE'
125+
- 'REDUNDANT'
126+
- 'BOX_AND_CROSS'
127+
- name: wireProperties
128+
type: NestedObject
129+
description: |
130+
Default properties for wires within the group.
131+
properties:
132+
- name: bandwidthUnmetered
133+
type: Integer
134+
description: |
135+
The unmetered bandwidth setting.
136+
- name: faultResponse
137+
type: enum
138+
description: |
139+
Response when a fault is detected in a pseudowire:
140+
NONE: default.
141+
DISABLE_PORT: set the port line protocol down when inline probes detect a fault. This setting is only permitted on port mode pseudowires.
142+
enum_values:
143+
- 'NONE'
144+
- 'DISABLE_PORT'
145+
- name: wires
146+
type: Array
147+
description: |
148+
The single/redundant wire(s) managed by the wire group.
149+
output: true
150+
item_type:
151+
type: NestedObject
152+
properties:
153+
- name: label
154+
type: string
155+
- name: endpoints
156+
type: Array
157+
description: |
158+
'Wire endpoints are specific Interconnect connections.'
159+
item_type:
160+
type: NestedObject
161+
properties:
162+
- name: interconnect
163+
type: string
164+
- name: vlanTag
165+
type: integer
166+
- name: wireProperties
167+
type: NestedObject
168+
output: true # This is redundant if the parent 'wires' is output: true, but harmless
169+
properties:
170+
- name: bandwidthUnmetered
171+
type: Integer
172+
- name: faultResponse
173+
type: enum
174+
enum_values:
175+
- 'NONE'
176+
- 'DISABLE_PORT'
177+
- name: adminEnabled
178+
type: boolean
179+
- name: topology
180+
type: NestedObject
181+
description: |
182+
Topology details for the wire group configuration.
183+
output: true
184+
properties:
185+
- name: endpoints
186+
type: Array
187+
item_type:
188+
type: NestedObject
189+
properties:
190+
- name: label
191+
type: string
192+
- name: city
193+
type: string
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
config := acctest.GoogleProviderConfig(t)
2+
3+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/global/crossSiteNetworks")
4+
if err != nil {
5+
return err
6+
}
7+
8+
billingProject := ""
9+
10+
if config.BillingProject != "" {
11+
billingProject = config.BillingProject
12+
}
13+
14+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
15+
Config: config,
16+
Method: "GET",
17+
Project: billingProject,
18+
RawURL: url,
19+
UserAgent: config.UserAgent,
20+
})
21+
if err == nil {
22+
return fmt.Errorf("ComputeCrossSiteNetwork still exists at %s", url)
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
config := acctest.GoogleProviderConfig(t)
2+
url, err := tpgresource.ReplaceVarsForTest(config, rs, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/global/crossSiteNetworks/{{"{{"}}cross_site_network{{"}}"}}/wireGroups/{{"{{"}}name{{"}}"}}")
3+
if err != nil {
4+
return err
5+
}
6+
7+
billingProject := ""
8+
9+
if config.BillingProject != "" {
10+
billingProject = config.BillingProject
11+
}
12+
13+
_, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
14+
Config: config,
15+
Method: "GET",
16+
Project: billingProject,
17+
RawURL: url,
18+
UserAgent: config.UserAgent,
19+
})
20+
if err == nil {
21+
return fmt.Errorf("ComputeWireGroup still exists at %s", url)
22+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
billingProject := ""
3+
4+
project, err := tpgresource.GetProject(d, config)
5+
if err != nil {
6+
return fmt.Errorf("Error fetching project for CrossSiteNetwork: %s", err)
7+
}
8+
billingProject = project
9+
10+
url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}ComputeBasePath{{"}}"}}projects/{{"{{"}}project{{"}}"}}/global/crossSiteNetworks/{{"{{"}}crossSiteNetworks{{"}}"}}")
11+
if err != nil {
12+
return err
13+
}
14+
15+
var obj map[string]interface{}
16+
17+
// err == nil indicates that the billing_project value was found
18+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
19+
billingProject = bp
20+
}
21+
22+
headers := make(http.Header)
23+
24+
log.Printf("[DEBUG] Deleting CrossSiteNetwork %q", d.Id())
25+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
26+
Config: config,
27+
Method: "DELETE",
28+
Project: billingProject,
29+
RawURL: url,
30+
UserAgent: userAgent,
31+
Body: obj,
32+
Timeout: d.Timeout(schema.TimeoutDelete),
33+
Headers: headers,
34+
})
35+
if err != nil {
36+
return transport_tpg.HandleNotFoundError(err, d, "CrossSiteNetwork")
37+
}
38+
39+
err = ComputeOperationWaitTime(
40+
config, res, project, "Deleting CrossSiteNetwork", userAgent,
41+
d.Timeout(schema.TimeoutDelete))
42+
43+
if err != nil {
44+
return err
45+
}
46+
47+
log.Printf("[DEBUG] Finished deleting CrossSiteNetwork %q: %#v", d.Id(), res)
48+
return nil
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
data "google_project" "project" {
2+
provider = google-beta
3+
}
4+
5+
resource "google_compute_cross_site_network" "example-cross-site-network" {
6+
name = "{{index $.Vars "cross_site_network"}}"
7+
description = "Example cross site network"
8+
provider = google-beta
9+
}
10+
11+
resource "google_compute_wire_group" "{{$.PrimaryResourceId}}" {
12+
name = "{{index $.Vars "name"}}"
13+
description = "{{index $.Vars "description"}}"
14+
cross_site_network = "{{index $.Vars "cross_site_network"}}"
15+
provider = google-beta
16+
depends_on = [
17+
google_compute_cross_site_network.example-cross-site-network
18+
]
19+
wire_properties {
20+
bandwidth_unmetered = 10
21+
}
22+
wire_group_properties {
23+
type = "WIRE"
24+
}
25+
}

0 commit comments

Comments
 (0)