Skip to content

Commit ed43b8c

Browse files
Add MulticloudDataTransferConfig Resource (#15988)
1 parent 3e02bdd commit ed43b8c

File tree

5 files changed

+490
-0
lines changed

5 files changed

+490
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Copyright 2025 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: 'MulticloudDataTransferConfig'
16+
description: |
17+
'Manage Multicloud Data Transfer Configs'
18+
references:
19+
guides:
20+
'QUICKSTART_TITLE': 'https://docs.cloud.google.com/data-transfer-essentials/docs/create-resources'
21+
api: 'https://docs.cloud.google.com/network-connectivity/docs/reference/networkconnectivity/rest/v1/projects.locations.multicloudDataTransferConfigs'
22+
23+
base_url: 'projects/{{project}}/locations/{{location}}/multicloudDataTransferConfigs'
24+
self_link: 'projects/{{project}}/locations/{{location}}/multicloudDataTransferConfigs/{{name}}'
25+
26+
immutable: false
27+
28+
create_url: 'projects/{{project}}/locations/{{location}}/multicloudDataTransferConfigs?multicloudDataTransferConfigId={{name}}'
29+
30+
update_verb: 'PATCH'
31+
update_mask: true
32+
33+
autogen_async: true
34+
async:
35+
operation:
36+
base_url: '{{op_id}}'
37+
38+
examples:
39+
- name: "network_connectivity_multicloud_data_transfer_config_basic"
40+
primary_resource_id: "example"
41+
vars:
42+
config_name: "basic_config"
43+
44+
parameters:
45+
- name: 'location'
46+
type: String
47+
required: true
48+
immutable: true
49+
url_param_only: true
50+
description: |
51+
The location of the multicloud data transfer config.
52+
- name: 'name'
53+
type: String
54+
required: true
55+
immutable: true
56+
url_param_only: true
57+
description: |
58+
The name of the MulticloudDataTransferConfig resource.
59+
60+
properties:
61+
- name: 'createTime'
62+
type: Time
63+
output: true
64+
description: |
65+
Time when the MulticloudDataTransferConfig resource was created.
66+
- name: 'updateTime'
67+
type: Time
68+
output: true
69+
description: |
70+
Time when the MulticloudDataTransferConfig resource was updated.
71+
- name: 'labels'
72+
type: KeyValueLabels
73+
description: |
74+
User-defined labels.
75+
- name: 'etag'
76+
type: Fingerprint
77+
description: |
78+
The etag is computed by the server, and might be sent with update and
79+
delete requests so that the client has an up-to-date value before
80+
proceeding.
81+
- name: 'description'
82+
type: String
83+
description: |
84+
A description of this resource.
85+
- name: 'destinationsCount'
86+
type: Integer
87+
output: true
88+
description: |
89+
The number of Destination resources configured for the
90+
MulticloudDataTransferConfig resource.
91+
- name: 'destinationsActiveCount'
92+
type: Integer
93+
output: true
94+
description: |
95+
The number of Destination resources in use with the
96+
MulticloudDataTransferConfig resource.
97+
- name: 'services'
98+
type: Array
99+
description: |
100+
Maps services to their current or planned states. Service names are keys,
101+
and the associated values describe the state of the service.
102+
custom_flatten: 'templates/terraform/custom_flatten/network_connectivity_mcdt_services_state_timeline_flatten.go.tmpl'
103+
custom_expand: 'templates/terraform/custom_expand/network_connectivity_mcdt_services_state_timeline_expand.go.tmpl'
104+
item_type:
105+
type: NestedObject
106+
properties:
107+
- name: 'service_name'
108+
type: String
109+
description: |
110+
The name of the service, like "big-query" or "cloud-storage".
111+
This corresponds to the map key in the API.
112+
required: true
113+
- name: 'states'
114+
type: Array
115+
description: 'The state and activation time details for the service.'
116+
output: true
117+
item_type:
118+
type: NestedObject
119+
properties:
120+
- name: 'state'
121+
type: String
122+
description: 'The state of the resource.'
123+
output: true
124+
- name: 'effective_time'
125+
type: String
126+
description: 'The time when the state becomes effective'
127+
output: true
128+
- name: 'uid'
129+
type: String
130+
output: true
131+
description: |
132+
The Google-generated unique ID for the MulticloudDataTransferConfig
133+
resource. This value is unique across all MulticloudDataTransferConfig
134+
resources. If a resource is deleted and another with the same name is
135+
created, the new resource is assigned a different and unique ID.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2024 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
func expand{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
14+
if v == nil {
15+
return make(map[string]interface{}), nil
16+
}
17+
18+
l, ok := v.([]interface{})
19+
if !ok {
20+
return nil, fmt.Errorf("expected 'services' to be a list, got %T", v)
21+
}
22+
23+
req := make(map[string]interface{})
24+
for _, raw := range l {
25+
if raw == nil {
26+
continue
27+
}
28+
29+
original, ok := raw.(map[string]interface{})
30+
if !ok {
31+
return nil, fmt.Errorf("expected a service item to be a map, got %T", raw)
32+
}
33+
34+
serviceName, ok := original["service_name"].(string)
35+
if !ok || serviceName == "" {
36+
// Skip items without a valid service name
37+
continue
38+
}
39+
40+
var apiStates []interface{}
41+
if states, ok := original["states"].([]interface{}); ok {
42+
for _, stateRaw := range states {
43+
state, ok := stateRaw.(map[string]interface{})
44+
if !ok {
45+
continue
46+
}
47+
48+
apiState := make(map[string]interface{})
49+
if s, ok := state["state"].(string); ok {
50+
apiState["state"] = s
51+
}
52+
if et, ok := state["effective_time"].(string); ok {
53+
apiState["effectiveTime"] = et
54+
}
55+
apiStates = append(apiStates, apiState)
56+
}
57+
}
58+
59+
req[serviceName] = map[string]interface{}{
60+
"states": apiStates,
61+
}
62+
}
63+
64+
return req, nil
65+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{{/*
2+
The license inside this block applies to this file
3+
Copyright 2024 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/ -}}
13+
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
14+
if v == nil {
15+
return nil
16+
}
17+
18+
servicesMap, ok := v.(map[string]interface{})
19+
if !ok {
20+
return nil
21+
}
22+
23+
transformed := make([]interface{}, 0, len(servicesMap))
24+
25+
// Sort the service names to ensure a consistent ordering.
26+
serviceNames := make([]string, 0, len(servicesMap))
27+
for name := range servicesMap {
28+
serviceNames = append(serviceNames, name)
29+
}
30+
sort.Strings(serviceNames)
31+
32+
for _, serviceName := range serviceNames {
33+
stateTimelineRaw := servicesMap[serviceName]
34+
stateTimeline, ok := stateTimelineRaw.(map[string]interface{})
35+
if !ok {
36+
continue
37+
}
38+
39+
var flattenedStates []interface{}
40+
if states, ok := stateTimeline["states"].([]interface{}); ok {
41+
for _, stateRaw := range states {
42+
state, ok := stateRaw.(map[string]interface{})
43+
if !ok {
44+
continue
45+
}
46+
flattenedState := make(map[string]interface{})
47+
if s, ok := state["state"].(string); ok {
48+
flattenedState["state"] = s
49+
}
50+
if et, ok := state["effectiveTime"].(string); ok {
51+
flattenedState["effective_time"] = et
52+
}
53+
flattenedStates = append(flattenedStates, flattenedState)
54+
}
55+
}
56+
57+
flattenedService := map[string]interface{}{
58+
"service_name": serviceName,
59+
"states": flattenedStates,
60+
}
61+
transformed = append(transformed, flattenedService)
62+
}
63+
64+
return transformed
65+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resource "google_network_connectivity_multicloud_data_transfer_config" "{{$.PrimaryResourceId}}" {
2+
name = "{{index $.Vars "config_name"}}"
3+
location = "europe-west1"
4+
description = "A basic multicloud data transfer configs"
5+
labels = {
6+
foo = "bar"
7+
}
8+
services {
9+
service_name = "big-query"
10+
}
11+
services {
12+
service_name = "cloud-storage"
13+
}
14+
}

0 commit comments

Comments
 (0)