From 8c749686405744296b42bcb9431a4d48a99186b0 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 9 Jul 2024 18:30:31 +0000 Subject: [PATCH] Add Resource SCC V1 Project Notification Config (#11004) [upstream:f9598bbfc513e6fc92a6bed4cf08bc0843a6ff38] Signed-off-by: Modular Magician --- go.mod | 2 +- go.sum | 4 +- ...uritycenter_project_notification_config.go | 108 ++++++++++++++++++ 3 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tfplan2cai/converters/google/resources/services/securitycenter/securitycenter_project_notification_config.go diff --git a/go.mod b/go.mod index ffb4e2942..84a1e2661 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/hashicorp/hcl/v2 v2.19.1 github.com/hashicorp/terraform-json v0.21.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 - github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240709170337-4bcc46189a96 + github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240709182658-c1bc41ed4446 github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 55af1a5d7..7bb5486a8 100644 --- a/go.sum +++ b/go.sum @@ -184,8 +184,8 @@ github.com/hashicorp/terraform-plugin-mux v0.15.0 h1:+/+lDx0WUsIOpkAmdwBIoFU8UP9 github.com/hashicorp/terraform-plugin-mux v0.15.0/go.mod h1:9ezplb1Dyq394zQ+ldB0nvy/qbNAz3mMoHHseMTMaKo= github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh3R4yp6pKksKHcqZx5G8= github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A= -github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240709170337-4bcc46189a96 h1:aaERKg5p15ugh2pkKRy6OWCtepuJmSd6+QSCUl8EBT4= -github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240709170337-4bcc46189a96/go.mod h1:LtqLd41zCL9zNzjz4lld4q9wnK3+MWRvIdoNc/anTZ0= +github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240709182658-c1bc41ed4446 h1:MI9PjAUANGjdSvngKZ08qZy0MksvfjNNvuO0y/vSnQQ= +github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240709182658-c1bc41ed4446/go.mod h1:LtqLd41zCL9zNzjz4lld4q9wnK3+MWRvIdoNc/anTZ0= 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= diff --git a/tfplan2cai/converters/google/resources/services/securitycenter/securitycenter_project_notification_config.go b/tfplan2cai/converters/google/resources/services/securitycenter/securitycenter_project_notification_config.go new file mode 100644 index 000000000..4d5b2b456 --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/securitycenter/securitycenter_project_notification_config.go @@ -0,0 +1,108 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 securitycenter + +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 SecurityCenterProjectNotificationConfigAssetType string = "securitycenter.googleapis.com/ProjectNotificationConfig" + +func ResourceConverterSecurityCenterProjectNotificationConfig() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: SecurityCenterProjectNotificationConfigAssetType, + Convert: GetSecurityCenterProjectNotificationConfigCaiObject, + } +} + +func GetSecurityCenterProjectNotificationConfigCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//securitycenter.googleapis.com/{{name}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetSecurityCenterProjectNotificationConfigApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: SecurityCenterProjectNotificationConfigAssetType, + Resource: &cai.AssetResource{ + Version: "v1", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/securitycenter/v1/rest", + DiscoveryName: "ProjectNotificationConfig", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetSecurityCenterProjectNotificationConfigApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + descriptionProp, err := expandSecurityCenterProjectNotificationConfigDescription(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 + } + pubsubTopicProp, err := expandSecurityCenterProjectNotificationConfigPubsubTopic(d.Get("pubsub_topic"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("pubsub_topic"); !tpgresource.IsEmptyValue(reflect.ValueOf(pubsubTopicProp)) && (ok || !reflect.DeepEqual(v, pubsubTopicProp)) { + obj["pubsubTopic"] = pubsubTopicProp + } + streamingConfigProp, err := expandSecurityCenterProjectNotificationConfigStreamingConfig(d.Get("streaming_config"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("streaming_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(streamingConfigProp)) && (ok || !reflect.DeepEqual(v, streamingConfigProp)) { + obj["streamingConfig"] = streamingConfigProp + } + + return obj, nil +} + +func expandSecurityCenterProjectNotificationConfigDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandSecurityCenterProjectNotificationConfigPubsubTopic(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandSecurityCenterProjectNotificationConfigStreamingConfig(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{}) + + transformedFilter, err := expandSecurityCenterProjectNotificationConfigStreamingConfigFilter(original["filter"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedFilter); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["filter"] = transformedFilter + } + + return transformed, nil +} + +func expandSecurityCenterProjectNotificationConfigStreamingConfigFilter(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +}