|
| 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/eventarc/GoogleApiSource.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 eventarc |
| 18 | + |
| 19 | +import ( |
| 20 | + "reflect" |
| 21 | + |
| 22 | + "github.com/GoogleCloudPlatform/terraform-google-conversion/v6/tfplan2cai/converters/google/resources/cai" |
| 23 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| 24 | + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| 25 | +) |
| 26 | + |
| 27 | +const EventarcGoogleApiSourceAssetType string = "eventarc.googleapis.com/GoogleApiSource" |
| 28 | + |
| 29 | +func ResourceConverterEventarcGoogleApiSource() cai.ResourceConverter { |
| 30 | + return cai.ResourceConverter{ |
| 31 | + AssetType: EventarcGoogleApiSourceAssetType, |
| 32 | + Convert: GetEventarcGoogleApiSourceCaiObject, |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func GetEventarcGoogleApiSourceCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { |
| 37 | + name, err := cai.AssetName(d, config, "//eventarc.googleapis.com/projects/{{project}}/locations/{{location}}/googleApiSources/{{google_api_source_id}}") |
| 38 | + if err != nil { |
| 39 | + return []cai.Asset{}, err |
| 40 | + } |
| 41 | + if obj, err := GetEventarcGoogleApiSourceApiObject(d, config); err == nil { |
| 42 | + return []cai.Asset{{ |
| 43 | + Name: name, |
| 44 | + Type: EventarcGoogleApiSourceAssetType, |
| 45 | + Resource: &cai.AssetResource{ |
| 46 | + Version: "v1", |
| 47 | + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/eventarc/v1/rest", |
| 48 | + DiscoveryName: "GoogleApiSource", |
| 49 | + Data: obj, |
| 50 | + }, |
| 51 | + }}, nil |
| 52 | + } else { |
| 53 | + return []cai.Asset{}, err |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +func GetEventarcGoogleApiSourceApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { |
| 58 | + obj := make(map[string]interface{}) |
| 59 | + cryptoKeyNameProp, err := expandEventarcGoogleApiSourceCryptoKeyName(d.Get("crypto_key_name"), d, config) |
| 60 | + if err != nil { |
| 61 | + return nil, err |
| 62 | + } else if v, ok := d.GetOkExists("crypto_key_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(cryptoKeyNameProp)) && (ok || !reflect.DeepEqual(v, cryptoKeyNameProp)) { |
| 63 | + obj["cryptoKeyName"] = cryptoKeyNameProp |
| 64 | + } |
| 65 | + displayNameProp, err := expandEventarcGoogleApiSourceDisplayName(d.Get("display_name"), d, config) |
| 66 | + if err != nil { |
| 67 | + return nil, err |
| 68 | + } else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { |
| 69 | + obj["displayName"] = displayNameProp |
| 70 | + } |
| 71 | + destinationProp, err := expandEventarcGoogleApiSourceDestination(d.Get("destination"), d, config) |
| 72 | + if err != nil { |
| 73 | + return nil, err |
| 74 | + } else if v, ok := d.GetOkExists("destination"); !tpgresource.IsEmptyValue(reflect.ValueOf(destinationProp)) && (ok || !reflect.DeepEqual(v, destinationProp)) { |
| 75 | + obj["destination"] = destinationProp |
| 76 | + } |
| 77 | + loggingConfigProp, err := expandEventarcGoogleApiSourceLoggingConfig(d.Get("logging_config"), d, config) |
| 78 | + if err != nil { |
| 79 | + return nil, err |
| 80 | + } else if v, ok := d.GetOkExists("logging_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(loggingConfigProp)) && (ok || !reflect.DeepEqual(v, loggingConfigProp)) { |
| 81 | + obj["loggingConfig"] = loggingConfigProp |
| 82 | + } |
| 83 | + labelsProp, err := expandEventarcGoogleApiSourceEffectiveLabels(d.Get("effective_labels"), d, config) |
| 84 | + if err != nil { |
| 85 | + return nil, err |
| 86 | + } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { |
| 87 | + obj["labels"] = labelsProp |
| 88 | + } |
| 89 | + annotationsProp, err := expandEventarcGoogleApiSourceEffectiveAnnotations(d.Get("effective_annotations"), d, config) |
| 90 | + if err != nil { |
| 91 | + return nil, err |
| 92 | + } else if v, ok := d.GetOkExists("effective_annotations"); !tpgresource.IsEmptyValue(reflect.ValueOf(annotationsProp)) && (ok || !reflect.DeepEqual(v, annotationsProp)) { |
| 93 | + obj["annotations"] = annotationsProp |
| 94 | + } |
| 95 | + |
| 96 | + return obj, nil |
| 97 | +} |
| 98 | + |
| 99 | +func expandEventarcGoogleApiSourceCryptoKeyName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 100 | + return v, nil |
| 101 | +} |
| 102 | + |
| 103 | +func expandEventarcGoogleApiSourceDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 104 | + return v, nil |
| 105 | +} |
| 106 | + |
| 107 | +func expandEventarcGoogleApiSourceDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 108 | + return v, nil |
| 109 | +} |
| 110 | + |
| 111 | +func expandEventarcGoogleApiSourceLoggingConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 112 | + l := v.([]interface{}) |
| 113 | + if len(l) == 0 || l[0] == nil { |
| 114 | + return nil, nil |
| 115 | + } |
| 116 | + raw := l[0] |
| 117 | + original := raw.(map[string]interface{}) |
| 118 | + transformed := make(map[string]interface{}) |
| 119 | + |
| 120 | + transformedLogSeverity, err := expandEventarcGoogleApiSourceLoggingConfigLogSeverity(original["log_severity"], d, config) |
| 121 | + if err != nil { |
| 122 | + return nil, err |
| 123 | + } else if val := reflect.ValueOf(transformedLogSeverity); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| 124 | + transformed["logSeverity"] = transformedLogSeverity |
| 125 | + } |
| 126 | + |
| 127 | + return transformed, nil |
| 128 | +} |
| 129 | + |
| 130 | +func expandEventarcGoogleApiSourceLoggingConfigLogSeverity(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 131 | + return v, nil |
| 132 | +} |
| 133 | + |
| 134 | +func expandEventarcGoogleApiSourceEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { |
| 135 | + if v == nil { |
| 136 | + return map[string]string{}, nil |
| 137 | + } |
| 138 | + m := make(map[string]string) |
| 139 | + for k, val := range v.(map[string]interface{}) { |
| 140 | + m[k] = val.(string) |
| 141 | + } |
| 142 | + return m, nil |
| 143 | +} |
| 144 | + |
| 145 | +func expandEventarcGoogleApiSourceEffectiveAnnotations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { |
| 146 | + if v == nil { |
| 147 | + return map[string]string{}, nil |
| 148 | + } |
| 149 | + m := make(map[string]string) |
| 150 | + for k, val := range v.(map[string]interface{}) { |
| 151 | + m[k] = val.(string) |
| 152 | + } |
| 153 | + return m, nil |
| 154 | +} |
0 commit comments