Skip to content

Commit d359eb8

Browse files
committed
Add storage_project_management_hub resource.
1 parent cb117a3 commit d359eb8

File tree

6 files changed

+436
-0
lines changed

6 files changed

+436
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
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+
# API resource name
16+
name: 'ProjectManagementHub'
17+
kind: 'storage#managementhub'
18+
# Resource description for the provider documentation.
19+
description: |
20+
RESOURCE_DESCRIPTION
21+
references:
22+
guides:
23+
# Link to quickstart in the API's Guides section. For example:
24+
# 'Create and connect to a database': 'https://cloud.google.com/alloydb/docs/quickstart/create-and-connect'
25+
'QUICKSTART_TITLE': 'QUICKSTART_URL'
26+
# Link to the REST API reference for the resource. For example,
27+
# https://cloud.google.com/alloydb/docs/reference/rest/v1/projects.locations.backups
28+
api: 'API_REFERENCE_URL'
29+
# Marks the resource as beta-only. Ensure a beta version block is present in
30+
# provider.yaml.
31+
# min_version: beta
32+
33+
# URL for the resource's standard Get method. https://google.aip.dev/131
34+
# Terraform field names enclosed in double curly braces are replaced with
35+
# the field values from the resource at runtime.
36+
self_link: 'projects/{{name}}/locations/global/managementHub'
37+
38+
# URL for the resource's standard Create method, including query parameters.
39+
# https://google.aip.dev/133
40+
# Terraform field names enclosed in double curly braces are replaced with
41+
# the field values from the resource at runtime.
42+
custom_code:
43+
pre_create: templates/terraform/constants/storage_management_hub.go.tmpl
44+
pre_delete: templates/terraform/constants/storage_management_hub.go.tmpl
45+
pre_read: templates/terraform/constants/storage_management_hub.go.tmpl
46+
pre_update: templates/terraform/constants/storage_management_hub.go.tmpl
47+
# Overrides the URL for the resource's standard Update method. (If unset, the
48+
# self_link URL is used by default.) https://google.aip.dev/134
49+
# Terraform field names enclosed in double curly braces are replaced with
50+
# the field values from the resource at runtime.
51+
# update_url: 'projects/{{project}}/locations/{{location}}/resourcenames/{{name}}'
52+
# The HTTP verb used to update a resource. Allowed values: :POST, :PUT, :PATCH. Default: :PUT.
53+
update_verb: 'PATCH'
54+
# If true, the resource sets an `updateMask` query parameter listing modified
55+
# fields when updating the resource. If false, it does not.
56+
update_mask: true
57+
58+
create_url: 'projects/{{name}}/locations/global/managementHub?updateMask=editionConfig,filter'
59+
create_verb: 'PATCH'
60+
61+
exclude_delete: true
62+
63+
import_format:
64+
- 'projects/{{name}}/locations/global/managementHub'
65+
66+
# If true, code for handling long-running operations is generated along with
67+
# the resource. If false, that code is not generated.
68+
autogen_async: false
69+
70+
properties:
71+
# Fields go here
72+
- name: 'name'
73+
type: String
74+
required: true
75+
immutable: true
76+
url_param_only: true
77+
description: |
78+
NAME_DESCRIPTION
79+
- name: 'editionConfig'
80+
type: String
81+
required: false
82+
default_from_api: true
83+
- name: 'updateTime'
84+
type: String
85+
output: true
86+
- name: 'filter'
87+
type: NestedObject
88+
description:
89+
properties:
90+
- name: excludedCloudStorageBuckets
91+
type: NestedObject
92+
required: false
93+
conflicts:
94+
- 'filter.0.included_cloud_storage_buckets'
95+
at_least_one_of:
96+
- 'filter.0.included_cloud_storage_buckets'
97+
- 'filter.0.excluded_cloud_storage_buckets'
98+
- 'filter.0.included_cloud_storage_locations'
99+
- 'filter.0.excluded_cloud_storage_locations'
100+
properties:
101+
- name: cloudStorageBuckets
102+
required: true
103+
type: Array
104+
item_type:
105+
type: NestedObject
106+
properties:
107+
- name: bucketId
108+
type: String
109+
- name: bucketIdRegex
110+
type: String
111+
- name: includedCloudStorageBuckets
112+
type: NestedObject
113+
required: false
114+
conflicts:
115+
- 'filter.0.excluded_cloud_storage_buckets'
116+
at_least_one_of:
117+
- 'filter.0.included_cloud_storage_buckets'
118+
- 'filter.0.excluded_cloud_storage_buckets'
119+
- 'filter.0.included_cloud_storage_locations'
120+
- 'filter.0.excluded_cloud_storage_locations'
121+
properties:
122+
- name: cloudStorageBuckets
123+
required: true
124+
type: Array
125+
item_type:
126+
type: NestedObject
127+
properties:
128+
- name: bucketId
129+
type: String
130+
required: false
131+
- name: bucketIdRegex
132+
type: String
133+
required: false
134+
- name: excludedCloudStorageLocations
135+
type: NestedObject
136+
required: false
137+
conflicts:
138+
- 'filter.0.included_cloud_storage_locations'
139+
at_least_one_of:
140+
- 'filter.0.included_cloud_storage_buckets'
141+
- 'filter.0.excluded_cloud_storage_buckets'
142+
- 'filter.0.included_cloud_storage_locations'
143+
- 'filter.0.excluded_cloud_storage_locations'
144+
properties:
145+
- name: locations
146+
type: Array
147+
required: true
148+
item_type:
149+
type: String
150+
- name: includedCloudStorageLocations
151+
type: NestedObject
152+
required: false
153+
conflicts:
154+
- 'filter.0.excluded_cloud_storage_locations'
155+
at_least_one_of:
156+
- 'filter.0.included_cloud_storage_buckets'
157+
- 'filter.0.excluded_cloud_storage_buckets'
158+
- 'filter.0.included_cloud_storage_locations'
159+
- 'filter.0.excluded_cloud_storage_locations'
160+
properties:
161+
- name: locations
162+
type: Array
163+
required: true
164+
item_type:
165+
type: String
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
url = strings.ReplaceAll(url, "storage/v1", "v2")
3+

