Skip to content

Commit 0ba8f0f

Browse files
eshagoel06Dave Karwowski
authored and
Dave Karwowski
committed
Add new resource Quota Adjuster Settings Manager for Cloud Quotas beta (GoogleCloudPlatform#12359)
1 parent f813823 commit 0ba8f0f

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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: 'QuotaAdjusterSettings'
16+
description: |
17+
QuotaAdjusterSettings represents the preferred quota configuration specified for a project, folder or organization. There is only one QuotaAdjusterSettings resource for a quota value targeting a unique set of dimensions.
18+
min_version: beta
19+
references:
20+
guides:
21+
'Cloud Quotas Overview': 'https://cloud.google.com/docs/quotas/overview'
22+
api: 'https://cloud.google.com/docs/quotas/reference/rest/v1beta/projects.locations.quotaAdjusterSettings'
23+
docs:
24+
id_format: '{{parent}}/locations/global/quotaAdjusterSettings'
25+
base_url: '{{parent}}/locations/global/quotaAdjusterSettings'
26+
self_link: '{{parent}}/locations/global/quotaAdjusterSettings'
27+
create_url: '{{parent}}/locations/global/quotaAdjusterSettings'
28+
# This is a singleton resource that is already created, so create
29+
# is really an update, and therefore should be PATCHed.
30+
create_verb: 'PATCH'
31+
update_url: '{{parent}}/locations/global/quotaAdjusterSettings'
32+
update_verb: 'PATCH'
33+
# This is a singleton resource that cannot be deleted, so skip delete.
34+
exclude_delete: true
35+
import_format:
36+
- '{{%parent}}/locations/global/quotaAdjusterSettings'
37+
timeouts:
38+
insert_minutes: 20
39+
update_minutes: 20
40+
delete_minutes: 20
41+
custom_code:
42+
examples:
43+
- name: 'cloudquotas_quota_adjuster_settings_basic'
44+
primary_resource_id: 'adjuster_settings'
45+
vars:
46+
parent: "projects/104740170505"
47+
enablement: "ENABLED"
48+
exclude_test: true
49+
parameters:
50+
- name: 'parent'
51+
type: String
52+
description: The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]".
53+
url_param_only: true
54+
required: true
55+
immutable: true
56+
default_from_api: true
57+
validation:
58+
regex: '^(projects|folders|organizations)/([^/]+)$'
59+
properties:
60+
- name: 'enablement'
61+
type: Enum
62+
description: |
63+
Required. The configured value of the enablement at the given resource.
64+
required: true
65+
enum_values:
66+
- 'ENABLED'
67+
- 'DISABLED'
68+
- name: 'effectiveContainer'
69+
type: String
70+
description: |
71+
Fields to capture the hierarchy enablement.
72+
The container (org/folder/project) that determines if the quota adjuster is set for this project/folder/org. We use the nearest-ancestor to determine the effective container.
73+
The nearest ancestor (including this container) with `enabled` set (either true or false) will be returned.
74+
output: true
75+
- name: 'effectiveEnablement'
76+
type: Enum
77+
description: |
78+
Based on the effective container`s setting above, determines Whether this container has the quota adjuster enabled.
79+
output: true
80+
enum_values:
81+
- 'DEFAULT'
82+
- 'ENABLED'
83+
- 'DISABLED'

mmv1/products/cloudquotas/product.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ display_name: 'Cloud Quotas'
1717
versions:
1818
- name: 'ga'
1919
base_url: 'https://cloudquotas.googleapis.com/v1/'
20+
- name: 'beta'
21+
base_url: 'https://cloudquotas.googleapis.com/v1beta/'
2022
scopes:
2123
- 'https://www.googleapis.com/auth/cloud-platform'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "google_cloud_quotas_quota_adjuster_settings" "{{$.PrimaryResourceId}}" {
2+
provider = google-beta
3+
parent = "{{index $.Vars "parent"}}"
4+
enablement = "{{index $.Vars "enablement"}}"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package cloudquotas_test
2+
3+
{{- if ne $.TargetVersionName "ga" }}
4+
5+
import (
6+
"testing"
7+
8+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9+
10+
"github.com/hashicorp/terraform-provider-google/google/acctest"
11+
"github.com/hashicorp/terraform-provider-google/google/envvar"
12+
)
13+
14+
15+
func TestAccCloudQuotasQuotaAdjusterSettings_cloudQuotasQuotaAdjusterSettingsUpdate(t *testing.T) {
16+
t.Parallel()
17+
18+
context := map[string]interface{}{
19+
"enablement": "ENABLED",
20+
"org_id": envvar.GetTestOrgFromEnv(t),
21+
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
22+
"updated_enablement": "DISABLED",
23+
"random_suffix": acctest.RandString(t, 10),
24+
}
25+
26+
acctest.VcrTest(t, resource.TestCase{
27+
PreCheck: func() { acctest.AccTestPreCheck(t) },
28+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
29+
Steps: []resource.TestStep{
30+
{
31+
Config: testAccCloudQuotasQuotaAdjusterSettings_basic(context),
32+
},
33+
{
34+
ResourceName: "google_cloud_quotas_quota_adjuster_settings.adjuster_settings",
35+
ImportState: true,
36+
ImportStateVerify: true,
37+
ImportStateVerifyIgnore: []string{"parent"},
38+
},
39+
{
40+
Config: testAccCloudQuotasQuotaAdjusterSettings_updateEnabelement(context),
41+
},
42+
{
43+
ResourceName: "google_cloud_quotas_quota_adjuster_settings.adjuster_settings",
44+
ImportState: true,
45+
ImportStateVerify: true,
46+
ImportStateVerifyIgnore: []string{"parent"},
47+
},
48+
},
49+
})
50+
}
51+
52+
func testAccCloudQuotasQuotaAdjusterSettings_basic(context map[string]interface{}) string {
53+
return acctest.Nprintf(`
54+
data "google_project" "project" {
55+
provider = google-beta
56+
}
57+
58+
resource "google_project_service" "cloudquotas" {
59+
provider = google-beta
60+
project = data.google_project.project.project_id
61+
service = "cloudquotas.googleapis.com"
62+
}
63+
64+
resource "google_cloud_quotas_quota_adjuster_settings" "adjuster_settings" {
65+
provider = google-beta
66+
parent = "projects/${data.google_project.project.number}"
67+
enablement = "%{enablement}"
68+
depends_on = [google_project_service.cloudquotas]
69+
}
70+
`, context)
71+
}
72+
73+
func testAccCloudQuotasQuotaAdjusterSettings_updateEnabelement(context map[string]interface{}) string {
74+
return acctest.Nprintf(`
75+
data "google_project" "project" {
76+
provider = google-beta
77+
}
78+
79+
resource "google_project_service" "cloudquotas" {
80+
provider = google-beta
81+
project = data.google_project.project.project_id
82+
service = "cloudquotas.googleapis.com"
83+
}
84+
85+
resource "google_cloud_quotas_quota_adjuster_settings" "adjuster_settings" {
86+
provider = google-beta
87+
parent = "projects/${data.google_project.project.number}"
88+
enablement = "%{updated_enablement}"
89+
depends_on = [google_project_service.cloudquotas]
90+
}
91+
`, context)
92+
}
93+
94+
{{- end }}

0 commit comments

Comments
 (0)