|
| 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/compute/RegionCompositeHealthCheck.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 compute |
| 18 | + |
| 19 | +import ( |
| 20 | + "bytes" |
| 21 | + "context" |
| 22 | + "encoding/base64" |
| 23 | + "encoding/json" |
| 24 | + "fmt" |
| 25 | + "log" |
| 26 | + "reflect" |
| 27 | + "regexp" |
| 28 | + "slices" |
| 29 | + "sort" |
| 30 | + "strconv" |
| 31 | + "strings" |
| 32 | + "time" |
| 33 | + |
| 34 | + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
| 35 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" |
| 36 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" |
| 37 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" |
| 38 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" |
| 39 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 40 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" |
| 41 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" |
| 42 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 43 | + |
| 44 | + "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/tfplan2cai/converters/google/resources/cai" |
| 45 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| 46 | + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| 47 | + "github.com/hashicorp/terraform-provider-google-beta/google-beta/verify" |
| 48 | + |
| 49 | + "google.golang.org/api/googleapi" |
| 50 | +) |
| 51 | + |
| 52 | +var ( |
| 53 | + _ = bytes.Clone |
| 54 | + _ = context.WithCancel |
| 55 | + _ = base64.StdEncoding |
| 56 | + _ = fmt.Sprintf |
| 57 | + _ = json.Marshal |
| 58 | + _ = log.Print |
| 59 | + _ = reflect.ValueOf |
| 60 | + _ = regexp.Match |
| 61 | + _ = slices.Min([]int{1}) |
| 62 | + _ = sort.IntSlice{} |
| 63 | + _ = strconv.Atoi |
| 64 | + _ = strings.Trim |
| 65 | + _ = time.Now |
| 66 | + _ = diag.Diagnostic{} |
| 67 | + _ = customdiff.All |
| 68 | + _ = id.UniqueId |
| 69 | + _ = logging.LogLevel |
| 70 | + _ = retry.Retry |
| 71 | + _ = schema.Noop |
| 72 | + _ = structure.ExpandJsonFromString |
| 73 | + _ = validation.All |
| 74 | + _ = terraform.State{} |
| 75 | + _ = tpgresource.SetLabels |
| 76 | + _ = transport_tpg.Config{} |
| 77 | + _ = verify.ProjectRegex |
| 78 | + _ = googleapi.Error{} |
| 79 | +) |
| 80 | + |
| 81 | +const ComputeRegionCompositeHealthCheckAssetType string = "compute.googleapis.com/RegionCompositeHealthCheck" |
| 82 | + |
| 83 | +func ResourceConverterComputeRegionCompositeHealthCheck() cai.ResourceConverter { |
| 84 | + return cai.ResourceConverter{ |
| 85 | + AssetType: ComputeRegionCompositeHealthCheckAssetType, |
| 86 | + Convert: GetComputeRegionCompositeHealthCheckCaiObject, |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +func GetComputeRegionCompositeHealthCheckCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { |
| 91 | + name, err := cai.AssetName(d, config, "//compute.googleapis.com/projects/{{project}}/regions/{{region}}/compositeHealthChecks/{{name}}") |
| 92 | + if err != nil { |
| 93 | + return []cai.Asset{}, err |
| 94 | + } |
| 95 | + if obj, err := GetComputeRegionCompositeHealthCheckApiObject(d, config); err == nil { |
| 96 | + return []cai.Asset{{ |
| 97 | + Name: name, |
| 98 | + Type: ComputeRegionCompositeHealthCheckAssetType, |
| 99 | + Resource: &cai.AssetResource{ |
| 100 | + Version: "beta", |
| 101 | + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/compute/beta/rest", |
| 102 | + DiscoveryName: "RegionCompositeHealthCheck", |
| 103 | + Data: obj, |
| 104 | + }, |
| 105 | + }}, nil |
| 106 | + } else { |
| 107 | + return []cai.Asset{}, err |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +func GetComputeRegionCompositeHealthCheckApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { |
| 112 | + obj := make(map[string]interface{}) |
| 113 | + descriptionProp, err := expandComputeRegionCompositeHealthCheckDescription(d.Get("description"), d, config) |
| 114 | + if err != nil { |
| 115 | + return nil, err |
| 116 | + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| 117 | + obj["description"] = descriptionProp |
| 118 | + } |
| 119 | + healthSourcesProp, err := expandComputeRegionCompositeHealthCheckHealthSources(d.Get("health_sources"), d, config) |
| 120 | + if err != nil { |
| 121 | + return nil, err |
| 122 | + } else if v, ok := d.GetOkExists("health_sources"); !tpgresource.IsEmptyValue(reflect.ValueOf(healthSourcesProp)) && (ok || !reflect.DeepEqual(v, healthSourcesProp)) { |
| 123 | + obj["healthSources"] = healthSourcesProp |
| 124 | + } |
| 125 | + healthDestinationProp, err := expandComputeRegionCompositeHealthCheckHealthDestination(d.Get("health_destination"), d, config) |
| 126 | + if err != nil { |
| 127 | + return nil, err |
| 128 | + } else if v, ok := d.GetOkExists("health_destination"); !tpgresource.IsEmptyValue(reflect.ValueOf(healthDestinationProp)) && (ok || !reflect.DeepEqual(v, healthDestinationProp)) { |
| 129 | + obj["healthDestination"] = healthDestinationProp |
| 130 | + } |
| 131 | + fingerprintProp, err := expandComputeRegionCompositeHealthCheckFingerprint(d.Get("fingerprint"), d, config) |
| 132 | + if err != nil { |
| 133 | + return nil, err |
| 134 | + } else if v, ok := d.GetOkExists("fingerprint"); !tpgresource.IsEmptyValue(reflect.ValueOf(fingerprintProp)) && (ok || !reflect.DeepEqual(v, fingerprintProp)) { |
| 135 | + obj["fingerprint"] = fingerprintProp |
| 136 | + } |
| 137 | + nameProp, err := expandComputeRegionCompositeHealthCheckName(d.Get("name"), d, config) |
| 138 | + if err != nil { |
| 139 | + return nil, err |
| 140 | + } else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { |
| 141 | + obj["name"] = nameProp |
| 142 | + } |
| 143 | + |
| 144 | + return obj, nil |
| 145 | +} |
| 146 | + |
| 147 | +func expandComputeRegionCompositeHealthCheckDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 148 | + return v, nil |
| 149 | +} |
| 150 | + |
| 151 | +func expandComputeRegionCompositeHealthCheckHealthSources(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 152 | + l := v.([]interface{}) |
| 153 | + req := make([]interface{}, 0, len(l)) |
| 154 | + for _, raw := range l { |
| 155 | + if raw == nil { |
| 156 | + return nil, fmt.Errorf("Invalid value for health_sources: nil") |
| 157 | + } |
| 158 | + req = append(req, raw.(string)) |
| 159 | + } |
| 160 | + return req, nil |
| 161 | +} |
| 162 | + |
| 163 | +func expandComputeRegionCompositeHealthCheckHealthDestination(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 164 | + return v, nil |
| 165 | +} |
| 166 | + |
| 167 | +func expandComputeRegionCompositeHealthCheckFingerprint(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 168 | + return v, nil |
| 169 | +} |
| 170 | + |
| 171 | +func expandComputeRegionCompositeHealthCheckName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| 172 | + return v, nil |
| 173 | +} |
0 commit comments