mmv1/templates/terraform/custom_create/management_hub_custom_create.go.tmpl

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
3+
if err != nil {
4+
return err
5+
}
6+
7+
obj := make(map[string]interface{})
8+
editionConfigProp, err := expandStorageManagementHubEditionConfig(d.Get("edition_config"), d, config)
9+
if err != nil {
10+
return err
11+
} else if v, ok := d.GetOkExists("edition_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(editionConfigProp)) && (ok || !reflect.DeepEqual(v, editionConfigProp)) {
12+
obj["editionConfig"] = editionConfigProp
13+
}
14+
filterProp, err := expandStorageManagementHubFilter(d.Get("filter"), d, config)
15+
if err != nil {
16+
return err
17+
} else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) {
18+
obj["filter"] = filterProp
19+
}
20+
21+
url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}StorageBasePath{{"}}"}}projects/{{"{{"}}name{{"}}"}}/locations/global/managementHub")
22+
if err != nil {
23+
return err
24+
}
25+
26+
log.Printf("[DEBUG] Creating new ManagementHub: %#v", obj)
27+
billingProject := ""
28+
29+
// err == nil indicates that the billing_project value was found
30+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
31+
billingProject = bp
32+
}
33+
34+
headers := make(http.Header)
35+
updateMask := []string{}
36+
37+
if d.HasChange("edition_config") {
38+
updateMask = append(updateMask, "editionConfig")
39+
}
40+
41+
if d.HasChange("filter") {
42+
updateMask = append(updateMask, "filter")
43+
}
44+
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
45+
// won't set it
46+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
47+
if err != nil {
48+
return err
49+
}
50+
51+
url = strings.ReplaceAll(url, "storage/v1", "v2")
52+
53+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
54+
Config: config,
55+
Method: "PATCH",
56+
Project: billingProject,
57+
RawURL: url,
58+
UserAgent: userAgent,
59+
Body: obj,
60+
Timeout: d.Timeout(schema.TimeoutCreate),
61+
Headers: headers,
62+
})
63+
if err != nil {
64+
return fmt.Errorf("Error creating ManagementHub: %s", err)
65+
}
66+
67+
// Store the ID now
68+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{"{{"}}name{{"}}"}}/locations/global/managementHub")
69+
if err != nil {
70+
return fmt.Errorf("Error constructing id: %s", err)
71+
}
72+
d.SetId(id)
73+
74+
log.Printf("[DEBUG] Finished creating ManagementHub %q: %#v", d.Id(), res)
75+
76+
return resourceStorageManagementHubRead(d, meta)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
url = strings.ReplaceAll(url, "storage/v1", "v2")
3+

0 commit comments

Comments
 (0)