From 155aecad25a37ae9b9808a38e20c01bea12282c1 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 16 Aug 2022 11:33:28 -0700 Subject: [PATCH] promote cfn2 to ga (#6388) (#916) Signed-off-by: Modular Magician Signed-off-by: Modular Magician --- .../resources/cloudfunctions2_function.go | 660 ++++++++++++++++++ .../resources/cloudfunctions2_function_iam.go | 123 ++++ converters/google/resources/config.go | 4 + .../resources/iam_cloudfunctions2_function.go | 223 ++++++ .../google/resources/resource_converters.go | 3 + go.mod | 2 +- go.sum | 4 +- 7 files changed, 1016 insertions(+), 3 deletions(-) create mode 100644 converters/google/resources/cloudfunctions2_function.go create mode 100644 converters/google/resources/cloudfunctions2_function_iam.go create mode 100644 converters/google/resources/iam_cloudfunctions2_function.go diff --git a/converters/google/resources/cloudfunctions2_function.go b/converters/google/resources/cloudfunctions2_function.go new file mode 100644 index 000000000..6d396de65 --- /dev/null +++ b/converters/google/resources/cloudfunctions2_function.go @@ -0,0 +1,660 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 google + +import ( + "reflect" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +const Cloudfunctions2functionAssetType string = "cloudfunctions.googleapis.com/function" + +func resourceConverterCloudfunctions2function() ResourceConverter { + return ResourceConverter{ + AssetType: Cloudfunctions2functionAssetType, + Convert: GetCloudfunctions2functionCaiObject, + } +} + +func GetCloudfunctions2functionCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { + name, err := assetName(d, config, "//cloudfunctions.googleapis.com/projects/{{project}}/locations/{{location}}/functions/{{name}}") + if err != nil { + return []Asset{}, err + } + if obj, err := GetCloudfunctions2functionApiObject(d, config); err == nil { + return []Asset{{ + Name: name, + Type: Cloudfunctions2functionAssetType, + Resource: &AssetResource{ + Version: "v2", + DiscoveryDocumentURI: "https://www.googleapis.com/discovery/v1/apis/cloudfunctions/v2/rest", + DiscoveryName: "function", + Data: obj, + }, + }}, nil + } else { + return []Asset{}, err + } +} + +func GetCloudfunctions2functionApiObject(d TerraformResourceData, config *Config) (map[string]interface{}, error) { + obj := make(map[string]interface{}) + nameProp, err := expandCloudfunctions2functionName(d.Get("name"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("name"); !isEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp + } + descriptionProp, err := expandCloudfunctions2functionDescription(d.Get("description"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + obj["description"] = descriptionProp + } + buildConfigProp, err := expandCloudfunctions2functionBuildConfig(d.Get("build_config"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("build_config"); !isEmptyValue(reflect.ValueOf(buildConfigProp)) && (ok || !reflect.DeepEqual(v, buildConfigProp)) { + obj["buildConfig"] = buildConfigProp + } + serviceConfigProp, err := expandCloudfunctions2functionServiceConfig(d.Get("service_config"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("service_config"); !isEmptyValue(reflect.ValueOf(serviceConfigProp)) && (ok || !reflect.DeepEqual(v, serviceConfigProp)) { + obj["serviceConfig"] = serviceConfigProp + } + eventTriggerProp, err := expandCloudfunctions2functionEventTrigger(d.Get("event_trigger"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("event_trigger"); !isEmptyValue(reflect.ValueOf(eventTriggerProp)) && (ok || !reflect.DeepEqual(v, eventTriggerProp)) { + obj["eventTrigger"] = eventTriggerProp + } + labelsProp, err := expandCloudfunctions2functionLabels(d.Get("labels"), d, config) + if err != nil { + return nil, err + } else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { + obj["labels"] = labelsProp + } + + return obj, nil +} + +func expandCloudfunctions2functionName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return replaceVars(d, config, "projects/{{project}}/locations/{{location}}/functions/{{name}}") +} + +func expandCloudfunctions2functionDescription(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfig(v interface{}, d TerraformResourceData, config *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{}) + + transformedBuild, err := expandCloudfunctions2functionBuildConfigBuild(original["build"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBuild); val.IsValid() && !isEmptyValue(val) { + transformed["build"] = transformedBuild + } + + transformedRuntime, err := expandCloudfunctions2functionBuildConfigRuntime(original["runtime"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRuntime); val.IsValid() && !isEmptyValue(val) { + transformed["runtime"] = transformedRuntime + } + + transformedEntryPoint, err := expandCloudfunctions2functionBuildConfigEntryPoint(original["entry_point"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEntryPoint); val.IsValid() && !isEmptyValue(val) { + transformed["entryPoint"] = transformedEntryPoint + } + + transformedSource, err := expandCloudfunctions2functionBuildConfigSource(original["source"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedSource); val.IsValid() && !isEmptyValue(val) { + transformed["source"] = transformedSource + } + + transformedWorkerPool, err := expandCloudfunctions2functionBuildConfigWorkerPool(original["worker_pool"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedWorkerPool); val.IsValid() && !isEmptyValue(val) { + transformed["workerPool"] = transformedWorkerPool + } + + transformedEnvironmentVariables, err := expandCloudfunctions2functionBuildConfigEnvironmentVariables(original["environment_variables"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEnvironmentVariables); val.IsValid() && !isEmptyValue(val) { + transformed["environmentVariables"] = transformedEnvironmentVariables + } + + transformedDockerRepository, err := expandCloudfunctions2functionBuildConfigDockerRepository(original["docker_repository"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDockerRepository); val.IsValid() && !isEmptyValue(val) { + transformed["dockerRepository"] = transformedDockerRepository + } + + return transformed, nil +} + +func expandCloudfunctions2functionBuildConfigBuild(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigRuntime(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigEntryPoint(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSource(v interface{}, d TerraformResourceData, config *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{}) + + transformedStorageSource, err := expandCloudfunctions2functionBuildConfigSourceStorageSource(original["storage_source"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedStorageSource); val.IsValid() && !isEmptyValue(val) { + transformed["storageSource"] = transformedStorageSource + } + + transformedRepoSource, err := expandCloudfunctions2functionBuildConfigSourceRepoSource(original["repo_source"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepoSource); val.IsValid() && !isEmptyValue(val) { + transformed["repoSource"] = transformedRepoSource + } + + return transformed, nil +} + +func expandCloudfunctions2functionBuildConfigSourceStorageSource(v interface{}, d TerraformResourceData, config *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{}) + + transformedBucket, err := expandCloudfunctions2functionBuildConfigSourceStorageSourceBucket(original["bucket"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBucket); val.IsValid() && !isEmptyValue(val) { + transformed["bucket"] = transformedBucket + } + + transformedObject, err := expandCloudfunctions2functionBuildConfigSourceStorageSourceObject(original["object"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedObject); val.IsValid() && !isEmptyValue(val) { + transformed["object"] = transformedObject + } + + transformedGeneration, err := expandCloudfunctions2functionBuildConfigSourceStorageSourceGeneration(original["generation"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedGeneration); val.IsValid() && !isEmptyValue(val) { + transformed["generation"] = transformedGeneration + } + + return transformed, nil +} + +func expandCloudfunctions2functionBuildConfigSourceStorageSourceBucket(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceStorageSourceObject(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceStorageSourceGeneration(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSource(v interface{}, d TerraformResourceData, config *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{}) + + transformedProjectId, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceProjectId(original["project_id"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedProjectId); val.IsValid() && !isEmptyValue(val) { + transformed["projectId"] = transformedProjectId + } + + transformedRepoName, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceRepoName(original["repo_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRepoName); val.IsValid() && !isEmptyValue(val) { + transformed["repoName"] = transformedRepoName + } + + transformedBranchName, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceBranchName(original["branch_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedBranchName); val.IsValid() && !isEmptyValue(val) { + transformed["branchName"] = transformedBranchName + } + + transformedTagName, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceTagName(original["tag_name"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTagName); val.IsValid() && !isEmptyValue(val) { + transformed["tagName"] = transformedTagName + } + + transformedCommitSha, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceCommitSha(original["commit_sha"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedCommitSha); val.IsValid() && !isEmptyValue(val) { + transformed["commitSha"] = transformedCommitSha + } + + transformedDir, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceDir(original["dir"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedDir); val.IsValid() && !isEmptyValue(val) { + transformed["dir"] = transformedDir + } + + transformedInvertRegex, err := expandCloudfunctions2functionBuildConfigSourceRepoSourceInvertRegex(original["invert_regex"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedInvertRegex); val.IsValid() && !isEmptyValue(val) { + transformed["invertRegex"] = transformedInvertRegex + } + + return transformed, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceProjectId(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceRepoName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceBranchName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceTagName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceCommitSha(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceDir(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigSourceRepoSourceInvertRegex(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigWorkerPool(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionBuildConfigEnvironmentVariables(v interface{}, d TerraformResourceData, config *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 +} + +func expandCloudfunctions2functionBuildConfigDockerRepository(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfig(v interface{}, d TerraformResourceData, config *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{}) + + transformedService, err := expandCloudfunctions2functionServiceConfigService(original["service"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedService); val.IsValid() && !isEmptyValue(val) { + transformed["service"] = transformedService + } + + transformedTimeoutSeconds, err := expandCloudfunctions2functionServiceConfigTimeoutSeconds(original["timeout_seconds"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTimeoutSeconds); val.IsValid() && !isEmptyValue(val) { + transformed["timeoutSeconds"] = transformedTimeoutSeconds + } + + transformedAvailableMemory, err := expandCloudfunctions2functionServiceConfigAvailableMemory(original["available_memory"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAvailableMemory); val.IsValid() && !isEmptyValue(val) { + transformed["availableMemory"] = transformedAvailableMemory + } + + transformedEnvironmentVariables, err := expandCloudfunctions2functionServiceConfigEnvironmentVariables(original["environment_variables"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEnvironmentVariables); val.IsValid() && !isEmptyValue(val) { + transformed["environmentVariables"] = transformedEnvironmentVariables + } + + transformedMaxInstanceCount, err := expandCloudfunctions2functionServiceConfigMaxInstanceCount(original["max_instance_count"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMaxInstanceCount); val.IsValid() && !isEmptyValue(val) { + transformed["maxInstanceCount"] = transformedMaxInstanceCount + } + + transformedMinInstanceCount, err := expandCloudfunctions2functionServiceConfigMinInstanceCount(original["min_instance_count"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedMinInstanceCount); val.IsValid() && !isEmptyValue(val) { + transformed["minInstanceCount"] = transformedMinInstanceCount + } + + transformedVPCConnector, err := expandCloudfunctions2functionServiceConfigVPCConnector(original["vpc_connector"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedVPCConnector); val.IsValid() && !isEmptyValue(val) { + transformed["vpcConnector"] = transformedVPCConnector + } + + transformedVPCConnectorEgressSettings, err := expandCloudfunctions2functionServiceConfigVPCConnectorEgressSettings(original["vpc_connector_egress_settings"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedVPCConnectorEgressSettings); val.IsValid() && !isEmptyValue(val) { + transformed["vpcConnectorEgressSettings"] = transformedVPCConnectorEgressSettings + } + + transformedIngressSettings, err := expandCloudfunctions2functionServiceConfigIngressSettings(original["ingress_settings"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedIngressSettings); val.IsValid() && !isEmptyValue(val) { + transformed["ingressSettings"] = transformedIngressSettings + } + + transformedUri, err := expandCloudfunctions2functionServiceConfigUri(original["uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedUri); val.IsValid() && !isEmptyValue(val) { + transformed["uri"] = transformedUri + } + + transformedGcfUri, err := expandCloudfunctions2functionServiceConfigGcfUri(original["gcf_uri"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedGcfUri); val.IsValid() && !isEmptyValue(val) { + transformed["gcfUri"] = transformedGcfUri + } + + transformedServiceAccountEmail, err := expandCloudfunctions2functionServiceConfigServiceAccountEmail(original["service_account_email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServiceAccountEmail); val.IsValid() && !isEmptyValue(val) { + transformed["serviceAccountEmail"] = transformedServiceAccountEmail + } + + transformedAllTrafficOnLatestRevision, err := expandCloudfunctions2functionServiceConfigAllTrafficOnLatestRevision(original["all_traffic_on_latest_revision"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAllTrafficOnLatestRevision); val.IsValid() && !isEmptyValue(val) { + transformed["allTrafficOnLatestRevision"] = transformedAllTrafficOnLatestRevision + } + + return transformed, nil +} + +func expandCloudfunctions2functionServiceConfigService(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigTimeoutSeconds(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigAvailableMemory(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigEnvironmentVariables(v interface{}, d TerraformResourceData, config *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 +} + +func expandCloudfunctions2functionServiceConfigMaxInstanceCount(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigMinInstanceCount(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigVPCConnector(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigVPCConnectorEgressSettings(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigIngressSettings(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigUri(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigGcfUri(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigServiceAccountEmail(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionServiceConfigAllTrafficOnLatestRevision(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTrigger(v interface{}, d TerraformResourceData, config *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{}) + + transformedTrigger, err := expandCloudfunctions2functionEventTriggerTrigger(original["trigger"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTrigger); val.IsValid() && !isEmptyValue(val) { + transformed["trigger"] = transformedTrigger + } + + transformedTriggerRegion, err := expandCloudfunctions2functionEventTriggerTriggerRegion(original["trigger_region"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedTriggerRegion); val.IsValid() && !isEmptyValue(val) { + transformed["triggerRegion"] = transformedTriggerRegion + } + + transformedEventType, err := expandCloudfunctions2functionEventTriggerEventType(original["event_type"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEventType); val.IsValid() && !isEmptyValue(val) { + transformed["eventType"] = transformedEventType + } + + transformedEventFilters, err := expandCloudfunctions2functionEventTriggerEventFilters(original["event_filters"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedEventFilters); val.IsValid() && !isEmptyValue(val) { + transformed["eventFilters"] = transformedEventFilters + } + + transformedPubsubTopic, err := expandCloudfunctions2functionEventTriggerPubsubTopic(original["pubsub_topic"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedPubsubTopic); val.IsValid() && !isEmptyValue(val) { + transformed["pubsubTopic"] = transformedPubsubTopic + } + + transformedServiceAccountEmail, err := expandCloudfunctions2functionEventTriggerServiceAccountEmail(original["service_account_email"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServiceAccountEmail); val.IsValid() && !isEmptyValue(val) { + transformed["serviceAccountEmail"] = transformedServiceAccountEmail + } + + transformedRetryPolicy, err := expandCloudfunctions2functionEventTriggerRetryPolicy(original["retry_policy"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedRetryPolicy); val.IsValid() && !isEmptyValue(val) { + transformed["retryPolicy"] = transformedRetryPolicy + } + + return transformed, nil +} + +func expandCloudfunctions2functionEventTriggerTrigger(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerTriggerRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerEventType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerEventFilters(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + v = v.(*schema.Set).List() + 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{}) + + transformedAttribute, err := expandCloudfunctions2functionEventTriggerEventFiltersAttribute(original["attribute"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedAttribute); val.IsValid() && !isEmptyValue(val) { + transformed["attribute"] = transformedAttribute + } + + transformedValue, err := expandCloudfunctions2functionEventTriggerEventFiltersValue(original["value"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedValue); val.IsValid() && !isEmptyValue(val) { + transformed["value"] = transformedValue + } + + transformedOperator, err := expandCloudfunctions2functionEventTriggerEventFiltersOperator(original["operator"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedOperator); val.IsValid() && !isEmptyValue(val) { + transformed["operator"] = transformedOperator + } + + req = append(req, transformed) + } + return req, nil +} + +func expandCloudfunctions2functionEventTriggerEventFiltersAttribute(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerEventFiltersValue(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerEventFiltersOperator(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerPubsubTopic(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerServiceAccountEmail(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionEventTriggerRetryPolicy(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) { + return v, nil +} + +func expandCloudfunctions2functionLabels(v interface{}, d TerraformResourceData, config *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/converters/google/resources/cloudfunctions2_function_iam.go b/converters/google/resources/cloudfunctions2_function_iam.go new file mode 100644 index 000000000..5a4beb0eb --- /dev/null +++ b/converters/google/resources/cloudfunctions2_function_iam.go @@ -0,0 +1,123 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 google + +import "fmt" + +// Provide a separate asset type constant so we don't have to worry about name conflicts between IAM and non-IAM converter files +const Cloudfunctions2functionIAMAssetType string = "cloudfunctions.googleapis.com/function" + +func resourceConverterCloudfunctions2functionIamPolicy() ResourceConverter { + return ResourceConverter{ + AssetType: Cloudfunctions2functionIAMAssetType, + Convert: GetCloudfunctions2functionIamPolicyCaiObject, + MergeCreateUpdate: MergeCloudfunctions2functionIamPolicy, + } +} + +func resourceConverterCloudfunctions2functionIamBinding() ResourceConverter { + return ResourceConverter{ + AssetType: Cloudfunctions2functionIAMAssetType, + Convert: GetCloudfunctions2functionIamBindingCaiObject, + FetchFullResource: FetchCloudfunctions2functionIamPolicy, + MergeCreateUpdate: MergeCloudfunctions2functionIamBinding, + MergeDelete: MergeCloudfunctions2functionIamBindingDelete, + } +} + +func resourceConverterCloudfunctions2functionIamMember() ResourceConverter { + return ResourceConverter{ + AssetType: Cloudfunctions2functionIAMAssetType, + Convert: GetCloudfunctions2functionIamMemberCaiObject, + FetchFullResource: FetchCloudfunctions2functionIamPolicy, + MergeCreateUpdate: MergeCloudfunctions2functionIamMember, + MergeDelete: MergeCloudfunctions2functionIamMemberDelete, + } +} + +func GetCloudfunctions2functionIamPolicyCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { + return newCloudfunctions2functionIamAsset(d, config, expandIamPolicyBindings) +} + +func GetCloudfunctions2functionIamBindingCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { + return newCloudfunctions2functionIamAsset(d, config, expandIamRoleBindings) +} + +func GetCloudfunctions2functionIamMemberCaiObject(d TerraformResourceData, config *Config) ([]Asset, error) { + return newCloudfunctions2functionIamAsset(d, config, expandIamMemberBindings) +} + +func MergeCloudfunctions2functionIamPolicy(existing, incoming Asset) Asset { + existing.IAMPolicy = incoming.IAMPolicy + return existing +} + +func MergeCloudfunctions2functionIamBinding(existing, incoming Asset) Asset { + return mergeIamAssets(existing, incoming, mergeAuthoritativeBindings) +} + +func MergeCloudfunctions2functionIamBindingDelete(existing, incoming Asset) Asset { + return mergeDeleteIamAssets(existing, incoming, mergeDeleteAuthoritativeBindings) +} + +func MergeCloudfunctions2functionIamMember(existing, incoming Asset) Asset { + return mergeIamAssets(existing, incoming, mergeAdditiveBindings) +} + +func MergeCloudfunctions2functionIamMemberDelete(existing, incoming Asset) Asset { + return mergeDeleteIamAssets(existing, incoming, mergeDeleteAdditiveBindings) +} + +func newCloudfunctions2functionIamAsset( + d TerraformResourceData, + config *Config, + expandBindings func(d TerraformResourceData) ([]IAMBinding, error), +) ([]Asset, error) { + bindings, err := expandBindings(d) + if err != nil { + return []Asset{}, fmt.Errorf("expanding bindings: %v", err) + } + + name, err := assetName(d, config, "//cloudfunctions.googleapis.com/projects/{{project}}/locations/{{location}}/functions/{{cloud_function}}") + if err != nil { + return []Asset{}, err + } + + return []Asset{{ + Name: name, + Type: Cloudfunctions2functionIAMAssetType, + IAMPolicy: &IAMPolicy{ + Bindings: bindings, + }, + }}, nil +} + +func FetchCloudfunctions2functionIamPolicy(d TerraformResourceData, config *Config) (Asset, error) { + // Check if the identity field returns a value + if _, ok := d.GetOk("location"); !ok { + return Asset{}, ErrEmptyIdentityField + } + if _, ok := d.GetOk("cloud_function"); !ok { + return Asset{}, ErrEmptyIdentityField + } + + return fetchIamPolicy( + Cloudfunctions2functionIamUpdaterProducer, + d, + config, + "//cloudfunctions.googleapis.com/projects/{{project}}/locations/{{location}}/functions/{{cloud_function}}", + Cloudfunctions2functionIAMAssetType, + ) +} diff --git a/converters/google/resources/config.go b/converters/google/resources/config.go index efb4aba44..46b3cd7ba 100644 --- a/converters/google/resources/config.go +++ b/converters/google/resources/config.go @@ -178,6 +178,7 @@ type Config struct { CloudAssetBasePath string CloudBuildBasePath string CloudFunctionsBasePath string + Cloudfunctions2BasePath string CloudIdentityBasePath string CloudIotBasePath string CloudRunBasePath string @@ -271,6 +272,7 @@ const CertificateManagerBasePathKey = "CertificateManager" const CloudAssetBasePathKey = "CloudAsset" const CloudBuildBasePathKey = "CloudBuild" const CloudFunctionsBasePathKey = "CloudFunctions" +const Cloudfunctions2BasePathKey = "Cloudfunctions2" const CloudIdentityBasePathKey = "CloudIdentity" const CloudIotBasePathKey = "CloudIot" const CloudRunBasePathKey = "CloudRun" @@ -358,6 +360,7 @@ var DefaultBasePaths = map[string]string{ CloudAssetBasePathKey: "https://cloudasset.googleapis.com/v1/", CloudBuildBasePathKey: "https://cloudbuild.googleapis.com/v1/", CloudFunctionsBasePathKey: "https://cloudfunctions.googleapis.com/v1/", + Cloudfunctions2BasePathKey: "https://cloudfunctions.googleapis.com/v2/", CloudIdentityBasePathKey: "https://cloudidentity.googleapis.com/v1/", CloudIotBasePathKey: "https://cloudiot.googleapis.com/v1/", CloudRunBasePathKey: "https://{{location}}-run.googleapis.com/", @@ -1207,6 +1210,7 @@ func ConfigureBasePaths(c *Config) { c.CloudAssetBasePath = DefaultBasePaths[CloudAssetBasePathKey] c.CloudBuildBasePath = DefaultBasePaths[CloudBuildBasePathKey] c.CloudFunctionsBasePath = DefaultBasePaths[CloudFunctionsBasePathKey] + c.Cloudfunctions2BasePath = DefaultBasePaths[Cloudfunctions2BasePathKey] c.CloudIdentityBasePath = DefaultBasePaths[CloudIdentityBasePathKey] c.CloudIotBasePath = DefaultBasePaths[CloudIotBasePathKey] c.CloudRunBasePath = DefaultBasePaths[CloudRunBasePathKey] diff --git a/converters/google/resources/iam_cloudfunctions2_function.go b/converters/google/resources/iam_cloudfunctions2_function.go new file mode 100644 index 000000000..652c57cc5 --- /dev/null +++ b/converters/google/resources/iam_cloudfunctions2_function.go @@ -0,0 +1,223 @@ +// ---------------------------------------------------------------------------- +// +// *** 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 google + +import ( + "fmt" + + "github.com/hashicorp/errwrap" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "google.golang.org/api/cloudresourcemanager/v1" +) + +var Cloudfunctions2functionIamSchema = map[string]*schema.Schema{ + "project": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "location": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + }, + "cloud_function": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + DiffSuppressFunc: compareSelfLinkOrResourceName, + }, +} + +type Cloudfunctions2functionIamUpdater struct { + project string + location string + cloudFunction string + d TerraformResourceData + Config *Config +} + +func Cloudfunctions2functionIamUpdaterProducer(d TerraformResourceData, config *Config) (ResourceIamUpdater, error) { + values := make(map[string]string) + + project, _ := 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 + location, _ := getLocation(d, config) + if location != "" { + if err := d.Set("location", location); err != nil { + return nil, fmt.Errorf("Error setting location: %s", err) + } + } + values["location"] = location + if v, ok := d.GetOk("cloud_function"); ok { + values["cloud_function"] = v.(string) + } + + // We may have gotten either a long or short name, so attempt to parse long name if possible + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/functions/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)/(?P[^/]+)", "(?P[^/]+)"}, d, config, d.Get("cloud_function").(string)) + if err != nil { + return nil, err + } + + for k, v := range m { + values[k] = v + } + + u := &Cloudfunctions2functionIamUpdater{ + project: values["project"], + location: values["location"], + cloudFunction: values["cloud_function"], + 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("location", u.location); err != nil { + return nil, fmt.Errorf("Error setting location: %s", err) + } + if err := d.Set("cloud_function", u.GetResourceId()); err != nil { + return nil, fmt.Errorf("Error setting cloud_function: %s", err) + } + + return u, nil +} + +func Cloudfunctions2functionIdParseFunc(d *schema.ResourceData, config *Config) error { + values := make(map[string]string) + + project, _ := getProject(d, config) + if project != "" { + values["project"] = project + } + + location, _ := getLocation(d, config) + if location != "" { + values["location"] = location + } + + m, err := getImportIdQualifiers([]string{"projects/(?P[^/]+)/locations/(?P[^/]+)/functions/(?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 := &Cloudfunctions2functionIamUpdater{ + project: values["project"], + location: values["location"], + cloudFunction: values["cloud_function"], + d: d, + Config: config, + } + if err := d.Set("cloud_function", u.GetResourceId()); err != nil { + return fmt.Errorf("Error setting cloud_function: %s", err) + } + d.SetId(u.GetResourceId()) + return nil +} + +func (u *Cloudfunctions2functionIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) { + url, err := u.qualifyfunctionUrl("getIamPolicy") + if err != nil { + return nil, err + } + + project, err := getProject(u.d, u.Config) + if err != nil { + return nil, err + } + var obj map[string]interface{} + + userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) + if err != nil { + return nil, err + } + + policy, err := sendRequest(u.Config, "GET", project, url, userAgent, obj) + if err != nil { + return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err) + } + + out := &cloudresourcemanager.Policy{} + err = 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 *Cloudfunctions2functionIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanager.Policy) error { + json, err := ConvertToMap(policy) + if err != nil { + return err + } + + obj := make(map[string]interface{}) + obj["policy"] = json + + url, err := u.qualifyfunctionUrl("setIamPolicy") + if err != nil { + return err + } + project, err := getProject(u.d, u.Config) + if err != nil { + return err + } + + userAgent, err := generateUserAgentString(u.d, u.Config.userAgent) + if err != nil { + return err + } + + _, err = sendRequestWithTimeout(u.Config, "POST", project, url, userAgent, obj, 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 *Cloudfunctions2functionIamUpdater) qualifyfunctionUrl(methodIdentifier string) (string, error) { + urlTemplate := fmt.Sprintf("{{Cloudfunctions2BasePath}}%s:%s", fmt.Sprintf("projects/%s/locations/%s/functions/%s", u.project, u.location, u.cloudFunction), methodIdentifier) + url, err := replaceVars(u.d, u.Config, urlTemplate) + if err != nil { + return "", err + } + return url, nil +} + +func (u *Cloudfunctions2functionIamUpdater) GetResourceId() string { + return fmt.Sprintf("projects/%s/locations/%s/functions/%s", u.project, u.location, u.cloudFunction) +} + +func (u *Cloudfunctions2functionIamUpdater) GetMutexKey() string { + return fmt.Sprintf("iam-cloudfunctions2-function-%s", u.GetResourceId()) +} + +func (u *Cloudfunctions2functionIamUpdater) DescribeResource() string { + return fmt.Sprintf("cloudfunctions2 function %q", u.GetResourceId()) +} diff --git a/converters/google/resources/resource_converters.go b/converters/google/resources/resource_converters.go index d4ecf6be5..544e607d9 100644 --- a/converters/google/resources/resource_converters.go +++ b/converters/google/resources/resource_converters.go @@ -100,6 +100,9 @@ func ResourceConverters() map[string][]ResourceConverter { "google_cloudfunctions_function_iam_policy": {resourceConverterCloudFunctionsCloudFunctionIamPolicy()}, "google_cloudfunctions_function_iam_binding": {resourceConverterCloudFunctionsCloudFunctionIamBinding()}, "google_cloudfunctions_function_iam_member": {resourceConverterCloudFunctionsCloudFunctionIamMember()}, + "google_cloudfunctions2_function_iam_policy": {resourceConverterCloudfunctions2functionIamPolicy()}, + "google_cloudfunctions2_function_iam_binding": {resourceConverterCloudfunctions2functionIamBinding()}, + "google_cloudfunctions2_function_iam_member": {resourceConverterCloudfunctions2functionIamMember()}, "google_cloudiot_registry_iam_policy": {resourceConverterCloudIotDeviceRegistryIamPolicy()}, "google_cloudiot_registry_iam_binding": {resourceConverterCloudIotDeviceRegistryIamBinding()}, "google_cloudiot_registry_iam_member": {resourceConverterCloudIotDeviceRegistryIamMember()}, diff --git a/go.mod b/go.mod index 3fbb523d0..2f89f9d43 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.2 github.com/hashicorp/terraform-json v0.14.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0 - github.com/hashicorp/terraform-provider-google v1.20.1-0.20220816171203-9809b8a240bb + github.com/hashicorp/terraform-provider-google v1.20.1-0.20220816182857-ed4ffec8dc53 github.com/mitchellh/go-homedir v1.1.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 0343225b1..28b0e18af 100644 --- a/go.sum +++ b/go.sum @@ -642,8 +642,8 @@ github.com/hashicorp/terraform-plugin-log v0.4.1 h1:xpbmVhvuU3mgHzLetOmx9pkOL2rm github.com/hashicorp/terraform-plugin-log v0.4.1/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4= github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0 h1:/cdI5di5XA+N80gXzXF4YcHq36DprBskubk6Z8i26ZQ= github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0/go.mod h1:L3SHkD/Q8zPVgXviQmpVwy9nKwpXXZscVIpVEnQ/T50= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20220816171203-9809b8a240bb h1:vZ7zE+USylvmJwGozm+XVURqc+a6IUYZctt+DnZjZ5Y= -github.com/hashicorp/terraform-provider-google v1.20.1-0.20220816171203-9809b8a240bb/go.mod h1:HJ4eeT50GEXVlW89O0pxY505sHy2X6JoqnPu2A8n/lY= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20220816182857-ed4ffec8dc53 h1:j14AQ+F3RDg7a180aU5tlGSVEeMtR65KJX3h5Rz8iFk= +github.com/hashicorp/terraform-provider-google v1.20.1-0.20220816182857-ed4ffec8dc53/go.mod h1:HJ4eeT50GEXVlW89O0pxY505sHy2X6JoqnPu2A8n/lY= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg= github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI= github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=