Skip to content

Commit

Permalink
Added CloudQuotas service and Create QuotaPreference Resource (#…
Browse files Browse the repository at this point in the history
…10019) (#2077)

* setup resoruce config and add create tests

* add create and update test

* fix lint error

* fix lint error

* update yaml config

* remove trailing spaces

* modify update test

* update acceptance test and cleanup

* add upsert scenario for testing

* update acceptance test syntax

* remove allow-missing flag & fix update test failure

* add import and id format

* teamcity test failure - manually add cloudquotas service

* teamcity test failure - manually add cloudquotas service for beta

* add field 'validate_only' to tests

* address comments & fix test failure

* remove unused import

* remove `validate_only` field, add ignore read feature to `annotations` field

* add input only fields to ImportStateVerifyIgnore

* update field name

* VCR test failure: remove batch service creation

* fix formatting

[upstream:7b41c4afa4f77c38bc1b72ed97bbd8b1aeb22352]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 20, 2024
1 parent 9e302f9 commit 8dd212e
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/terraform-json v0.18.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240320170541-d33fe3788dfb
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240320182510-2b8fc14990c3
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ github.com/hashicorp/terraform-plugin-mux v0.13.0 h1:79U401/3nd8CWwDGtTHc8F3miSC
github.com/hashicorp/terraform-plugin-mux v0.13.0/go.mod h1:Ndv0FtwDG2ogzH59y64f2NYimFJ6I0smRgFUKfm6dyQ=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 h1:Bl3e2ei2j/Z3Hc2HIS15Gal2KMKyLAZ2om1HCEvK6es=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0/go.mod h1:i2C41tszDjiWfziPQDL5R/f3Zp0gahXe5No/MIO9rCE=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240320170541-d33fe3788dfb h1:GbJdCYByc+aQWDo/DcKsQPgzAEkEiK74LChYbNTdKkQ=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240320170541-d33fe3788dfb/go.mod h1:byTI6lADBHk3CFRtlrJBdf5H2bMlUu0tnjzYUbT0oxE=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240320182510-2b8fc14990c3 h1:4VxL14YLPakzZX8NhZwyCw9Rv7SYeBUfW5Yj1s0JN2s=
github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240320182510-2b8fc14990c3/go.mod h1:byTI6lADBHk3CFRtlrJBdf5H2bMlUu0tnjzYUbT0oxE=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
// ----------------------------------------------------------------------------
//
// *** 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 (
"reflect"

"github.com/GoogleCloudPlatform/terraform-google-conversion/v5/tfplan2cai/converters/google/resources/cai"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
)

const CloudQuotasQuotaPreferenceAssetType string = "cloudquotas.googleapis.com/QuotaPreference"

func ResourceConverterCloudQuotasQuotaPreference() cai.ResourceConverter {
return cai.ResourceConverter{
AssetType: CloudQuotasQuotaPreferenceAssetType,
Convert: GetCloudQuotasQuotaPreferenceCaiObject,
}
}

func GetCloudQuotasQuotaPreferenceCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) {
name, err := cai.AssetName(d, config, "//cloudquotas.googleapis.com/{{parent}}/locations/global/quotaPreferences/{{name}}")
if err != nil {
return []cai.Asset{}, err
}
if obj, err := GetCloudQuotasQuotaPreferenceApiObject(d, config); err == nil {
return []cai.Asset{{
Name: name,
Type: CloudQuotasQuotaPreferenceAssetType,
Resource: &cai.AssetResource{
Version: "v1",
DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/cloudquotas/v1/rest",
DiscoveryName: "QuotaPreference",
Data: obj,
},
}}, nil
} else {
return []cai.Asset{}, err
}
}

func GetCloudQuotasQuotaPreferenceApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) {
obj := make(map[string]interface{})
nameProp, err := expandCloudQuotasQuotaPreferenceName(d.Get("name"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) {
obj["name"] = nameProp
}
serviceProp, err := expandCloudQuotasQuotaPreferenceService(d.Get("service"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("service"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceProp)) && (ok || !reflect.DeepEqual(v, serviceProp)) {
obj["service"] = serviceProp
}
quotaIdProp, err := expandCloudQuotasQuotaPreferenceQuotaId(d.Get("quota_id"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("quota_id"); !tpgresource.IsEmptyValue(reflect.ValueOf(quotaIdProp)) && (ok || !reflect.DeepEqual(v, quotaIdProp)) {
obj["quotaId"] = quotaIdProp
}
quotaConfigProp, err := expandCloudQuotasQuotaPreferenceQuotaConfig(d.Get("quota_config"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("quota_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(quotaConfigProp)) && (ok || !reflect.DeepEqual(v, quotaConfigProp)) {
obj["quotaConfig"] = quotaConfigProp
}
dimensionsProp, err := expandCloudQuotasQuotaPreferenceDimensions(d.Get("dimensions"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("dimensions"); !tpgresource.IsEmptyValue(reflect.ValueOf(dimensionsProp)) && (ok || !reflect.DeepEqual(v, dimensionsProp)) {
obj["dimensions"] = dimensionsProp
}
justificationProp, err := expandCloudQuotasQuotaPreferenceJustification(d.Get("justification"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("justification"); !tpgresource.IsEmptyValue(reflect.ValueOf(justificationProp)) && (ok || !reflect.DeepEqual(v, justificationProp)) {
obj["justification"] = justificationProp
}
contactEmailProp, err := expandCloudQuotasQuotaPreferenceContactEmail(d.Get("contact_email"), d, config)
if err != nil {
return nil, err
} else if v, ok := d.GetOkExists("contact_email"); !tpgresource.IsEmptyValue(reflect.ValueOf(contactEmailProp)) && (ok || !reflect.DeepEqual(v, contactEmailProp)) {
obj["contactEmail"] = contactEmailProp
}

return obj, nil
}

func expandCloudQuotasQuotaPreferenceName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return tpgresource.GetResourceNameFromSelfLink(v.(string)), nil
}

func expandCloudQuotasQuotaPreferenceService(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceQuotaId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil, nil
}
raw := l[0]
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedPreferredValue, err := expandCloudQuotasQuotaPreferenceQuotaConfigPreferredValue(original["preferred_value"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedPreferredValue); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["preferredValue"] = transformedPreferredValue
}

transformedStateDetail, err := expandCloudQuotasQuotaPreferenceQuotaConfigStateDetail(original["state_detail"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedStateDetail); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["stateDetail"] = transformedStateDetail
}

transformedGrantedValue, err := expandCloudQuotasQuotaPreferenceQuotaConfigGrantedValue(original["granted_value"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedGrantedValue); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["grantedValue"] = transformedGrantedValue
}

transformedTraceId, err := expandCloudQuotasQuotaPreferenceQuotaConfigTraceId(original["trace_id"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedTraceId); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["traceId"] = transformedTraceId
}

transformedAnnotations, err := expandCloudQuotasQuotaPreferenceQuotaConfigAnnotations(original["annotations"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedAnnotations); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["annotations"] = transformedAnnotations
}

transformedRequestOrigin, err := expandCloudQuotasQuotaPreferenceQuotaConfigRequestOrigin(original["request_origin"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedRequestOrigin); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["requestOrigin"] = transformedRequestOrigin
}

return transformed, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfigPreferredValue(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfigStateDetail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfigGrantedValue(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfigTraceId(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfigAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandCloudQuotasQuotaPreferenceQuotaConfigRequestOrigin(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceDimensions(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandCloudQuotasQuotaPreferenceJustification(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandCloudQuotasQuotaPreferenceContactEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

0 comments on commit 8dd212e

Please sign in to comment.