|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** Type: MMv1 *** |
| 4 | +// |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | +// |
| 7 | +// This code is generated by Magic Modules using the following: |
| 8 | +// |
| 9 | +// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/iambeta/WorkloadIdentityPoolManagedIdentity.yaml |
| 10 | +// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/tgc/resource_converter.go.tmpl |
| 11 | +// |
| 12 | +// DO NOT EDIT this file directly. Any changes made to this file will be |
| 13 | +// overwritten during the next generation cycle. |
| 14 | +// |
| 15 | +// ---------------------------------------------------------------------------- |
| 16 | + |
| 17 | +package iambeta |
| 18 | + |
| 19 | +import ( |
| 20 | + "fmt" |
| 21 | + "reflect" |
| 22 | + "regexp" |
| 23 | + "strings" |
| 24 | + |
| 25 | + "github.com/GoogleCloudPlatform/terraform-google-conversion/v6/tfplan2cai/converters/google/resources/cai" |
| 26 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| 27 | + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| 28 | +) |
| 29 | + |
| 30 | +const workloadIdentityPoolManagedIdentityIdRegexp = `^[0-9a-z-]+$` |
| 31 | + |
| 32 | +func ValidateWorkloadIdentityPoolManagedIdentityId(v interface{}, k string) (ws []string, errors []error) { |
| 33 | + value := v.(string) |
| 34 | + |
| 35 | + if !regexp.MustCompile(workloadIdentityPoolManagedIdentityIdRegexp).MatchString(value) { |
| 36 | + errors = append(errors, fmt.Errorf( |
| 37 | + "%q must contain only lowercase letters (a-z), numbers (0-9), or dashes (-)", k)) |
| 38 | + } |
| 39 | + |
| 40 | + if len(value) < 2 { |
| 41 | + errors = append(errors, fmt.Errorf( |
| 42 | + "%q cannot be less than 2 characters", k)) |
| 43 | + return |
| 44 | + } |
| 45 | + |
| 46 | + if len(value) > 63 { |
| 47 | + errors = append(errors, fmt.Errorf( |
| 48 | + "%q cannot be greater than 63 characters", k)) |
| 49 | + } |
| 50 | + |
| 51 | + isLowerAlphaNumeric := func(r byte) bool { |
| 52 | + return (r >= '0' && r <= '9') || (r >= 'a' && r <= 'z') |
| 53 | + } |
| 54 | + |
| 55 | + firstChar := value[0] |
| 56 | + if !isLowerAlphaNumeric(firstChar) { |
| 57 | + errors = append(errors, fmt.Errorf( |
| 58 | + "%q must start with an alphanumeric character", k)) |
| 59 | + } |
| 60 | + |
| 61 | + lastChar := value[len(value)-1] |
| 62 | + if !isLowerAlphaNumeric(lastChar) { |
| 63 | + errors = append(errors, fmt.Errorf( |
| 64 | + "%q must end with an alphanumeric character", k)) |
| 65 | + } |
| 66 | + |
| 67 | + if strings.HasPrefix(value, "gcp-") { |
| 68 | + errors = append(errors, fmt.Errorf( |
| 69 | + "%q (%q) can not start with \"gcp-\"", k, value)) |
| 70 | + } |
| 71 | + |
| 72 | + return |
| 73 | +} |
| 74 | + |
| 75 | +const IAMBetaWorkloadIdentityPoolManagedIdentityAssetType string = "iam.googleapis.com/WorkloadIdentityPoolManagedIdentity" |
| 76 | + |
| 77 | +func ResourceConverterIAMBetaWorkloadIdentityPoolManagedIdentity() cai.ResourceConverter { |
| 78 | + return cai.ResourceConverter{ |
| 79 | + AssetType: IAMBetaWorkloadIdentityPoolManagedIdentityAssetType, |
| 80 | + Convert: GetIAMBetaWorkloadIdentityPoolManagedIdentityCaiObject, |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +func GetIAMBetaWorkloadIdentityPoolManagedIdentityCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { |
| 85 | + name, err := cai.AssetName(d, config, "//iam.googleapis.com/projects/{{project}}/locations/global/workloadIdentityPools/{{workload_identity_pool_id}}/namespaces/{{workload_identity_pool_namespace_id}}/managedIdentities/{{workload_identity_pool_managed_identity_id}}") |
| 86 | + if err != nil { |
| 87 | + return []cai.Asset{}, err |
| 88 | + } |
| 89 | + if obj, err := GetIAMBetaWorkloadIdentityPoolManagedIdentityApiObject(d, config); err == nil { |
| 90 | + return []cai.Asset{{ |
| 91 | + Name: name, |
| 92 | + Type: IAMBetaWorkloadIdentityPoolManagedIdentityAssetType, |
| 93 | + Resource: &cai.AssetResource{ |
| 94 | + Version: "v1", |
| 95 | + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/iam/v1/rest", |
| 96 | + DiscoveryName: "WorkloadIdentityPoolManagedIdentity", |
| 97 | + Data: obj, |
| 98 | + }, |
| 99 | + }}, nil |
| 100 | + } else { |
| 101 | + return []cai.Asset{}, err |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +func GetIAMBetaWorkloadIdentityPoolManagedIdentityApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { |
| 106 | + obj := make(map[string]interface{}) |
| 107 | + descriptionProp, err := expandIAMBetaWorkloadIdentityPoolManagedIdentityDescription(d.Get("description"), d, config) |
| 108 | + if err != nil { |
| 109 | + return nil, err |
| 110 | + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| 111 | + obj["description"] = descriptionProp |
| 112 | + } |
| 113 | + disabledProp, err := expandIAMBetaWorkloadIdentityPoolManagedIdentityDisabled(d.Get("disabled"), d, config) |
| 114 | + if err != nil { |
| 115 | + return nil, err |
| 116 | + } else if v, ok := d.GetOkExists("disabled"); !tpgresource.IsEmptyValue(reflect.ValueOf(disabledProp)) && (ok || !reflect.DeepEqual(v, disabledProp)) { |
| 117 | + obj["disabled"] = disabledProp |
| 118 | + } |
| 119 | + |
| 120 | + return obj, nil |
| 121 | +} |
| 122 | + |
| 123 | +func expandIAMBetaWorkloadIdentityPoolManagedIdentityDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 124 | + return v, nil |
| 125 | +} |
| 126 | + |
| 127 | +func expandIAMBetaWorkloadIdentityPoolManagedIdentityDisabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 128 | + return v, nil |
| 129 | +} |
0 commit comments