diff --git a/go.mod b/go.mod index 8b8fddb7f..cc7e528a1 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.18.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 - github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240313114837-4a5ca1d3a863 + github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240315165833-17d05109509e github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index c711f30a0..a55e8289c 100644 --- a/go.sum +++ b/go.sum @@ -187,8 +187,8 @@ github.com/hashicorp/terraform-plugin-mux v0.13.0 h1:79U401/3nd8CWwDGtTHc8F3miSC github.com/hashicorp/terraform-plugin-mux v0.13.0/go.mod h1:Ndv0FtwDG2ogzH59y64f2NYimFJ6I0smRgFUKfm6dyQ= github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 h1:Bl3e2ei2j/Z3Hc2HIS15Gal2KMKyLAZ2om1HCEvK6es= github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0/go.mod h1:i2C41tszDjiWfziPQDL5R/f3Zp0gahXe5No/MIO9rCE= -github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240313114837-4a5ca1d3a863 h1:k/Pr2gVQjn/Wu9og6R1EfBbI59u5QT6RKG+DiHP7mNY= -github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240313114837-4a5ca1d3a863/go.mod h1:xqktgz44XcXx24WFlm6lYZEri5YeyyFGL+qBamSShDc= +github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240315165833-17d05109509e h1:Y9z+UamfsvpTSjlNpbZ6B3XxGjPUhI0++ePzpX5CLSI= +github.com/hashicorp/terraform-provider-google-beta v1.20.1-0.20240315165833-17d05109509e/go.mod h1:byTI6lADBHk3CFRtlrJBdf5H2bMlUu0tnjzYUbT0oxE= 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/resource_converters.go b/tfplan2cai/converters/google/resources/resource_converters.go index 091d1b4f0..86a603889 100644 --- a/tfplan2cai/converters/google/resources/resource_converters.go +++ b/tfplan2cai/converters/google/resources/resource_converters.go @@ -276,6 +276,9 @@ func ResourceConverters() map[string][]cai.ResourceConverter { "google_iap_tunnel_iam_policy": {iap.ResourceConverterIapTunnelIamPolicy()}, "google_iap_tunnel_iam_binding": {iap.ResourceConverterIapTunnelIamBinding()}, "google_iap_tunnel_iam_member": {iap.ResourceConverterIapTunnelIamMember()}, + "google_iap_tunnel_dest_group_iam_policy": {iap.ResourceConverterIapTunnelDestGroupIamPolicy()}, + "google_iap_tunnel_dest_group_iam_binding": {iap.ResourceConverterIapTunnelDestGroupIamBinding()}, + "google_iap_tunnel_dest_group_iam_member": {iap.ResourceConverterIapTunnelDestGroupIamMember()}, "google_iap_tunnel_instance_iam_policy": {iap.ResourceConverterIapTunnelInstanceIamPolicy()}, "google_iap_tunnel_instance_iam_binding": {iap.ResourceConverterIapTunnelInstanceIamBinding()}, "google_iap_tunnel_instance_iam_member": {iap.ResourceConverterIapTunnelInstanceIamMember()}, diff --git a/tfplan2cai/converters/google/resources/services/apphub/apphub_service.go b/tfplan2cai/converters/google/resources/services/apphub/apphub_service.go new file mode 100644 index 000000000..69ae37e6e --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/apphub/apphub_service.go @@ -0,0 +1,299 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 apphub + +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 ApphubServiceAssetType string = "apphub.googleapis.com/Service" + +func ResourceConverterApphubService() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: ApphubServiceAssetType, + Convert: GetApphubServiceCaiObject, + } +} + +func GetApphubServiceCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//apphub.googleapis.com/projects/{{project}}/locations/{{location}}/applications/{{application_id}}/services/{{service_id}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetApphubServiceApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: ApphubServiceAssetType, + Resource: &cai.AssetResource{ + Version: "v1", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/apphub/v1/rest", + DiscoveryName: "Service", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetApphubServiceApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + displayNameProp, err := expandApphubServiceDisplayName(d.Get("display_name"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandApphubServiceDescription(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 + } + attributesProp, err := expandApphubServiceAttributes(d.Get("attributes"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("attributes"); !tpgresource.IsEmptyValue(reflect.ValueOf(attributesProp)) && (ok || !reflect.DeepEqual(v, attributesProp)) { + obj["attributes"] = attributesProp + } + discoveredServiceProp, err := expandApphubServiceDiscoveredService(d.Get("discovered_service"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("discovered_service"); !tpgresource.IsEmptyValue(reflect.ValueOf(discoveredServiceProp)) && (ok || !reflect.DeepEqual(v, discoveredServiceProp)) { + obj["discoveredService"] = discoveredServiceProp + } + + return obj, nil +} + +func expandApphubServiceDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributes(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{}) + + transformedCriticality, err := expandApphubServiceAttributesCriticality(original["criticality"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCriticality); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["criticality"] = transformedCriticality + } + + transformedEnvironment, err := expandApphubServiceAttributesEnvironment(original["environment"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEnvironment); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["environment"] = transformedEnvironment + } + + transformedDeveloperOwners, err := expandApphubServiceAttributesDeveloperOwners(original["developer_owners"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDeveloperOwners); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["developerOwners"] = transformedDeveloperOwners + } + + transformedOperatorOwners, err := expandApphubServiceAttributesOperatorOwners(original["operator_owners"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedOperatorOwners); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["operatorOwners"] = transformedOperatorOwners + } + + transformedBusinessOwners, err := expandApphubServiceAttributesBusinessOwners(original["business_owners"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBusinessOwners); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["businessOwners"] = transformedBusinessOwners + } + + return transformed, nil +} + +func expandApphubServiceAttributesCriticality(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{}) + + transformedType, err := expandApphubServiceAttributesCriticalityType(original["type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedType); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["type"] = transformedType + } + + return transformed, nil +} + +func expandApphubServiceAttributesCriticalityType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesEnvironment(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{}) + + transformedType, err := expandApphubServiceAttributesEnvironmentType(original["type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedType); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["type"] = transformedType + } + + return transformed, nil +} + +func expandApphubServiceAttributesEnvironmentType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesDeveloperOwners(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{}) + + transformedDisplayName, err := expandApphubServiceAttributesDeveloperOwnersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + transformedEmail, err := expandApphubServiceAttributesDeveloperOwnersEmail(original["email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEmail); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["email"] = transformedEmail + } + + req = append(req, transformed) + } + return req, nil +} + +func expandApphubServiceAttributesDeveloperOwnersDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesDeveloperOwnersEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesOperatorOwners(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{}) + + transformedDisplayName, err := expandApphubServiceAttributesOperatorOwnersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + transformedEmail, err := expandApphubServiceAttributesOperatorOwnersEmail(original["email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEmail); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["email"] = transformedEmail + } + + req = append(req, transformed) + } + return req, nil +} + +func expandApphubServiceAttributesOperatorOwnersDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesOperatorOwnersEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesBusinessOwners(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{}) + + transformedDisplayName, err := expandApphubServiceAttributesBusinessOwnersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + transformedEmail, err := expandApphubServiceAttributesBusinessOwnersEmail(original["email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEmail); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["email"] = transformedEmail + } + + req = append(req, transformed) + } + return req, nil +} + +func expandApphubServiceAttributesBusinessOwnersDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceAttributesBusinessOwnersEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubServiceDiscoveredService(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} diff --git a/tfplan2cai/converters/google/resources/services/apphub/apphub_service_project_attachment.go b/tfplan2cai/converters/google/resources/services/apphub/apphub_service_project_attachment.go new file mode 100644 index 000000000..63b43dd3d --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/apphub/apphub_service_project_attachment.go @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 apphub + +import ( + "reflect" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "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" +) + +// Suppress all diff for the field Service Project +func ServiceProjectDiffSuppress(_, _, _ string, _ *schema.ResourceData) bool { + return true +} + +const ApphubServiceProjectAttachmentAssetType string = "apphub.googleapis.com/ServiceProjectAttachment" + +func ResourceConverterApphubServiceProjectAttachment() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: ApphubServiceProjectAttachmentAssetType, + Convert: GetApphubServiceProjectAttachmentCaiObject, + } +} + +func GetApphubServiceProjectAttachmentCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//apphub.googleapis.com/projects/{{project}}/locations/global/serviceProjectAttachments/{{service_project_attachment_id}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetApphubServiceProjectAttachmentApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: ApphubServiceProjectAttachmentAssetType, + Resource: &cai.AssetResource{ + Version: "v1", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/apphub/v1/rest", + DiscoveryName: "ServiceProjectAttachment", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetApphubServiceProjectAttachmentApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + serviceProjectProp, err := expandApphubServiceProjectAttachmentServiceProject(d.Get("service_project"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("service_project"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceProjectProp)) && (ok || !reflect.DeepEqual(v, serviceProjectProp)) { + obj["serviceProject"] = serviceProjectProp + } + + return obj, nil +} + +func expandApphubServiceProjectAttachmentServiceProject(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + + service_project := "projects/" + d.Get("service_project_attachment_id").(string) + + return service_project, nil +} diff --git a/tfplan2cai/converters/google/resources/services/apphub/apphub_workload.go b/tfplan2cai/converters/google/resources/services/apphub/apphub_workload.go new file mode 100644 index 000000000..c0b68ca40 --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/apphub/apphub_workload.go @@ -0,0 +1,299 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 apphub + +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 ApphubWorkloadAssetType string = "apphub.googleapis.com/Workload" + +func ResourceConverterApphubWorkload() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: ApphubWorkloadAssetType, + Convert: GetApphubWorkloadCaiObject, + } +} + +func GetApphubWorkloadCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//apphub.googleapis.com/projects/{{project}}/locations/{{location}}/applications/{{application_id}}/workloads/{{workload_id}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetApphubWorkloadApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: ApphubWorkloadAssetType, + Resource: &cai.AssetResource{ + Version: "v1", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/apphub/v1/rest", + DiscoveryName: "Workload", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetApphubWorkloadApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + displayNameProp, err := expandApphubWorkloadDisplayName(d.Get("display_name"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { + obj["displayName"] = displayNameProp + } + descriptionProp, err := expandApphubWorkloadDescription(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 + } + discoveredWorkloadProp, err := expandApphubWorkloadDiscoveredWorkload(d.Get("discovered_workload"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("discovered_workload"); !tpgresource.IsEmptyValue(reflect.ValueOf(discoveredWorkloadProp)) && (ok || !reflect.DeepEqual(v, discoveredWorkloadProp)) { + obj["discoveredWorkload"] = discoveredWorkloadProp + } + attributesProp, err := expandApphubWorkloadAttributes(d.Get("attributes"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("attributes"); !tpgresource.IsEmptyValue(reflect.ValueOf(attributesProp)) && (ok || !reflect.DeepEqual(v, attributesProp)) { + obj["attributes"] = attributesProp + } + + return obj, nil +} + +func expandApphubWorkloadDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadDiscoveredWorkload(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributes(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{}) + + transformedCriticality, err := expandApphubWorkloadAttributesCriticality(original["criticality"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCriticality); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["criticality"] = transformedCriticality + } + + transformedEnvironment, err := expandApphubWorkloadAttributesEnvironment(original["environment"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEnvironment); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["environment"] = transformedEnvironment + } + + transformedDeveloperOwners, err := expandApphubWorkloadAttributesDeveloperOwners(original["developer_owners"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDeveloperOwners); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["developerOwners"] = transformedDeveloperOwners + } + + transformedOperatorOwners, err := expandApphubWorkloadAttributesOperatorOwners(original["operator_owners"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedOperatorOwners); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["operatorOwners"] = transformedOperatorOwners + } + + transformedBusinessOwners, err := expandApphubWorkloadAttributesBusinessOwners(original["business_owners"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBusinessOwners); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["businessOwners"] = transformedBusinessOwners + } + + return transformed, nil +} + +func expandApphubWorkloadAttributesCriticality(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{}) + + transformedType, err := expandApphubWorkloadAttributesCriticalityType(original["type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedType); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["type"] = transformedType + } + + return transformed, nil +} + +func expandApphubWorkloadAttributesCriticalityType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesEnvironment(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{}) + + transformedType, err := expandApphubWorkloadAttributesEnvironmentType(original["type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedType); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["type"] = transformedType + } + + return transformed, nil +} + +func expandApphubWorkloadAttributesEnvironmentType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesDeveloperOwners(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{}) + + transformedDisplayName, err := expandApphubWorkloadAttributesDeveloperOwnersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + transformedEmail, err := expandApphubWorkloadAttributesDeveloperOwnersEmail(original["email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEmail); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["email"] = transformedEmail + } + + req = append(req, transformed) + } + return req, nil +} + +func expandApphubWorkloadAttributesDeveloperOwnersDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesDeveloperOwnersEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesOperatorOwners(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{}) + + transformedDisplayName, err := expandApphubWorkloadAttributesOperatorOwnersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + transformedEmail, err := expandApphubWorkloadAttributesOperatorOwnersEmail(original["email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEmail); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["email"] = transformedEmail + } + + req = append(req, transformed) + } + return req, nil +} + +func expandApphubWorkloadAttributesOperatorOwnersDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesOperatorOwnersEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesBusinessOwners(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{}) + + transformedDisplayName, err := expandApphubWorkloadAttributesBusinessOwnersDisplayName(original["display_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDisplayName); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["displayName"] = transformedDisplayName + } + + transformedEmail, err := expandApphubWorkloadAttributesBusinessOwnersEmail(original["email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEmail); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["email"] = transformedEmail + } + + req = append(req, transformed) + } + return req, nil +} + +func expandApphubWorkloadAttributesBusinessOwnersDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandApphubWorkloadAttributesBusinessOwnersEmail(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} diff --git a/tfplan2cai/converters/google/resources/services/compute/compute_region_url_map.go b/tfplan2cai/converters/google/resources/services/compute/compute_region_url_map.go index c9b81c808..9710bd977 100644 --- a/tfplan2cai/converters/google/resources/services/compute/compute_region_url_map.go +++ b/tfplan2cai/converters/google/resources/services/compute/compute_region_url_map.go @@ -536,6 +536,13 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRules(v interface{}, d t transformed["regexMatch"] = transformedRegexMatch } + transformedPathTemplateMatch, err := expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(original["path_template_match"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPathTemplateMatch); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["pathTemplateMatch"] = transformedPathTemplateMatch + } + req = append(req, transformed) } return req, nil @@ -819,6 +826,10 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesRegexMatch(v interf return v, nil } +func expandComputeRegionUrlMapPathMatcherRouteRulesMatchRulesPathTemplateMatch(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandComputeRegionUrlMapPathMatcherRouteRulesRouteAction(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -1263,6 +1274,13 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewrite(v inter transformed["pathPrefixRewrite"] = transformedPathPrefixRewrite } + transformedPathTemplateRewrite, err := expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(original["path_template_rewrite"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPathTemplateRewrite); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["pathTemplateRewrite"] = transformedPathTemplateRewrite + } + return transformed, nil } @@ -1274,6 +1292,10 @@ func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathPref return v, nil } +func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionUrlRewritePathTemplateRewrite(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandComputeRegionUrlMapPathMatcherRouteRulesRouteActionWeightedBackendServices(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { l := v.([]interface{}) req := make([]interface{}, 0, len(l)) diff --git a/tfplan2cai/converters/google/resources/services/iap/iam_iap_tunnel_dest_group.go b/tfplan2cai/converters/google/resources/services/iap/iam_iap_tunnel_dest_group.go new file mode 100644 index 000000000..169b8ebb2 --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/iap/iam_iap_tunnel_dest_group.go @@ -0,0 +1,247 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 iap + +import ( + "fmt" + + "github.com/hashicorp/errwrap" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "google.golang.org/api/cloudresourcemanager/v1" + + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgiamresource" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" + transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" +) + +var IapTunnelDestGroupIamSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "region": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "dest_group": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName, + }, +} + +type IapTunnelDestGroupIamUpdater struct { + project string + region string + destGroup string + d tpgresource.TerraformResourceData + Config *transport_tpg.Config +} + +func IapTunnelDestGroupIamUpdaterProducer(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (tpgiamresource.ResourceIamUpdater, error) { + values := make(map[string]string) + + project, _ := tpgresource.GetProject(d, config) + if project != "" { + if err := d.Set("project", project); err != nil { + return nil, fmt.Errorf("Error setting project: %s", err) + } + } + values["project"] = project + region, _ := tpgresource.GetRegion(d, config) + if region != "" { + if err := d.Set("region", region); err != nil { + return nil, fmt.Errorf("Error setting region: %s", err) + } + } + values["region"] = region + if v, ok := d.GetOk("dest_group"); ok { + values["dest_group"] = v.(string) + } + + // We may have gotten either a long or short name, so attempt to parse long name if possible + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_tunnel/locations/(?P[^/]+)/destGroups/(?P[^/]+)", "(?P[^/]+)/iap_tunnel/locations/(?P[^/]+)/destGroups/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("dest_group").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &IapTunnelDestGroupIamUpdater{ + project: values["project"], + region: values["region"], + destGroup: values["dest_group"], + d: d, + Config: config, + } + + if err := d.Set("project", u.project); err != nil { + return nil, fmt.Errorf("Error setting project: %s", err) + } + if err := d.Set("region", u.region); err != nil { + return nil, fmt.Errorf("Error setting region: %s", err) + } + if err := d.Set("dest_group", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting dest_group: %s", err) + } + + return u, nil +} + +func IapTunnelDestGroupIdParseFunc(d *schema.ResourceData, config *transport_tpg.Config) error { + values := make(map[string]string) + + project, _ := tpgresource.GetProject(d, config) + if project != "" { + values["project"] = project + } + + region, _ := tpgresource.GetRegion(d, config) + if region != "" { + values["region"] = region + } + + m, err := tpgresource.GetImportIdQualifiers([]string{"projects/(?P[^/]+)/iap_tunnel/locations/(?P[^/]+)/destGroups/(?P[^/]+)", "(?P[^/]+)/iap_tunnel/locations/(?P[^/]+)/destGroups/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Id()) + if err != nil { + return err + } + + for k, v := range m { + values[k] = v + } + + u := &IapTunnelDestGroupIamUpdater{ + project: values["project"], + region: values["region"], + destGroup: values["dest_group"], + d: d, + Config: config, + } + if err := d.Set("dest_group", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting dest_group: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *IapTunnelDestGroupIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyTunnelDestGroupUrl("getIamPolicy") + if err != nil { + return nil, err + } + + project, err := tpgresource.GetProject(u.d, u.Config) + if err != nil { + return nil, err + } + var obj map[string]interface{} + obj = map[string]interface{}{ + "options": map[string]interface{}{ + "requestedPolicyVersion": tpgiamresource.IamPolicyVersion, + }, + } + + userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent) + if err != nil { + return nil, err + } + + policy, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: u.Config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + }) + if err != nil { + return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) + } + + out := &cloudresourcemanager.Policy{} + err = tpgresource.Convert(policy, out) + if err != nil { + return nil, errwrap.Wrapf("Cannot convert a policy to a resource manager policy: {{err}}", err) + } + + return out, nil +} + +func (u *IapTunnelDestGroupIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { + json, err := tpgresource.ConvertToMap(policy) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + obj["policy"] = json + + url, err := u.qualifyTunnelDestGroupUrl("setIamPolicy") + if err != nil { + return err + } + project, err := tpgresource.GetProject(u.d, u.Config) + if err != nil { + return err + } + + userAgent, err := tpgresource.GenerateUserAgentString(u.d, u.Config.UserAgent) + if err != nil { + return err + } + + _, err = transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: u.Config, + Method: "POST", + Project: project, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: u.d.Timeout(schema.TimeoutCreate), + }) + if err != nil { + return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err) + } + + return nil +} + +func (u *IapTunnelDestGroupIamUpdater) qualifyTunnelDestGroupUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{IapBasePath}}%s:%s", fmt.Sprintf("projects/%s/iap_tunnel/locations/%s/destGroups/%s", u.project, u.region, u.destGroup), methodIdentifier) + url, err := tpgresource.ReplaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *IapTunnelDestGroupIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/iap_tunnel/locations/%s/destGroups/%s", u.project, u.region, u.destGroup) +} + +func (u *IapTunnelDestGroupIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-iap-tunneldestgroup-%s", u.GetResourceId()) +} + +func (u *IapTunnelDestGroupIamUpdater) DescribeResource() string { + return fmt.Sprintf("iap tunneldestgroup %q", u.GetResourceId()) +} diff --git a/tfplan2cai/converters/google/resources/services/iap/iap_tunnel_dest_group.go b/tfplan2cai/converters/google/resources/services/iap/iap_tunnel_dest_group.go new file mode 100644 index 000000000..1de9bcc54 --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/iap/iap_tunnel_dest_group.go @@ -0,0 +1,79 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 iap + +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 IapTunnelDestGroupAssetType string = "iap.googleapis.com/TunnelDestGroup" + +func ResourceConverterIapTunnelDestGroup() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: IapTunnelDestGroupAssetType, + Convert: GetIapTunnelDestGroupCaiObject, + } +} + +func GetIapTunnelDestGroupCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//iap.googleapis.com/projects/{{project}}/iap_tunnel/locations/{{region}}/destGroups/{{group_name}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetIapTunnelDestGroupApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: IapTunnelDestGroupAssetType, + Resource: &cai.AssetResource{ + Version: "v1", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/iap/v1/rest", + DiscoveryName: "TunnelDestGroup", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetIapTunnelDestGroupApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + cidrsProp, err := expandIapTunnelDestGroupCidrs(d.Get("cidrs"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("cidrs"); !tpgresource.IsEmptyValue(reflect.ValueOf(cidrsProp)) && (ok || !reflect.DeepEqual(v, cidrsProp)) { + obj["cidrs"] = cidrsProp + } + fqdnsProp, err := expandIapTunnelDestGroupFqdns(d.Get("fqdns"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("fqdns"); !tpgresource.IsEmptyValue(reflect.ValueOf(fqdnsProp)) && (ok || !reflect.DeepEqual(v, fqdnsProp)) { + obj["fqdns"] = fqdnsProp + } + + return obj, nil +} + +func expandIapTunnelDestGroupCidrs(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandIapTunnelDestGroupFqdns(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} diff --git a/tfplan2cai/converters/google/resources/services/iap/iap_tunnel_dest_group_iam.go b/tfplan2cai/converters/google/resources/services/iap/iap_tunnel_dest_group_iam.go new file mode 100644 index 000000000..742a5d3ec --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/iap/iap_tunnel_dest_group_iam.go @@ -0,0 +1,129 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 iap + +import ( + "fmt" + + "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" +) + +// Provide a separate asset type constant so we don't have to worry about name conflicts between IAM and non-IAM converter files +const IapTunnelDestGroupIAMAssetType string = "iap.googleapis.com/TunnelDestGroup" + +func ResourceConverterIapTunnelDestGroupIamPolicy() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: IapTunnelDestGroupIAMAssetType, + Convert: GetIapTunnelDestGroupIamPolicyCaiObject, + MergeCreateUpdate: MergeIapTunnelDestGroupIamPolicy, + } +} + +func ResourceConverterIapTunnelDestGroupIamBinding() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: IapTunnelDestGroupIAMAssetType, + Convert: GetIapTunnelDestGroupIamBindingCaiObject, + FetchFullResource: FetchIapTunnelDestGroupIamPolicy, + MergeCreateUpdate: MergeIapTunnelDestGroupIamBinding, + MergeDelete: MergeIapTunnelDestGroupIamBindingDelete, + } +} + +func ResourceConverterIapTunnelDestGroupIamMember() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: IapTunnelDestGroupIAMAssetType, + Convert: GetIapTunnelDestGroupIamMemberCaiObject, + FetchFullResource: FetchIapTunnelDestGroupIamPolicy, + MergeCreateUpdate: MergeIapTunnelDestGroupIamMember, + MergeDelete: MergeIapTunnelDestGroupIamMemberDelete, + } +} + +func GetIapTunnelDestGroupIamPolicyCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + return newIapTunnelDestGroupIamAsset(d, config, cai.ExpandIamPolicyBindings) +} + +func GetIapTunnelDestGroupIamBindingCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + return newIapTunnelDestGroupIamAsset(d, config, cai.ExpandIamRoleBindings) +} + +func GetIapTunnelDestGroupIamMemberCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + return newIapTunnelDestGroupIamAsset(d, config, cai.ExpandIamMemberBindings) +} + +func MergeIapTunnelDestGroupIamPolicy(existing, incoming cai.Asset) cai.Asset { + existing.IAMPolicy = incoming.IAMPolicy + return existing +} + +func MergeIapTunnelDestGroupIamBinding(existing, incoming cai.Asset) cai.Asset { + return cai.MergeIamAssets(existing, incoming, cai.MergeAuthoritativeBindings) +} + +func MergeIapTunnelDestGroupIamBindingDelete(existing, incoming cai.Asset) cai.Asset { + return cai.MergeDeleteIamAssets(existing, incoming, cai.MergeDeleteAuthoritativeBindings) +} + +func MergeIapTunnelDestGroupIamMember(existing, incoming cai.Asset) cai.Asset { + return cai.MergeIamAssets(existing, incoming, cai.MergeAdditiveBindings) +} + +func MergeIapTunnelDestGroupIamMemberDelete(existing, incoming cai.Asset) cai.Asset { + return cai.MergeDeleteIamAssets(existing, incoming, cai.MergeDeleteAdditiveBindings) +} + +func newIapTunnelDestGroupIamAsset( + d tpgresource.TerraformResourceData, + config *transport_tpg.Config, + expandBindings func(d tpgresource.TerraformResourceData) ([]cai.IAMBinding, error), +) ([]cai.Asset, error) { + bindings, err := expandBindings(d) + if err != nil { + return []cai.Asset{}, fmt.Errorf("expanding bindings: %v", err) + } + + name, err := cai.AssetName(d, config, "//iap.googleapis.com/projects/{{project}}/iap_tunnel/locations/{{region}}/destGroups/{{dest_group}}") + if err != nil { + return []cai.Asset{}, err + } + + return []cai.Asset{{ + Name: name, + Type: IapTunnelDestGroupIAMAssetType, + IAMPolicy: &cai.IAMPolicy{ + Bindings: bindings, + }, + }}, nil +} + +func FetchIapTunnelDestGroupIamPolicy(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (cai.Asset, error) { + // Check if the identity field returns a value + if _, ok := d.GetOk("region"); !ok { + return cai.Asset{}, cai.ErrEmptyIdentityField + } + if _, ok := d.GetOk("dest_group"); !ok { + return cai.Asset{}, cai.ErrEmptyIdentityField + } + + return cai.FetchIamPolicy( + IapTunnelDestGroupIamUpdaterProducer, + d, + config, + "//iap.googleapis.com/projects/{{project}}/iap_tunnel/locations/{{region}}/destGroups/{{dest_group}}", + IapTunnelDestGroupIAMAssetType, + ) +} diff --git a/tfplan2cai/converters/google/resources/services/networksecurity/networksecurity_firewall_endpoint_association.go b/tfplan2cai/converters/google/resources/services/networksecurity/networksecurity_firewall_endpoint_association.go new file mode 100644 index 000000000..496320792 --- /dev/null +++ b/tfplan2cai/converters/google/resources/services/networksecurity/networksecurity_firewall_endpoint_association.go @@ -0,0 +1,106 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 networksecurity + +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 NetworkSecurityFirewallEndpointAssociationAssetType string = "networksecurity.googleapis.com/FirewallEndpointAssociation" + +func ResourceConverterNetworkSecurityFirewallEndpointAssociation() cai.ResourceConverter { + return cai.ResourceConverter{ + AssetType: NetworkSecurityFirewallEndpointAssociationAssetType, + Convert: GetNetworkSecurityFirewallEndpointAssociationCaiObject, + } +} + +func GetNetworkSecurityFirewallEndpointAssociationCaiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) ([]cai.Asset, error) { + name, err := cai.AssetName(d, config, "//networksecurity.googleapis.com/{{parent}}/locations/{{location}}/firewallEndpointAssociations/{{name}}") + if err != nil { + return []cai.Asset{}, err + } + if obj, err := GetNetworkSecurityFirewallEndpointAssociationApiObject(d, config); err == nil { + return []cai.Asset{{ + Name: name, + Type: NetworkSecurityFirewallEndpointAssociationAssetType, + Resource: &cai.AssetResource{ + Version: "v1beta1", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/networksecurity/v1beta1/rest", + DiscoveryName: "FirewallEndpointAssociation", + Data: obj, + }, + }}, nil + } else { + return []cai.Asset{}, err + } +} + +func GetNetworkSecurityFirewallEndpointAssociationApiObject(d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + firewallEndpointProp, err := expandNetworkSecurityFirewallEndpointAssociationFirewallEndpoint(d.Get("firewall_endpoint"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("firewall_endpoint"); !tpgresource.IsEmptyValue(reflect.ValueOf(firewallEndpointProp)) && (ok || !reflect.DeepEqual(v, firewallEndpointProp)) { + obj["firewallEndpoint"] = firewallEndpointProp + } + networkProp, err := expandNetworkSecurityFirewallEndpointAssociationNetwork(d.Get("network"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("network"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkProp)) && (ok || !reflect.DeepEqual(v, networkProp)) { + obj["network"] = networkProp + } + tlsInspectionPolicyProp, err := expandNetworkSecurityFirewallEndpointAssociationTlsInspectionPolicy(d.Get("tls_inspection_policy"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("tls_inspection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(tlsInspectionPolicyProp)) && (ok || !reflect.DeepEqual(v, tlsInspectionPolicyProp)) { + obj["tlsInspectionPolicy"] = tlsInspectionPolicyProp + } + labelsProp, err := expandNetworkSecurityFirewallEndpointAssociationEffectiveLabels(d.Get("effective_labels"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + return obj, nil +} + +func expandNetworkSecurityFirewallEndpointAssociationFirewallEndpoint(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandNetworkSecurityFirewallEndpointAssociationNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandNetworkSecurityFirewallEndpointAssociationTlsInspectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandNetworkSecurityFirewallEndpointAssociationEffectiveLabels(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (map[string]string, error) { + if v == nil { + return map[string]string{}, nil + } + m := make(map[string]string) + for k, val := range v.(map[string]interface{}) { + m[k] = val.(string) + } + return m, nil +} diff --git a/tfplan2cai/converters/google/resources/services/notebooks/notebooks_instance.go b/tfplan2cai/converters/google/resources/services/notebooks/notebooks_instance.go index 2115429cf..a2a05f62f 100644 --- a/tfplan2cai/converters/google/resources/services/notebooks/notebooks_instance.go +++ b/tfplan2cai/converters/google/resources/services/notebooks/notebooks_instance.go @@ -32,8 +32,22 @@ var NotebooksInstanceProvidedScopes = []string{ "https://www.googleapis.com/auth/userinfo.email", } +var NotebooksInstanceProvidedTags = []string{ + "deeplearning-vm", + "notebook-instance", +} + func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData) bool { - old, new := d.GetChange("service_account_scopes") + return NotebooksDiffSuppressTemplate("service_account_scopes", NotebooksInstanceProvidedScopes, d) +} + +func NotebooksInstanceTagsDiffSuppress(_, _, _ string, d *schema.ResourceData) bool { + return NotebooksDiffSuppressTemplate("tags", NotebooksInstanceProvidedTags, d) +} + +func NotebooksDiffSuppressTemplate(field string, defaults []string, d *schema.ResourceData) bool { + old, new := d.GetChange(field) + oldValue := old.([]interface{}) newValue := new.([]interface{}) oldValueList := []string{} @@ -46,7 +60,7 @@ func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData) for _, item := range newValue { newValueList = append(newValueList, item.(string)) } - newValueList = append(newValueList, NotebooksInstanceProvidedScopes...) + newValueList = append(newValueList, defaults...) sort.Strings(oldValueList) sort.Strings(newValueList)