diff --git a/mmv1/products/cloudquotas/product.yaml b/mmv1/products/cloudquotas/product.yaml new file mode 100644 index 000000000000..53c82344b0d2 --- /dev/null +++ b/mmv1/products/cloudquotas/product.yaml @@ -0,0 +1,22 @@ +# 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. + +--- !ruby/object:Api::Product +name: CloudQuotas +display_name: Cloud Quotas +versions: + - !ruby/object:Api::Product::Version + name: ga + base_url: https://cloudquotas.googleapis.com/v1/ +scopes: + - https://www.googleapis.com/auth/cloud-platform diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt index 443987885a6f..e8beb038983d 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_beta.kt @@ -178,6 +178,11 @@ var ServicesListBeta = mapOf( "displayName" to "Cloudids", "path" to "./google-beta/services/cloudids" ), + "cloudquotas" to mapOf( + "name" to "cloudquotas", + "displayName" to "Cloudquotas", + "path" to "./google-beta/services/cloudquotas" + ), "cloudrun" to mapOf( "name" to "cloudrun", "displayName" to "Cloudrun", @@ -693,4 +698,4 @@ var ServicesListBeta = mapOf( "displayName" to "Workstations", "path" to "./google-beta/services/workstations" ) -) \ No newline at end of file +) diff --git a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt index 08ce6c2ee82f..071ea16ec879 100644 --- a/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt +++ b/mmv1/third_party/terraform/.teamcity/components/inputs/services_ga.kt @@ -178,6 +178,11 @@ var ServicesListGa = mapOf( "displayName" to "Cloudids", "path" to "./google/services/cloudids" ), + "cloudquotas" to mapOf( + "name" to "cloudquotas", + "displayName" to "Cloudquotas", + "path" to "./google/services/cloudquotas" + ), "cloudrun" to mapOf( "name" to "cloudrun", "displayName" to "Cloudrun", @@ -688,4 +693,4 @@ var ServicesListGa = mapOf( "displayName" to "Workstations", "path" to "./google/services/workstations" ) -) \ No newline at end of file +) diff --git a/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb b/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb index cf84c8032b16..f58f2b57e660 100644 --- a/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb +++ b/mmv1/third_party/terraform/provider/provider_mmv1_resources.go.erb @@ -15,6 +15,9 @@ import ( "github.com/hashicorp/terraform-provider-google/google/services/dataflow" "github.com/hashicorp/terraform-provider-google/google/services/servicenetworking" "github.com/hashicorp/terraform-provider-google/google/tpgiamresource" + <% if version == 'ga' -%> // https://github.com/hashicorp/terraform-provider-google/issues/15633 for details + "github.com/hashicorp/terraform-provider-google/google/services/cloudquotas" + <% end -%> ) // Datasources @@ -49,6 +52,7 @@ var handwrittenDatasources = map[string]*schema.Resource{ "google_cloud_identity_groups": cloudidentity.DataSourceGoogleCloudIdentityGroups(), "google_cloud_identity_group_memberships": cloudidentity.DataSourceGoogleCloudIdentityGroupMemberships(), "google_cloud_identity_group_lookup": cloudidentity.DataSourceGoogleCloudIdentityGroupLookup(), + "google_cloud_quotas_quota_info": cloudquotas.DataSourceGoogleCloudQuotasQuotaInfo(), "google_cloud_run_locations": cloudrun.DataSourceGoogleCloudRunLocations(), "google_cloud_run_service": cloudrun.DataSourceGoogleCloudRunService(), "google_cloud_run_v2_job": cloudrunv2.DataSourceGoogleCloudRunV2Job(), diff --git a/mmv1/third_party/terraform/services/cloudquotas/data_source_google_cloud_quotas_quota_info.go b/mmv1/third_party/terraform/services/cloudquotas/data_source_google_cloud_quotas_quota_info.go new file mode 100644 index 000000000000..e2ac85a5a99e --- /dev/null +++ b/mmv1/third_party/terraform/services/cloudquotas/data_source_google_cloud_quotas_quota_info.go @@ -0,0 +1,247 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package cloudquotas + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-google/google/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport" +) + +func DataSourceGoogleCloudQuotasQuotaInfo() *schema.Resource { + return &schema.Resource{ + Read: dataSourceGoogleCloudQuotasQuotaInfoRead, + + Schema: map[string]*schema.Schema{ + "parent": { + Type: schema.TypeString, + Required: true, + }, + "service": { + Type: schema.TypeString, + Required: true, + }, + "quota_id": { + Type: schema.TypeString, + Required: true, + }, + "name": { + Type: schema.TypeString, + Computed: true, + }, + "metric": { + Type: schema.TypeString, + Computed: true, + }, + "is_precise": { + Type: schema.TypeBool, + Computed: true, + }, + "refresh_interval": { + Type: schema.TypeString, + Computed: true, + }, + "container_type": { + Type: schema.TypeString, + Computed: true, + }, + "dimensions": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "metric_display_name": { + Type: schema.TypeString, + Computed: true, + }, + "quota_display_name": { + Type: schema.TypeString, + Computed: true, + }, + "metric_unit": { + Type: schema.TypeString, + Computed: true, + }, + "quota_increase_eligibility": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "is_eligible": { + Type: schema.TypeBool, + Computed: true, + }, + "ineligibility_reason": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "is_fixed": { + Type: schema.TypeBool, + Computed: true, + }, + "dimensions_infos": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "dimensions": { + Type: schema.TypeMap, + Computed: true, + }, + "details": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "value": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + "applicable_locations": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + }, + }, + "is_concurrent": { + Type: schema.TypeBool, + Computed: true, + }, + "service_request_quota_uri": { + Type: schema.TypeString, + Computed: true, + }, + }, + UseJSONNumber: true, + } +} + +func dataSourceGoogleCloudQuotasQuotaInfoRead(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/services/{{service}}/quotaInfos/{{quota_id}}") + if err != nil { + return fmt.Errorf("error setting api endpoint") + } + + res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "GET", + RawURL: url, + UserAgent: userAgent, + }) + + if err != nil { + return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("CloudQuotasQuotaInfo %q", d.Id())) + } + + if err := d.Set("name", res["name"]); err != nil { + return fmt.Errorf("error reading QuotaInfo name: %s", err) + } + if err := d.Set("quota_id", res["quotaId"]); err != nil { + return fmt.Errorf("error reading QuotaInfo quota_id: %s", err) + } + if err := d.Set("metric", res["metric"]); err != nil { + return fmt.Errorf("error reading QuotaInfo metric: %s", err) + } + if err := d.Set("service", res["service"]); err != nil { + return fmt.Errorf("error reading QuotaInfo service: %s", err) + } + if err := d.Set("is_precise", res["isPrecise"]); err != nil { + return fmt.Errorf("error reading QuotaInfo is_precise: %s", err) + } + if err := d.Set("refresh_interval", res["refreshInterval"]); err != nil { + return fmt.Errorf("error reading QuotaInfo refresh_interval: %s", err) + } + if err := d.Set("container_type", res["containerType"]); err != nil { + return fmt.Errorf("error reading QuotaInfo container_type: %s", err) + } + if err := d.Set("dimensions", res["dimensions"]); err != nil { + return fmt.Errorf("error reading QuotaInfo dimensions: %s", err) + } + if err := d.Set("metric_display_name", res["metricDisplayName"]); err != nil { + return fmt.Errorf("error reading QuotaInfo metric_display_name: %s", err) + } + if err := d.Set("quota_display_name", res["quotaDisplayName"]); err != nil { + return fmt.Errorf("error reading QuotaInfo quota_display_name: %s", err) + } + if err := d.Set("metric_unit", res["metricUnit"]); err != nil { + return fmt.Errorf("error reading QuotaInfo metric_unit: %s", err) + } + if err := d.Set("quota_increase_eligibility", flattenCloudQuotasQuotaInfoQuotaIncreaseEligibility(res["quotaIncreaseEligibility"], d, config)); err != nil { + return fmt.Errorf("error reading QuotaInfo quota_increase_eligibility: %s", err) + } + if err := d.Set("is_fixed", res["isFixed"]); err != nil { + return fmt.Errorf("error reading QuotaInfo is_fixed: %s", err) + } + if err := d.Set("dimensions_infos", flattenCloudQuotasQuotaInfoDimensionsInfos(res["dimensionsInfos"], d, config)); err != nil { + return fmt.Errorf("error reading QuotaInfo dimensions_infos: %s", err) + } + if err := d.Set("is_concurrent", res["isConcurrent"]); err != nil { + return fmt.Errorf("error reading QuotaInfo is_concurrent: %s", err) + } + if err := d.Set("service_request_quota_uri", res["serviceRequestQuotaUri"]); err != nil { + return fmt.Errorf("error reading QuotaInfo service_request_quota_uri: %s", err) + } + + d.SetId(res["name"].(string)) + return nil +} + +func flattenCloudQuotasQuotaInfoQuotaIncreaseEligibility(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return nil + } + original := v.(map[string]interface{}) + if len(original) == 0 { + return nil + } + transformed := make(map[string]interface{}) + transformed["is_eligible"] = original["is_eligible"] + transformed["ineligibility_reason"] = original["ineligibility_reason"] + return []interface{}{transformed} +} + +func flattenCloudQuotasQuotaInfoDimensionsInfos(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) []interface{} { + if v == nil { + return make([]interface{}, 0) + } + + original := v.([]interface{}) + dimensionsInfos := make([]interface{}, 0, len(original)) + + for _, raw := range original { + data := make(map[string]interface{}) + data["details"] = flattenCloudQuotasQuotaInfoDetails(raw.(map[string]interface{})["details"], d, config) + data["applicable_locations"] = raw.(map[string]interface{})["applicableLocations"] + data["dimensions"] = raw.(map[string]interface{})["dimensions"] + + dimensionsInfos = append(dimensionsInfos, data) + } + return dimensionsInfos +} + +func flattenCloudQuotasQuotaInfoDetails(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + original, ok := v.(map[string]interface{}) + if !ok || len(original) == 0 { + return nil + } + + return []interface{}{ + map[string]interface{}{"value": original["value"]}, + } +} diff --git a/mmv1/third_party/terraform/services/cloudquotas/data_source_google_cloud_quotas_quota_info_test.go b/mmv1/third_party/terraform/services/cloudquotas/data_source_google_cloud_quotas_quota_info_test.go new file mode 100644 index 000000000000..9a4ff979b47d --- /dev/null +++ b/mmv1/third_party/terraform/services/cloudquotas/data_source_google_cloud_quotas_quota_info_test.go @@ -0,0 +1,61 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 +package cloudquotas_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/envvar" +) + +func TestAccDataSourceGoogleQuotaInfo_basic(t *testing.T) { + t.Parallel() + + resourceName := "data.google_cloud_quotas_quota_info.my_quota_info" + service := "compute.googleapis.com" + quotaId := "CPUS-per-project-region" + + context := map[string]interface{}{ + "project": envvar.GetTestProjectFromEnv(), + "service": service, + "quota_id": quotaId, + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccDataSourceGoogleQuotaInfo_basic(context), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(resourceName, "name"), + resource.TestCheckResourceAttr(resourceName, "quota_id", quotaId), + resource.TestCheckResourceAttr(resourceName, "metric", "compute.googleapis.com/cpus"), + resource.TestCheckResourceAttr(resourceName, "service", service), + resource.TestCheckResourceAttrSet(resourceName, "is_precise"), + resource.TestCheckResourceAttr(resourceName, "container_type", "PROJECT"), + resource.TestCheckResourceAttr(resourceName, "dimensions.0", "region"), + resource.TestCheckResourceAttr(resourceName, "metric_display_name", "CPUs"), + resource.TestCheckResourceAttr(resourceName, "quota_display_name", "CPUs"), + resource.TestCheckResourceAttrSet(resourceName, "metric_unit"), + resource.TestCheckResourceAttrSet(resourceName, "quota_increase_eligibility.0.is_eligible"), + resource.TestCheckResourceAttrSet(resourceName, "dimensions_infos.0.dimensions.region"), + resource.TestCheckResourceAttrSet(resourceName, "dimensions_infos.0.details.0.value"), + resource.TestCheckResourceAttrSet(resourceName, "dimensions_infos.0.applicable_locations.0"), + ), + }, + }, + }) +} + +func testAccDataSourceGoogleQuotaInfo_basic(context map[string]interface{}) string { + return acctest.Nprintf(` + data "google_cloud_quotas_quota_info" "my_quota_info" { + parent = "projects/%{project}" + quota_id = "%{quota_id}" + service = "%{service}" + } + `, context) +} diff --git a/mmv1/third_party/terraform/website/docs/d/cloud_quotas_quota_info.html.markdown b/mmv1/third_party/terraform/website/docs/d/cloud_quotas_quota_info.html.markdown new file mode 100644 index 000000000000..77e97d36489c --- /dev/null +++ b/mmv1/third_party/terraform/website/docs/d/cloud_quotas_quota_info.html.markdown @@ -0,0 +1,61 @@ +--- +subcategory: "Cloud Quotas" +--- + +# google\_cloud\_quotas\_quota\_info + +Provides information about a particular quota for a given project, folder or organization. + +## Example Usage + +```hcl +data "google_cloud_quotas_quota_info" "my_quota_info" { + parent = "projects/my-project" + service = "compute.googleapis.com" + quota_id = "CPUS-per-project-region" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `parent` - (Required) The parent of the quota info. Allowed parents are "projects/[project-id / number]" or "folders/[folder-id / number]" or "organizations/[org-id / number]. + +* `quota_id` - (Required) The id of the quota, which is unique within the service. + +* `service` - (Required) The name of the service in which the quota is defined. + +## Attributes Reference + +The following attributes are exported: + +* `name` - (Output) Resource name of this QuotaInfo, for example: `projects/123/locations/global/services/compute.googleapis.com/quotaInfos/CpusPerProjectPerRegion`. +* `metric` - (Output) The metric of the quota. It specifies the resources consumption the quota is defined for, for example: `compute.googleapis.com/cpus`. +* `is_precise` - (Output) Whether this is a precise quota. A precise quota is tracked with absolute precision. In contrast, an imprecise quota is not tracked with precision. +* `refresh_interval` - (Output) The reset time interval for the quota. Refresh interval applies to rate quota only. Example: "minute" for per minute, "day" for per day, or "10 seconds" for every 10 seconds. +* `container_type` - (Output) The container type of the QuotaInfo. +* `dimensions` - (Output) The dimensions the quota is defined on. +* `metric_display_name` - (Output) The display name of the quota metric. +* `quota_display_name` - (Output) The display name of the quota. +* `metric_unit` - (Output) The unit in which the metric value is reported, e.g., `MByte`. +* `quota_increase_eligibility` - (Output) Whether it is eligible to request a higher quota value for this quota. +* `is_fixed` - (Output) Whether the quota value is fixed or adjustable. +* `dimensions_infos` - (Output) The collection of dimensions info ordered by their dimensions from more specific ones to less specific ones. +* `is_concurrent` - (Output) Whether the quota is a concurrent quota. Concurrent quotas are enforced on the total number of concurrent operations in flight at any given time. +* `service_request_quota_uri` - (Output) URI to the page where users can request more quota for the cloud service, for example: `https://console.cloud.google.com/iam-admin/quotas`. + + The `quota_increase_eligibility` block supports: + +* `is_eligible` - Whether a higher quota value can be requested for the quota. +* `ineligibility_reason` - The enumeration of reasons when it is ineligible to request increase adjustment. + + The `dimensions_infos` block supports: +* `dimensions` - The map of dimensions for this dimensions info. The key of a map entry is "region", "zone" or the name of a service specific dimension, and the value of a map entry is the value of the dimension. If a dimension does not appear in the map of dimensions, the dimensions info applies to all the dimension values except for those that have another DimenisonInfo instance configured for the specific value. Example: {"provider" : "Foo Inc"} where "provider" is a service specific dimension of a quota. + + An object containing a list of "key": value pairs, for example: `{ "name": "wrench", "mass": "1.3kg", "count": "3" }`. +* `details` - The quota details for a map of dimensions. +* `applicable_locations` - The applicable regions or zones of this dimensions info. The field will be set to `['global']` for quotas that are not per region or per zone. Otherwise, it will be set to the list of locations this dimension info is applicable to. + + The `details` block supports: +* `value` - The value currently in effect and being enforced.