diff --git a/.changelog/12359.txt b/.changelog/12359.txt new file mode 100644 index 0000000000..d70c152626 --- /dev/null +++ b/.changelog/12359.txt @@ -0,0 +1,3 @@ +```release-note:new-resource +`google_cloud_quotas_quota_adjuster_settings` +``` \ No newline at end of file diff --git a/google-beta/provider/provider_mmv1_resources.go b/google-beta/provider/provider_mmv1_resources.go index b41918debc..c3c53bf797 100644 --- a/google-beta/provider/provider_mmv1_resources.go +++ b/google-beta/provider/provider_mmv1_resources.go @@ -513,9 +513,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{ } // Resources -// Generated resources: 576 +// Generated resources: 577 // Generated IAM resources: 294 -// Total generated resources: 870 +// Total generated resources: 871 var generatedResources = map[string]*schema.Resource{ "google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(), "google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(), @@ -682,6 +682,7 @@ var generatedResources = map[string]*schema.Resource{ "google_cloud_identity_group": cloudidentity.ResourceCloudIdentityGroup(), "google_cloud_identity_group_membership": cloudidentity.ResourceCloudIdentityGroupMembership(), "google_cloud_ids_endpoint": cloudids.ResourceCloudIdsEndpoint(), + "google_cloud_quotas_quota_adjuster_settings": cloudquotas.ResourceCloudQuotasQuotaAdjusterSettings(), "google_cloud_quotas_quota_preference": cloudquotas.ResourceCloudQuotasQuotaPreference(), "google_cloud_run_domain_mapping": cloudrun.ResourceCloudRunDomainMapping(), "google_cloud_run_service": cloudrun.ResourceCloudRunService(), diff --git a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go new file mode 100644 index 0000000000..f857979582 --- /dev/null +++ b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings.go @@ -0,0 +1,274 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// ---------------------------------------------------------------------------- +// +// *** AUTO GENERATED CODE *** Type: MMv1 *** +// +// ---------------------------------------------------------------------------- +// +// This file is automatically generated by Magic Modules and manual +// changes will be clobbered when the file is regenerated. +// +// Please read more about how to change this file in +// .github/CONTRIBUTING.md. +// +// ---------------------------------------------------------------------------- + +package cloudquotas + +import ( + "fmt" + "log" + "net/http" + "reflect" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/verify" +) + +func ResourceCloudQuotasQuotaAdjusterSettings() *schema.Resource { + return &schema.Resource{ + Create: resourceCloudQuotasQuotaAdjusterSettingsCreate, + Read: resourceCloudQuotasQuotaAdjusterSettingsRead, + Update: resourceCloudQuotasQuotaAdjusterSettingsUpdate, + Delete: resourceCloudQuotasQuotaAdjusterSettingsDelete, + + Importer: &schema.ResourceImporter{ + State: resourceCloudQuotasQuotaAdjusterSettingsImport, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(20 * time.Minute), + Update: schema.DefaultTimeout(20 * time.Minute), + Delete: schema.DefaultTimeout(20 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "enablement": { + Type: schema.TypeString, + Required: true, + ValidateFunc: verify.ValidateEnum([]string{"ENABLED", "DISABLED"}), + Description: `Required. The configured value of the enablement at the given resource. Possible values: ["ENABLED", "DISABLED"]`, + }, + "parent": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + ValidateFunc: verify.ValidateRegexp(`^(projects|folders|organizations)/([^/]+)$`), + Description: `The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]".`, + }, + "effective_container": { + Type: schema.TypeString, + Computed: true, + 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.`, + }, + "effective_enablement": { + Type: schema.TypeString, + Computed: true, + Description: `Based on the effective container's setting above, determines Whether this container has the quota adjuster enabled.`, + }, + }, + UseJSONNumber: true, + } +} + +func resourceCloudQuotasQuotaAdjusterSettingsCreate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + enablementProp, err := expandCloudQuotasQuotaAdjusterSettingsEnablement(d.Get("enablement"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enablement"); !tpgresource.IsEmptyValue(reflect.ValueOf(enablementProp)) && (ok || !reflect.DeepEqual(v, enablementProp)) { + obj["enablement"] = enablementProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{CloudQuotasBasePath}}{{parent}}/locations/global/quotaAdjusterSettings") + if err != nil { + return err + } + + log.Printf("[DEBUG] Creating new QuotaAdjusterSettings: %#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) + 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 creating QuotaAdjusterSettings: %s", err) + } + + // Store the ID now + id, err := tpgresource.ReplaceVars(d, config, "{{parent}}/locations/global/quotaAdjusterSettings") + if err != nil { + return fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + log.Printf("[DEBUG] Finished creating QuotaAdjusterSettings %q: %#v", d.Id(), res) + + return resourceCloudQuotasQuotaAdjusterSettingsRead(d, meta) +} + +func resourceCloudQuotasQuotaAdjusterSettingsRead(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + url, err := tpgresource.ReplaceVars(d, config, "{{CloudQuotasBasePath}}{{parent}}/locations/global/quotaAdjusterSettings") + if err != nil { + return err + } + + 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) + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Headers: headers, + }) + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("CloudQuotasQuotaAdjusterSettings %q", d.Id())) + } + + if err := d.Set("enablement", flattenCloudQuotasQuotaAdjusterSettingsEnablement(res["enablement"], d, config)); err != nil { + return fmt.Errorf("Error reading QuotaAdjusterSettings: %s", err) + } + if err := d.Set("effective_container", flattenCloudQuotasQuotaAdjusterSettingsEffectiveContainer(res["effectiveContainer"], d, config)); err != nil { + return fmt.Errorf("Error reading QuotaAdjusterSettings: %s", err) + } + if err := d.Set("effective_enablement", flattenCloudQuotasQuotaAdjusterSettingsEffectiveEnablement(res["effectiveEnablement"], d, config)); err != nil { + return fmt.Errorf("Error reading QuotaAdjusterSettings: %s", err) + } + + return nil +} + +func resourceCloudQuotasQuotaAdjusterSettingsUpdate(d *schema.ResourceData, meta interface{}) error { + config := meta.(*transport_tpg.Config) + userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) + if err != nil { + return err + } + + billingProject := "" + + obj := make(map[string]interface{}) + enablementProp, err := expandCloudQuotasQuotaAdjusterSettingsEnablement(d.Get("enablement"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("enablement"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enablementProp)) { + obj["enablement"] = enablementProp + } + + url, err := tpgresource.ReplaceVars(d, config, "{{CloudQuotasBasePath}}{{parent}}/locations/global/quotaAdjusterSettings") + if err != nil { + return err + } + + log.Printf("[DEBUG] Updating QuotaAdjusterSettings %q: %#v", d.Id(), obj) + headers := make(http.Header) + + // err == nil indicates that the billing_project value was found + if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "PATCH", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutUpdate), + Headers: headers, + }) + + if err != nil { + return fmt.Errorf("Error updating QuotaAdjusterSettings %q: %s", d.Id(), err) + } else { + log.Printf("[DEBUG] Finished updating QuotaAdjusterSettings %q: %#v", d.Id(), res) + } + + return resourceCloudQuotasQuotaAdjusterSettingsRead(d, meta) +} + +func resourceCloudQuotasQuotaAdjusterSettingsDelete(d *schema.ResourceData, meta interface{}) error { + log.Printf("[WARNING] CloudQuotas QuotaAdjusterSettings resources"+ + " cannot be deleted from Google Cloud. The resource %s will be removed from Terraform"+ + " state, but will still be present on Google Cloud.", d.Id()) + d.SetId("") + + return nil +} + +func resourceCloudQuotasQuotaAdjusterSettingsImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { + config := meta.(*transport_tpg.Config) + if err := tpgresource.ParseImportId([]string{ + "^(?P.+)/locations/global/quotaAdjusterSettings$", + }, d, config); err != nil { + return nil, err + } + + // Replace import id for the resource id + id, err := tpgresource.ReplaceVars(d, config, "{{parent}}/locations/global/quotaAdjusterSettings") + if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) + } + d.SetId(id) + + return []*schema.ResourceData{d}, nil +} + +func flattenCloudQuotasQuotaAdjusterSettingsEnablement(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudQuotasQuotaAdjusterSettingsEffectiveContainer(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenCloudQuotasQuotaAdjusterSettingsEffectiveEnablement(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func expandCloudQuotasQuotaAdjusterSettingsEnablement(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} diff --git a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings_generated_meta.yaml b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings_generated_meta.yaml new file mode 100644 index 0000000000..fb149444a9 --- /dev/null +++ b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings_generated_meta.yaml @@ -0,0 +1,5 @@ +resource: 'google_cloud_quotas_quota_adjuster_settings' +generation_type: 'mmv1' +api_service_name: 'cloudquotas.googleapis.com' +api_version: 'v1beta' +api_resource_type_kind: 'QuotaAdjusterSettings' diff --git a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings_test.go b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings_test.go new file mode 100644 index 0000000000..67a3fc6972 --- /dev/null +++ b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_adjuster_settings_test.go @@ -0,0 +1,91 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package cloudquotas_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/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) +} diff --git a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference_generated_meta.yaml b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference_generated_meta.yaml index ebf61bfa02..e7bdd508ff 100644 --- a/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference_generated_meta.yaml +++ b/google-beta/services/cloudquotas/resource_cloud_quotas_quota_preference_generated_meta.yaml @@ -1,5 +1,5 @@ resource: 'google_cloud_quotas_quota_preference' generation_type: 'mmv1' api_service_name: 'cloudquotas.googleapis.com' -api_version: 'v1' +api_version: 'v1beta' api_resource_type_kind: 'QuotaPreference' diff --git a/google-beta/transport/config.go b/google-beta/transport/config.go index 742d3fc5e7..1fafea4a36 100644 --- a/google-beta/transport/config.go +++ b/google-beta/transport/config.go @@ -543,7 +543,7 @@ var DefaultBasePaths = map[string]string{ Cloudfunctions2BasePathKey: "https://cloudfunctions.googleapis.com/v2beta/", CloudIdentityBasePathKey: "https://cloudidentity.googleapis.com/v1beta1/", CloudIdsBasePathKey: "https://ids.googleapis.com/v1/", - CloudQuotasBasePathKey: "https://cloudquotas.googleapis.com/v1/", + CloudQuotasBasePathKey: "https://cloudquotas.googleapis.com/v1beta/", CloudRunBasePathKey: "https://{{location}}-run.googleapis.com/", CloudRunV2BasePathKey: "https://run.googleapis.com/v2/", CloudSchedulerBasePathKey: "https://cloudscheduler.googleapis.com/v1/", diff --git a/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown b/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown new file mode 100644 index 0000000000..7b10d8a3c8 --- /dev/null +++ b/website/docs/r/cloud_quotas_quota_adjuster_settings.html.markdown @@ -0,0 +1,108 @@ +--- +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in +# .github/CONTRIBUTING.md. +# +# ---------------------------------------------------------------------------- +subcategory: "Cloud Quotas" +description: |- + QuotaAdjusterSettings represents the preferred quota configuration specified for a project, folder or organization. +--- + +# google_cloud_quotas_quota_adjuster_settings + +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. + +~> **Warning:** This resource is in beta, and should be used with the terraform-provider-google-beta provider. +See [Provider Versions](https://terraform.io/docs/providers/google/guides/provider_versions.html) for more details on beta resources. + +To get more information about QuotaAdjusterSettings, see: + +* [API documentation](https://cloud.google.com/docs/quotas/reference/rest/v1beta/projects.locations.quotaAdjusterSettings) +* How-to Guides + * [Cloud Quotas Overview](https://cloud.google.com/docs/quotas/overview) + +## Example Usage - Cloudquotas Quota Adjuster Settings Basic + + +```hcl +resource "google_cloud_quotas_quota_adjuster_settings" "adjuster_settings" { + provider = google-beta + parent = "projects/104740170505" + enablement = "ENABLED" +} +``` + +## Argument Reference + +The following arguments are supported: + + +* `enablement` - + (Required) + Required. The configured value of the enablement at the given resource. + Possible values are: `ENABLED`, `DISABLED`. + +* `parent` - + (Required) + The parent of the quota preference. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]". + + +- - - + + + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `id` - an identifier for the resource with format `{{parent}}/locations/global/quotaAdjusterSettings` + +* `effective_container` - + 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. + +* `effective_enablement` - + Based on the effective container`s setting above, determines Whether this container has the quota adjuster enabled. + + +## Timeouts + +This resource provides the following +[Timeouts](https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/retries-and-customizable-timeouts) configuration options: + +- `create` - Default is 20 minutes. +- `update` - Default is 20 minutes. +- `delete` - Default is 20 minutes. + +## Import + + +QuotaAdjusterSettings can be imported using any of these accepted formats: + +* `{{parent}}/locations/global/quotaAdjusterSettings` + + +In Terraform v1.5.0 and later, use an [`import` block](https://developer.hashicorp.com/terraform/language/import) to import QuotaAdjusterSettings using one of the formats above. For example: + +```tf +import { + id = "{{parent}}/locations/global/quotaAdjusterSettings" + to = google_cloud_quotas_quota_adjuster_settings.default +} +``` + +When using the [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import), QuotaAdjusterSettings can be imported using one of the formats above. For example: + +``` +$ terraform import google_cloud_quotas_quota_adjuster_settings.default {{parent}}/locations/global/quotaAdjusterSettings +```