-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storage_organization_management_hub resource.
- Loading branch information
Showing
3 changed files
with
487 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,225 @@ | ||
# Copyright 2024 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- | ||
# API resource name | ||
name: 'OrganizationManagementHub' | ||
kind: 'storage#managementhub' | ||
# Resource description for the provider documentation. | ||
description: | | ||
The Project Management Hub resource represents GCS Management Hub operating on | ||
individual GCP project. Management Hub is a singleton resource and individual | ||
instance exists on each GCP project. | ||
Management Hub is for Storage Admins to manage GCP storage assets at scale for | ||
performance, cost, security & compliance. | ||
docs: | ||
warning: | | ||
Management Hub is a singleton resource which cannot be created or | ||
deleted. A single instance of Management Hub exist for each GCP Project. | ||
Terraform does not create or destroy this resource. Terraform resource | ||
creation for this resource is simply an update operation on existing | ||
resource with specified properties. Terraform deletion won't have any effect | ||
on this resource rather it will only remove it from the state file. | ||
# Marks the resource as beta-only. Ensure a beta version block is present in | ||
# provider.yaml. | ||
# min_version: beta | ||
|
||
# URL for the resource's standard Get method. https://google.aip.dev/131 | ||
# Terraform field names enclosed in double curly braces are replaced with | ||
# the field values from the resource at runtime. | ||
self_link: 'organizations/{{name}}/locations/global/managementHub' | ||
|
||
# URL for the resource's standard Create method, including query parameters. | ||
# https://google.aip.dev/133 | ||
# Terraform field names enclosed in double curly braces are replaced with | ||
# the field values from the resource at runtime. | ||
custom_code: | ||
pre_delete: templates/terraform/constants/storage_management_hub.go.tmpl | ||
pre_read: templates/terraform/constants/storage_management_hub.go.tmpl | ||
pre_update: templates/terraform/constants/storage_management_hub.go.tmpl | ||
custom_create: templates/terraform/custom_create/storage_organization_management_hub.go.tmpl | ||
# Overrides the URL for the resource's standard Update method. (If unset, the | ||
# self_link URL is used by default.) https://google.aip.dev/134 | ||
# Terraform field names enclosed in double curly braces are replaced with | ||
# the field values from the resource at runtime. | ||
# update_url: 'projects/{{project}}/locations/{{location}}/resourcenames/{{name}}' | ||
# The HTTP verb used to update a resource. Allowed values: :POST, :PUT, :PATCH. Default: :PUT. | ||
update_verb: 'PATCH' | ||
# If true, the resource sets an `updateMask` query parameter listing modified | ||
# fields when updating the resource. If false, it does not. | ||
update_mask: true | ||
|
||
create_url: 'organizations/{{name}}/locations/global/managementHub?updateMask=editionConfig,filter' | ||
create_verb: 'PATCH' | ||
|
||
exclude_delete: true | ||
|
||
import_format: | ||
- 'organizations/{{name}}/locations/global/managementHub' | ||
|
||
# If true, code for handling long-running operations is generated along with | ||
# the resource. If false, that code is not generated. | ||
autogen_async: false | ||
|
||
properties: | ||
# Fields go here | ||
- name: 'name' | ||
type: String | ||
required: true | ||
immutable: true | ||
url_param_only: true | ||
description: | | ||
Identifier of the GCP Organization. For GCP org, It should be | ||
organization number. | ||
- name: 'editionConfig' | ||
type: String | ||
required: false | ||
default_from_api: true | ||
description: | | ||
Edition configuration of the Management Hub resource. Valid values are | ||
INHERIT, DISABLED and STANDARD. | ||
- name: 'updateTime' | ||
type: String | ||
output: true | ||
description: | | ||
The time at which the Management Hub resource is last updated. | ||
- name: 'filter' | ||
type: NestedObject | ||
description: | | ||
Filter over location and bucket using include or exclude semantics. | ||
Resources that match the include or exclude filter are exclusively | ||
included or excluded from the Management Hub plan. | ||
properties: | ||
- name: excludedCloudStorageBuckets | ||
type: NestedObject | ||
required: false | ||
description: | | ||
Buckets to exclude from the Management Hub plan. | ||
conflicts: | ||
- 'filter.0.included_cloud_storage_buckets' | ||
at_least_one_of: | ||
- 'filter.0.included_cloud_storage_buckets' | ||
- 'filter.0.excluded_cloud_storage_buckets' | ||
- 'filter.0.included_cloud_storage_locations' | ||
- 'filter.0.excluded_cloud_storage_locations' | ||
properties: | ||
- name: cloudStorageBuckets | ||
required: true | ||
type: Array | ||
item_type: | ||
type: NestedObject | ||
properties: | ||
- name: bucketId | ||
type: String | ||
description: | | ||
Id of the bucket. | ||
Only one of the bucket_id and bucket_id_regex should be | ||
specified. | ||
- name: bucketIdRegex | ||
type: String | ||
description: | | ||
ID regex of the bucket. | ||
Only one of the bucket_id and bucket_id_regex should be | ||
specified. | ||
- name: includedCloudStorageBuckets | ||
type: NestedObject | ||
required: false | ||
description: | | ||
Buckets to include in the Management Hub plan. | ||
conflicts: | ||
- 'filter.0.excluded_cloud_storage_buckets' | ||
at_least_one_of: | ||
- 'filter.0.included_cloud_storage_buckets' | ||
- 'filter.0.excluded_cloud_storage_buckets' | ||
- 'filter.0.included_cloud_storage_locations' | ||
- 'filter.0.excluded_cloud_storage_locations' | ||
properties: | ||
- name: cloudStorageBuckets | ||
required: true | ||
type: Array | ||
item_type: | ||
type: NestedObject | ||
properties: | ||
- name: bucketId | ||
type: String | ||
required: false | ||
description: | | ||
Id of the bucket. | ||
Only one of the bucket_id and bucket_id_regex should be | ||
specified. | ||
- name: bucketIdRegex | ||
type: String | ||
required: false | ||
description: | | ||
ID regex of the bucket. | ||
Only one of the bucket_id and bucket_id_regex should be | ||
specified. | ||
- name: excludedCloudStorageLocations | ||
type: NestedObject | ||
required: false | ||
description: | | ||
Locations to exclude from the Management Hub plan. | ||
conflicts: | ||
- 'filter.0.included_cloud_storage_locations' | ||
at_least_one_of: | ||
- 'filter.0.included_cloud_storage_buckets' | ||
- 'filter.0.excluded_cloud_storage_buckets' | ||
- 'filter.0.included_cloud_storage_locations' | ||
- 'filter.0.excluded_cloud_storage_locations' | ||
properties: | ||
- name: locations | ||
type: Array | ||
required: true | ||
description: | | ||
List of locations. | ||
item_type: | ||
type: String | ||
- name: includedCloudStorageLocations | ||
type: NestedObject | ||
required: false | ||
description: | | ||
Locations to include in the Management Hub plan. | ||
conflicts: | ||
- 'filter.0.excluded_cloud_storage_locations' | ||
at_least_one_of: | ||
- 'filter.0.included_cloud_storage_buckets' | ||
- 'filter.0.excluded_cloud_storage_buckets' | ||
- 'filter.0.included_cloud_storage_locations' | ||
- 'filter.0.excluded_cloud_storage_locations' | ||
properties: | ||
- name: locations | ||
type: Array | ||
required: true | ||
description: | | ||
List of locations. | ||
item_type: | ||
type: String | ||
- name: 'effectiveManagementHubEdition' | ||
output: true | ||
description: | | ||
The Management Hub edition that is effective for the resource. | ||
type: NestedObject | ||
properties: | ||
- name: managementHub | ||
type: String | ||
output: true | ||
description: | | ||
The Management Hub resource that is applied for the target resource. | ||
- name: managementHubEdition | ||
type: String | ||
output: true | ||
description: | | ||
The `ManagementHub` edition that is applicable for the resource. |
72 changes: 72 additions & 0 deletions
72
mmv1/templates/terraform/custom_create/storage_organization_management_hub.go.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
obj := make(map[string]interface{}) | ||
editionConfigProp, err := expandStorageOrganizationManagementHubEditionConfig(d.Get("edition_config"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("edition_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(editionConfigProp)) && (ok || !reflect.DeepEqual(v, editionConfigProp)) { | ||
obj["editionConfig"] = editionConfigProp | ||
} | ||
filterProp, err := expandStorageOrganizationManagementHubFilter(d.Get("filter"), d, config) | ||
if err != nil { | ||
return err | ||
} else if v, ok := d.GetOkExists("filter"); !tpgresource.IsEmptyValue(reflect.ValueOf(filterProp)) && (ok || !reflect.DeepEqual(v, filterProp)) { | ||
obj["filter"] = filterProp | ||
} | ||
|
||
url, err := tpgresource.ReplaceVars(d, config, "{{"{{"}}StorageBasePath{{"}}"}}organizations/{{"{{"}}name{{"}}"}}/locations/global/managementHub") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Printf("[DEBUG] Patching ManagementHub: %#v", obj) | ||
billingProject := "" | ||
|
||
// err == nil indicates that the billing_project value was found | ||
if bp, err := tpgresource.GetBillingProject(d, config); err == nil { | ||
billingProject = bp | ||
} | ||
|
||
headers := make(http.Header) | ||
updateMask := []string{"filter"} | ||
|
||
if d.HasChange("edition_config") { | ||
updateMask = append(updateMask, "editionConfig") | ||
} | ||
// updateMask is a URL parameter but not present in the schema, so ReplaceVars | ||
// won't set it | ||
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
url = strings.ReplaceAll(url, "storage/v1", "v2") | ||
|
||
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ | ||
Config: config, | ||
Method: "PATCH", | ||
Project: billingProject, | ||
RawURL: url, | ||
UserAgent: userAgent, | ||
Body: obj, | ||
Timeout: d.Timeout(schema.TimeoutCreate), | ||
Headers: headers, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("Error patching ManagementHub: %s", err) | ||
} | ||
|
||
// Store the ID now | ||
id, err := tpgresource.ReplaceVars(d, config, "organizations/{{"{{"}}name{{"}}"}}/locations/global/managementHub") | ||
if err != nil { | ||
return fmt.Errorf("Error constructing id: %s", err) | ||
} | ||
d.SetId(id) | ||
|
||
log.Printf("[DEBUG] Finished patching ManagementHub %q: %#v", d.Id(), res) | ||
|
||
return resourceStorageOrganizationManagementHubRead(d, meta) |
Oops, something went wrong.