Skip to content

Add new resource Quota Adjuster Settings Manager for Cloud Quotas beta #12359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions mmv1/products/cloudquotas/QuotaAdjusterSettings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# 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.

---
name: 'QuotaAdjusterSettings'
description: |
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.
min_version: beta
references:
guides:
'Cloud Quotas Overview': 'https://cloud.google.com/docs/quotas/overview'
api: 'https://cloud.google.com/docs/quotas/reference/rest/v1beta/projects.locations.quotaAdjusterSettings'
docs:
id_format: '{{parent}}/locations/global/quotaAdjusterSettings'
base_url: '{{parent}}/locations/global/quotaAdjusterSettings'
self_link: '{{parent}}/locations/global/quotaAdjusterSettings'
create_url: '{{parent}}/locations/global/quotaAdjusterSettings'
# This is a singleton resource that is already created, so create
# is really an update, and therefore should be PATCHed.
create_verb: 'PATCH'
update_url: '{{parent}}/locations/global/quotaAdjusterSettings'
update_verb: 'PATCH'
# This is a singleton resource that cannot be deleted, so skip delete.
exclude_delete: true
import_format:
- '{{%parent}}/locations/global/quotaAdjusterSettings'
timeouts:
insert_minutes: 20
update_minutes: 20
delete_minutes: 20
custom_code:
examples:
- name: 'cloudquotas_quota_adjuster_settings_basic'
primary_resource_id: 'adjuster_settings'
vars:
parent: "projects/104740170505"
enablement: "ENABLED"
exclude_test: true
parameters:
- name: 'parent'
type: String
description: The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]".
url_param_only: true
required: true
immutable: true
default_from_api: true
validation:
regex: '^(projects|folders|organizations)/([^/]+)$'
properties:
- name: 'enablement'
type: Enum
description: |
Required. The configured value of the enablement at the given resource.
required: true
enum_values:
- 'ENABLED'
- 'DISABLED'
- name: 'effectiveContainer'
type: String
description: |
Fields to capture the hierarchy enablement.
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.
The nearest ancestor (including this container) with `enabled` set (either true or false) will be returned.
output: true
- name: 'effectiveEnablement'
type: Enum
description: |
Based on the effective container`s setting above, determines Whether this container has the quota adjuster enabled.
output: true
enum_values:
- 'DEFAULT'
- 'ENABLED'
- 'DISABLED'
2 changes: 2 additions & 0 deletions mmv1/products/cloudquotas/product.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ display_name: 'Cloud Quotas'
versions:
- name: 'ga'
base_url: 'https://cloudquotas.googleapis.com/v1/'
- name: 'beta'
base_url: 'https://cloudquotas.googleapis.com/v1beta/'
scopes:
- 'https://www.googleapis.com/auth/cloud-platform'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "google_cloud_quotas_quota_adjuster_settings" "{{$.PrimaryResourceId}}" {
provider = google-beta
parent = "{{index $.Vars "parent"}}"
enablement = "{{index $.Vars "enablement"}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package cloudquotas_test

{{- if ne $.TargetVersionName "ga" }}

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"

"github.com/hashicorp/terraform-provider-google/google/acctest"
"github.com/hashicorp/terraform-provider-google/google/envvar"
)


func TestAccCloudQuotasQuotaAdjusterSettings_cloudQuotasQuotaAdjusterSettingsUpdate(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"enablement": "ENABLED",
"org_id": envvar.GetTestOrgFromEnv(t),
"billing_account": envvar.GetTestBillingAccountFromEnv(t),
"updated_enablement": "DISABLED",
"random_suffix": acctest.RandString(t, 10),
}

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
Steps: []resource.TestStep{
{
Config: testAccCloudQuotasQuotaAdjusterSettings_basic(context),
},
{
ResourceName: "google_cloud_quotas_quota_adjuster_settings.adjuster_settings",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
},
{
Config: testAccCloudQuotasQuotaAdjusterSettings_updateEnabelement(context),
},
{
ResourceName: "google_cloud_quotas_quota_adjuster_settings.adjuster_settings",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"parent"},
},
},
})
}

func testAccCloudQuotasQuotaAdjusterSettings_basic(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_project" "project" {
provider = google-beta
}

resource "google_project_service" "cloudquotas" {
provider = google-beta
project = data.google_project.project.project_id
service = "cloudquotas.googleapis.com"
}

resource "google_cloud_quotas_quota_adjuster_settings" "adjuster_settings" {
provider = google-beta
parent = "projects/${data.google_project.project.number}"
enablement = "%{enablement}"
depends_on = [google_project_service.cloudquotas]
}
`, context)
}

func testAccCloudQuotasQuotaAdjusterSettings_updateEnabelement(context map[string]interface{}) string {
return acctest.Nprintf(`
data "google_project" "project" {
provider = google-beta
}

resource "google_project_service" "cloudquotas" {
provider = google-beta
project = data.google_project.project.project_id
service = "cloudquotas.googleapis.com"
}

resource "google_cloud_quotas_quota_adjuster_settings" "adjuster_settings" {
provider = google-beta
parent = "projects/${data.google_project.project.number}"
enablement = "%{updated_enablement}"
depends_on = [google_project_service.cloudquotas]
}
`, context)
}

{{- end }}
Loading