From fea6dc40d32ca96610bac7311469f611a4262e1b Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Mon, 13 Jan 2025 17:35:41 +0000 Subject: [PATCH] Add google_chronicle_reference_list resource to chronicle (#12717) [upstream:d0f8efaf8b363e53e099e9a4f7211f06750fce76] Signed-off-by: Modular Magician --- .../chronicle/chronicle_reference_list.go | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 tfplan2cai/converters/google/resources/services/chronicle/chronicle_reference_list.go diff --git a/tfplan2cai/converters/google/resources/services/chronicle/chronicle_reference_list.go b/tfplan2cai/converters/google/resources/services/chronicle/chronicle_reference_list.go new file mode 100644 index 000000000..83bd2ae6e --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/chronicle/chronicle_reference_list.go @@ -0,0 +1,111 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 chronicle + +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 ChronicleReferenceListAssetType string = "{{location}}-chronicle.googleapis.com/ReferenceList" + +func ResourceConverterChronicleReferenceList() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: ChronicleReferenceListAssetType, + Convert: GetChronicleReferenceListCaiObject, + } +} + +func GetChronicleReferenceListCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//{{location}}-chronicle.googleapis.com/projects/{{project}}/locations/{{location}}/instances/{{instance}}/referenceLists/{{reference_list_id}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetChronicleReferenceListApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: ChronicleReferenceListAssetType, + Resource: &cai.AssetResource{ + Version: "v1beta", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/{{location}}-chronicle/v1beta/rest", + DiscoveryName: "ReferenceList", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetChronicleReferenceListApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + descriptionProp, err := expandChronicleReferenceListDescription(d.Get("description"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + entriesProp, err := expandChronicleReferenceListEntries(d.Get("entries"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("entries"); !tpgresource.IsEmptyValue(reflect.ValueOf(entriesProp)) && (ok || !reflect.DeepEqual(v, entriesProp)) { + obj["entries"] = entriesProp + } + syntaxTypeProp, err := expandChronicleReferenceListSyntaxType(d.Get("syntax_type"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("syntax_type"); !tpgresource.IsEmptyValue(reflect.ValueOf(syntaxTypeProp)) && (ok || !reflect.DeepEqual(v, syntaxTypeProp)) { + obj["syntaxType"] = syntaxTypeProp + } + + return obj, nil +} + +func expandChronicleReferenceListDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandChronicleReferenceListEntries(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedValue, err := expandChronicleReferenceListEntriesValue(original["value"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedValue); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["value"] = transformedValue + } + + req = append(req, transformed) + } + return req, nil +} + +func expandChronicleReferenceListEntriesValue(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandChronicleReferenceListSyntaxType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +}