| // Copyright (c) HashiCorp, Inc. |
| // SPDX-License-Identifier: MPL-2.0 |
| |
| // ---------------------------------------------------------------------------- |
| // |
| // *** 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 datafusion |
| |
| import ( |
| "fmt" |
| "log" |
| "net/http" |
| "reflect" |
| "strings" |
| "time" |
| |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" |
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" |
| transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport" |
| "github.com/hashicorp/terraform-provider-google-beta/google-beta/verify" |
| ) |
| |
| var instanceAcceleratorOptions = []string{ |
| "delta.default.checkpoint.directory", |
| "ui.feature.cdc", |
| } |
| |
| func instanceOptionsDiffSuppress(k, old, new string, d *schema.ResourceData) bool { |
| // Suppress diffs for the options generated by adding an accelerator to a data fusion instance |
| for _, option := range instanceAcceleratorOptions { |
| if strings.Contains(k, option) && new == "" { |
| return true |
| } |
| } |
| |
| // Let diff be determined by options (above) |
| if strings.Contains(k, "options.%") { |
| return true |
| } |
| |
| // For other keys, don't suppress diff. |
| return false |
| } |
| |
| func ResourceDataFusionInstance() *schema.Resource { |
| return &schema.Resource{ |
| Create: resourceDataFusionInstanceCreate, |
| Read: resourceDataFusionInstanceRead, |
| Update: resourceDataFusionInstanceUpdate, |
| Delete: resourceDataFusionInstanceDelete, |
| |
| Importer: &schema.ResourceImporter{ |
| State: resourceDataFusionInstanceImport, |
| }, |
| |
| Timeouts: &schema.ResourceTimeout{ |
| Create: schema.DefaultTimeout(90 * time.Minute), |
| Update: schema.DefaultTimeout(25 * time.Minute), |
| Delete: schema.DefaultTimeout(50 * time.Minute), |
| }, |
| |
| CustomizeDiff: customdiff.All( |
| tpgresource.SetLabelsDiff, |
| tpgresource.DefaultProviderProject, |
| tpgresource.DefaultProviderRegion, |
| ), |
| |
| Schema: map[string]*schema.Schema{ |
| "name": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The ID of the instance or a fully qualified identifier for the instance.`, |
| }, |
| "type": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"BASIC", "ENTERPRISE", "DEVELOPER"}), |
| Description: `Represents the type of Data Fusion instance. Each type is configured with |
| the default settings for processing and memory. |
| - BASIC: Basic Data Fusion instance. In Basic type, the user will be able to create data pipelines |
| using point and click UI. However, there are certain limitations, such as fewer number |
| of concurrent pipelines, no support for streaming pipelines, etc. |
| - ENTERPRISE: Enterprise Data Fusion instance. In Enterprise type, the user will have more features |
| available, such as support for streaming pipelines, higher number of concurrent pipelines, etc. |
| - DEVELOPER: Developer Data Fusion instance. In Developer type, the user will have all features available but |
| with restrictive capabilities. This is to help enterprises design and develop their data ingestion and integration |
| pipelines at low cost. Possible values: ["BASIC", "ENTERPRISE", "DEVELOPER"]`, |
| }, |
| "accelerators": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `List of accelerators enabled for this CDF instance. |
| |
| If accelerators are enabled it is possible a permadiff will be created with the Options field. |
| Users will need to either manually update their state file to include these diffed options, or include the field in a [lifecycle ignore changes block](https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle#ignore_changes).`, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "accelerator_type": { |
| Type: schema.TypeString, |
| Required: true, |
| ValidateFunc: verify.ValidateEnum([]string{"CDC", "HEALTHCARE", "CCAI_INSIGHTS"}), |
| Description: `The type of an accelator for a CDF instance. Possible values: ["CDC", "HEALTHCARE", "CCAI_INSIGHTS"]`, |
| }, |
| "state": { |
| Type: schema.TypeString, |
| Required: true, |
| ValidateFunc: verify.ValidateEnum([]string{"ENABLED", "DISABLED"}), |
| Description: `The type of an accelator for a CDF instance. Possible values: ["ENABLED", "DISABLED"]`, |
| }, |
| }, |
| }, |
| }, |
| "crypto_key_config": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `The crypto key configuration. This field is used by the Customer-Managed Encryption Keys (CMEK) feature.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "key_reference": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The name of the key which is used to encrypt/decrypt customer data. For key in Cloud KMS, the key should be in the format of projects/*/locations/*/keyRings/*/cryptoKeys/*.`, |
| }, |
| }, |
| }, |
| }, |
| "dataproc_service_account": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `User-managed service account to set on Dataproc when Cloud Data Fusion creates Dataproc to run data processing pipelines.`, |
| }, |
| "description": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `An optional description of the instance.`, |
| }, |
| "display_name": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Display name for an instance.`, |
| }, |
| "enable_rbac": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `Option to enable granular role-based access control.`, |
| }, |
| "enable_stackdriver_logging": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `Option to enable Stackdriver Logging.`, |
| }, |
| "enable_stackdriver_monitoring": { |
| Type: schema.TypeBool, |
| Optional: true, |
| Description: `Option to enable Stackdriver Monitoring.`, |
| }, |
| "event_publish_config": { |
| Type: schema.TypeList, |
| Optional: true, |
| Description: `Option to enable and pass metadata for event publishing.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "enabled": { |
| Type: schema.TypeBool, |
| Required: true, |
| Description: `Option to enable Event Publishing.`, |
| }, |
| "topic": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The resource name of the Pub/Sub topic. Format: projects/{projectId}/topics/{topic_id}`, |
| }, |
| }, |
| }, |
| }, |
| "labels": { |
| Type: schema.TypeMap, |
| Optional: true, |
| Description: `The resource labels for instance to use to annotate any related underlying resources, |
| such as Compute Engine VMs. |
| |
| |
| **Note**: This field is non-authoritative, and will only manage the labels present in your configuration. |
| Please refer to the field 'effective_labels' for all of the labels present on the resource.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "network_config": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Network configuration options. These are required when a private Data Fusion instance is to be created.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "connection_type": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| ValidateFunc: verify.ValidateEnum([]string{"VPC_PEERING", "PRIVATE_SERVICE_CONNECT_INTERFACES", ""}), |
| Description: `Optional. Type of connection for establishing private IP connectivity between the Data Fusion customer project VPC and |
| the corresponding tenant project from a predefined list of available connection modes. |
| If this field is unspecified for a private instance, VPC peering is used. Possible values: ["VPC_PEERING", "PRIVATE_SERVICE_CONNECT_INTERFACES"]`, |
| }, |
| "ip_allocation": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `The IP range in CIDR notation to use for the managed Data Fusion instance |
| nodes. This range must not overlap with any other ranges used in the Data Fusion instance network.`, |
| }, |
| "network": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Name of the network in the project with which the tenant project |
| will be peered for executing pipelines. In case of shared VPC where the network resides in another host |
| project the network should specified in the form of projects/{host-project-id}/global/networks/{network}`, |
| }, |
| "private_service_connect_config": { |
| Type: schema.TypeList, |
| Optional: true, |
| ForceNew: true, |
| Description: `Optional. Configuration for Private Service Connect. |
| This is required only when using connection type PRIVATE_SERVICE_CONNECT_INTERFACES.`, |
| MaxItems: 1, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "network_attachment": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Optional. The reference to the network attachment used to establish private connectivity. |
| It will be of the form projects/{project-id}/regions/{region}/networkAttachments/{network-attachment-id}. |
| This is required only when using connection type PRIVATE_SERVICE_CONNECT_INTERFACES.`, |
| }, |
| "unreachable_cidr_block": { |
| Type: schema.TypeString, |
| Optional: true, |
| ForceNew: true, |
| Description: `Optional. Input only. The CIDR block to which the CDF instance can't route traffic to in the consumer project VPC. |
| The size of this block should be at least /25. This range should not overlap with the primary address range of any subnetwork used by the network attachment. |
| This range can be used for other purposes in the consumer VPC as long as there is no requirement for CDF to reach destinations using these addresses. |
| If this value is not provided, the server chooses a non RFC 1918 address range. The format of this field is governed by RFC 4632.`, |
| }, |
| "effective_unreachable_cidr_block": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Output only. The CIDR block to which the CDF instance can't route traffic to in the consumer project VPC. |
| The size of this block is /25. The format of this field is governed by RFC 4632.`, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| }, |
| "options": { |
| Type: schema.TypeMap, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| DiffSuppressFunc: instanceOptionsDiffSuppress, |
| Description: `Map of additional options used to configure the behavior of Data Fusion instance.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "private_instance": { |
| Type: schema.TypeBool, |
| Optional: true, |
| ForceNew: true, |
| Description: `Specifies whether the Data Fusion instance should be private. If set to |
| true, all Data Fusion nodes will have private IP addresses and will not be |
| able to access the public internet.`, |
| }, |
| "region": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `The region of the Data Fusion instance.`, |
| }, |
| "version": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| Description: `Current version of the Data Fusion.`, |
| }, |
| "zone": { |
| Type: schema.TypeString, |
| Computed: true, |
| Optional: true, |
| ForceNew: true, |
| Description: `Name of the zone in which the Data Fusion instance will be created. Only DEVELOPER instances use this field.`, |
| }, |
| "api_endpoint": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Endpoint on which the REST APIs is accessible.`, |
| }, |
| "create_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The time the instance was created in RFC3339 UTC "Zulu" format, accurate to nanoseconds.`, |
| }, |
| "effective_labels": { |
| Type: schema.TypeMap, |
| Computed: true, |
| Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "gcs_bucket": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Cloud Storage bucket generated by Data Fusion in the customer project.`, |
| }, |
| "p4_service_account": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `P4 service account for the customer project.`, |
| }, |
| "service_account": { |
| Type: schema.TypeString, |
| Computed: true, |
| Deprecated: "`service_account` is deprecated and will be removed in a future major release. Instead, use `tenant_project_id` to extract the tenant project ID.", |
| Description: `Service account which will be used to access resources in the customer project.`, |
| }, |
| "service_endpoint": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Endpoint on which the Data Fusion UI and REST APIs are accessible.`, |
| }, |
| "state": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The current state of this Data Fusion instance. |
| - CREATING: Instance is being created |
| - RUNNING: Instance is running and ready for requests |
| - FAILED: Instance creation failed |
| - DELETING: Instance is being deleted |
| - UPGRADING: Instance is being upgraded |
| - RESTARTING: Instance is being restarted`, |
| }, |
| "state_message": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Additional information about the current state of this Data Fusion instance if available.`, |
| }, |
| "tenant_project_id": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The name of the tenant project.`, |
| }, |
| "terraform_labels": { |
| Type: schema.TypeMap, |
| Computed: true, |
| Description: `The combination of labels configured directly on the resource |
| and default labels configured on the provider.`, |
| Elem: &schema.Schema{Type: schema.TypeString}, |
| }, |
| "update_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `The time the instance was last updated in RFC3339 UTC "Zulu" format, accurate to nanoseconds.`, |
| }, |
| "project": { |
| Type: schema.TypeString, |
| Optional: true, |
| Computed: true, |
| ForceNew: true, |
| }, |
| }, |
| UseJSONNumber: true, |
| } |
| } |
| |
| func resourceDataFusionInstanceCreate(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| obj := make(map[string]interface{}) |
| nameProp, err := expandDataFusionInstanceName(d.Get("name"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { |
| obj["name"] = nameProp |
| } |
| descriptionProp, err := expandDataFusionInstanceDescription(d.Get("description"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| obj["description"] = descriptionProp |
| } |
| typeProp, err := expandDataFusionInstanceType(d.Get("type"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("type"); !tpgresource.IsEmptyValue(reflect.ValueOf(typeProp)) && (ok || !reflect.DeepEqual(v, typeProp)) { |
| obj["type"] = typeProp |
| } |
| enableStackdriverLoggingProp, err := expandDataFusionInstanceEnableStackdriverLogging(d.Get("enable_stackdriver_logging"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_stackdriver_logging"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableStackdriverLoggingProp)) && (ok || !reflect.DeepEqual(v, enableStackdriverLoggingProp)) { |
| obj["enableStackdriverLogging"] = enableStackdriverLoggingProp |
| } |
| enableStackdriverMonitoringProp, err := expandDataFusionInstanceEnableStackdriverMonitoring(d.Get("enable_stackdriver_monitoring"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_stackdriver_monitoring"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableStackdriverMonitoringProp)) && (ok || !reflect.DeepEqual(v, enableStackdriverMonitoringProp)) { |
| obj["enableStackdriverMonitoring"] = enableStackdriverMonitoringProp |
| } |
| enableRbacProp, err := expandDataFusionInstanceEnableRbac(d.Get("enable_rbac"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_rbac"); !tpgresource.IsEmptyValue(reflect.ValueOf(enableRbacProp)) && (ok || !reflect.DeepEqual(v, enableRbacProp)) { |
| obj["enableRbac"] = enableRbacProp |
| } |
| optionsProp, err := expandDataFusionInstanceOptions(d.Get("options"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("options"); !tpgresource.IsEmptyValue(reflect.ValueOf(optionsProp)) && (ok || !reflect.DeepEqual(v, optionsProp)) { |
| obj["options"] = optionsProp |
| } |
| versionProp, err := expandDataFusionInstanceVersion(d.Get("version"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("version"); !tpgresource.IsEmptyValue(reflect.ValueOf(versionProp)) && (ok || !reflect.DeepEqual(v, versionProp)) { |
| obj["version"] = versionProp |
| } |
| privateInstanceProp, err := expandDataFusionInstancePrivateInstance(d.Get("private_instance"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("private_instance"); !tpgresource.IsEmptyValue(reflect.ValueOf(privateInstanceProp)) && (ok || !reflect.DeepEqual(v, privateInstanceProp)) { |
| obj["privateInstance"] = privateInstanceProp |
| } |
| dataprocServiceAccountProp, err := expandDataFusionInstanceDataprocServiceAccount(d.Get("dataproc_service_account"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("dataproc_service_account"); !tpgresource.IsEmptyValue(reflect.ValueOf(dataprocServiceAccountProp)) && (ok || !reflect.DeepEqual(v, dataprocServiceAccountProp)) { |
| obj["dataprocServiceAccount"] = dataprocServiceAccountProp |
| } |
| networkConfigProp, err := expandDataFusionInstanceNetworkConfig(d.Get("network_config"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("network_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(networkConfigProp)) && (ok || !reflect.DeepEqual(v, networkConfigProp)) { |
| obj["networkConfig"] = networkConfigProp |
| } |
| zoneProp, err := expandDataFusionInstanceZone(d.Get("zone"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("zone"); !tpgresource.IsEmptyValue(reflect.ValueOf(zoneProp)) && (ok || !reflect.DeepEqual(v, zoneProp)) { |
| obj["zone"] = zoneProp |
| } |
| displayNameProp, err := expandDataFusionInstanceDisplayName(d.Get("display_name"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("display_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(displayNameProp)) && (ok || !reflect.DeepEqual(v, displayNameProp)) { |
| obj["displayName"] = displayNameProp |
| } |
| cryptoKeyConfigProp, err := expandDataFusionInstanceCryptoKeyConfig(d.Get("crypto_key_config"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("crypto_key_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(cryptoKeyConfigProp)) && (ok || !reflect.DeepEqual(v, cryptoKeyConfigProp)) { |
| obj["cryptoKeyConfig"] = cryptoKeyConfigProp |
| } |
| eventPublishConfigProp, err := expandDataFusionInstanceEventPublishConfig(d.Get("event_publish_config"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("event_publish_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(eventPublishConfigProp)) && (ok || !reflect.DeepEqual(v, eventPublishConfigProp)) { |
| obj["eventPublishConfig"] = eventPublishConfigProp |
| } |
| acceleratorsProp, err := expandDataFusionInstanceAccelerators(d.Get("accelerators"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("accelerators"); !tpgresource.IsEmptyValue(reflect.ValueOf(acceleratorsProp)) && (ok || !reflect.DeepEqual(v, acceleratorsProp)) { |
| obj["accelerators"] = acceleratorsProp |
| } |
| labelsProp, err := expandDataFusionInstanceEffectiveLabels(d.Get("effective_labels"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) { |
| obj["labels"] = labelsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DataFusionBasePath}}projects/{{project}}/locations/{{region}}/instances?instanceId={{name}}") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Creating new Instance: %#v", obj) |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| headers := make(http.Header) |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "POST", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutCreate), |
| Headers: headers, |
| }) |
| if err != nil { |
| return fmt.Errorf("Error creating Instance: %s", err) |
| } |
| |
| // Store the ID now |
| id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| if err != nil { |
| return fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| // Use the resource in the operation response to populate |
| // identity fields and d.Id() before read |
| var opRes map[string]interface{} |
| err = DataFusionOperationWaitTimeWithResponse( |
| config, res, &opRes, project, "Creating Instance", userAgent, |
| d.Timeout(schema.TimeoutCreate)) |
| if err != nil { |
| // The resource didn't actually create |
| d.SetId("") |
| |
| return fmt.Errorf("Error waiting to create Instance: %s", err) |
| } |
| |
| if err := d.Set("name", flattenDataFusionInstanceName(opRes["name"], d, config)); err != nil { |
| return err |
| } |
| |
| // This may have caused the ID to update - update it if so. |
| id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| if err != nil { |
| return fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| log.Printf("[DEBUG] Finished creating Instance %q: %#v", d.Id(), res) |
| |
| return resourceDataFusionInstanceRead(d, meta) |
| } |
| |
| func resourceDataFusionInstanceRead(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DataFusionBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| headers := make(http.Header) |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "GET", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Headers: headers, |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("DataFusionInstance %q", d.Id())) |
| } |
| |
| if err := d.Set("project", project); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| |
| region, err := tpgresource.GetRegion(d, config) |
| if err != nil { |
| return err |
| } |
| if err := d.Set("region", region); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| |
| if err := d.Set("name", flattenDataFusionInstanceName(res["name"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("description", flattenDataFusionInstanceDescription(res["description"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("type", flattenDataFusionInstanceType(res["type"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("enable_stackdriver_logging", flattenDataFusionInstanceEnableStackdriverLogging(res["enableStackdriverLogging"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("enable_stackdriver_monitoring", flattenDataFusionInstanceEnableStackdriverMonitoring(res["enableStackdriverMonitoring"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("enable_rbac", flattenDataFusionInstanceEnableRbac(res["enableRbac"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("labels", flattenDataFusionInstanceLabels(res["labels"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("options", flattenDataFusionInstanceOptions(res["options"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("create_time", flattenDataFusionInstanceCreateTime(res["createTime"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("update_time", flattenDataFusionInstanceUpdateTime(res["updateTime"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("state", flattenDataFusionInstanceState(res["state"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("state_message", flattenDataFusionInstanceStateMessage(res["stateMessage"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("service_endpoint", flattenDataFusionInstanceServiceEndpoint(res["serviceEndpoint"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("version", flattenDataFusionInstanceVersion(res["version"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("service_account", flattenDataFusionInstanceServiceAccount(res["serviceAccount"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("private_instance", flattenDataFusionInstancePrivateInstance(res["privateInstance"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("dataproc_service_account", flattenDataFusionInstanceDataprocServiceAccount(res["dataprocServiceAccount"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("tenant_project_id", flattenDataFusionInstanceTenantProjectId(res["tenantProjectId"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("gcs_bucket", flattenDataFusionInstanceGcsBucket(res["gcsBucket"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("network_config", flattenDataFusionInstanceNetworkConfig(res["networkConfig"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("zone", flattenDataFusionInstanceZone(res["zone"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("display_name", flattenDataFusionInstanceDisplayName(res["displayName"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("api_endpoint", flattenDataFusionInstanceApiEndpoint(res["apiEndpoint"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("p4_service_account", flattenDataFusionInstanceP4ServiceAccount(res["p4ServiceAccount"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("crypto_key_config", flattenDataFusionInstanceCryptoKeyConfig(res["cryptoKeyConfig"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("event_publish_config", flattenDataFusionInstanceEventPublishConfig(res["eventPublishConfig"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("accelerators", flattenDataFusionInstanceAccelerators(res["accelerators"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("terraform_labels", flattenDataFusionInstanceTerraformLabels(res["labels"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| if err := d.Set("effective_labels", flattenDataFusionInstanceEffectiveLabels(res["labels"], d, config)); err != nil { |
| return fmt.Errorf("Error reading Instance: %s", err) |
| } |
| |
| return nil |
| } |
| |
| func resourceDataFusionInstanceUpdate(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| obj := make(map[string]interface{}) |
| enableStackdriverLoggingProp, err := expandDataFusionInstanceEnableStackdriverLogging(d.Get("enable_stackdriver_logging"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_stackdriver_logging"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableStackdriverLoggingProp)) { |
| obj["enableStackdriverLogging"] = enableStackdriverLoggingProp |
| } |
| enableStackdriverMonitoringProp, err := expandDataFusionInstanceEnableStackdriverMonitoring(d.Get("enable_stackdriver_monitoring"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_stackdriver_monitoring"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableStackdriverMonitoringProp)) { |
| obj["enableStackdriverMonitoring"] = enableStackdriverMonitoringProp |
| } |
| enableRbacProp, err := expandDataFusionInstanceEnableRbac(d.Get("enable_rbac"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("enable_rbac"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableRbacProp)) { |
| obj["enableRbac"] = enableRbacProp |
| } |
| versionProp, err := expandDataFusionInstanceVersion(d.Get("version"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("version"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, versionProp)) { |
| obj["version"] = versionProp |
| } |
| eventPublishConfigProp, err := expandDataFusionInstanceEventPublishConfig(d.Get("event_publish_config"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("event_publish_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, eventPublishConfigProp)) { |
| obj["eventPublishConfig"] = eventPublishConfigProp |
| } |
| acceleratorsProp, err := expandDataFusionInstanceAccelerators(d.Get("accelerators"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("accelerators"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, acceleratorsProp)) { |
| obj["accelerators"] = acceleratorsProp |
| } |
| labelsProp, err := expandDataFusionInstanceEffectiveLabels(d.Get("effective_labels"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) { |
| obj["labels"] = labelsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DataFusionBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Updating Instance %q: %#v", d.Id(), obj) |
| headers := make(http.Header) |
| updateMask := []string{} |
| |
| if d.HasChange("enable_stackdriver_logging") { |
| updateMask = append(updateMask, "enableStackdriverLogging") |
| } |
| |
| if d.HasChange("enable_stackdriver_monitoring") { |
| updateMask = append(updateMask, "enableStackdriverMonitoring") |
| } |
| |
| if d.HasChange("enable_rbac") { |
| updateMask = append(updateMask, "enableRbac") |
| } |
| |
| // updateMask is a URL parameter but not present in the schema, so ReplaceVars |
| // won't set it |
| |
| url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) |
| if err != nil { |
| return err |
| } |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "PATCH", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutUpdate), |
| Headers: headers, |
| }) |
| |
| if err != nil { |
| return fmt.Errorf("Error updating Instance %q: %s", d.Id(), err) |
| } else { |
| log.Printf("[DEBUG] Finished updating Instance %q: %#v", d.Id(), res) |
| } |
| |
| err = DataFusionOperationWaitTime( |
| config, res, project, "Updating Instance", userAgent, |
| d.Timeout(schema.TimeoutUpdate)) |
| |
| if err != nil { |
| return err |
| } |
| |
| return resourceDataFusionInstanceRead(d, meta) |
| } |
| |
| func resourceDataFusionInstanceDelete(d *schema.ResourceData, meta interface{}) error { |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| project, err := tpgresource.GetProject(d, config) |
| if err != nil { |
| return fmt.Errorf("Error fetching project for Instance: %s", err) |
| } |
| billingProject = project |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{DataFusionBasePath}}projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| var obj map[string]interface{} |
| |
| // err == nil indicates that the billing_project value was found |
| if bp, err := tpgresource.GetBillingProject(d, config); err == nil { |
| billingProject = bp |
| } |
| |
| headers := make(http.Header) |
| |
| log.Printf("[DEBUG] Deleting Instance %q", d.Id()) |
| res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ |
| Config: config, |
| Method: "DELETE", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutDelete), |
| Headers: headers, |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, "Instance") |
| } |
| |
| err = DataFusionOperationWaitTime( |
| config, res, project, "Deleting Instance", userAgent, |
| d.Timeout(schema.TimeoutDelete)) |
| |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Finished deleting Instance %q: %#v", d.Id(), res) |
| return nil |
| } |
| |
| func resourceDataFusionInstanceImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { |
| config := meta.(*transport_tpg.Config) |
| if err := tpgresource.ParseImportId([]string{ |
| "^projects/(?P<project>[^/]+)/locations/(?P<region>[^/]+)/instances/(?P<name>[^/]+)$", |
| "^(?P<project>[^/]+)/(?P<region>[^/]+)/(?P<name>[^/]+)$", |
| "^(?P<region>[^/]+)/(?P<name>[^/]+)$", |
| "^(?P<name>[^/]+)$", |
| }, d, config); err != nil { |
| return nil, err |
| } |
| |
| // Replace import id for the resource id |
| id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| if err != nil { |
| return nil, fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| return []*schema.ResourceData{d}, nil |
| } |
| |
| func flattenDataFusionInstanceName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| return tpgresource.NameFromSelfLinkStateFunc(v) |
| } |
| |
| func flattenDataFusionInstanceDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceEnableStackdriverLogging(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceEnableStackdriverMonitoring(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceEnableRbac(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| |
| transformed := make(map[string]interface{}) |
| if l, ok := d.GetOkExists("labels"); ok { |
| for k := range l.(map[string]interface{}) { |
| transformed[k] = v.(map[string]interface{})[k] |
| } |
| } |
| |
| return transformed |
| } |
| |
| func flattenDataFusionInstanceOptions(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceStateMessage(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceServiceEndpoint(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstancePrivateInstance(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceDataprocServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceTenantProjectId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceGcsBucket(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceNetworkConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["ip_allocation"] = |
| flattenDataFusionInstanceNetworkConfigIpAllocation(original["ipAllocation"], d, config) |
| transformed["network"] = |
| flattenDataFusionInstanceNetworkConfigNetwork(original["network"], d, config) |
| transformed["connection_type"] = |
| flattenDataFusionInstanceNetworkConfigConnectionType(original["connectionType"], d, config) |
| transformed["private_service_connect_config"] = |
| flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfig(original["privateServiceConnectConfig"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDataFusionInstanceNetworkConfigIpAllocation(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceNetworkConfigNetwork(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceNetworkConfigConnectionType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["network_attachment"] = |
| flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfigNetworkAttachment(original["networkAttachment"], d, config) |
| transformed["unreachable_cidr_block"] = |
| flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfigUnreachableCidrBlock(original["unreachableCidrBlock"], d, config) |
| transformed["effective_unreachable_cidr_block"] = |
| flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfigEffectiveUnreachableCidrBlock(original["effectiveUnreachableCidrBlock"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfigNetworkAttachment(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfigUnreachableCidrBlock(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return d.Get("network_config.0.private_service_connect_config.0.unreachable_cidr_block") |
| } |
| |
| func flattenDataFusionInstanceNetworkConfigPrivateServiceConnectConfigEffectiveUnreachableCidrBlock(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceZone(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceDisplayName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceApiEndpoint(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceP4ServiceAccount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceCryptoKeyConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["key_reference"] = |
| flattenDataFusionInstanceCryptoKeyConfigKeyReference(original["keyReference"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDataFusionInstanceCryptoKeyConfigKeyReference(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceEventPublishConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return nil |
| } |
| original := v.(map[string]interface{}) |
| if len(original) == 0 { |
| return nil |
| } |
| transformed := make(map[string]interface{}) |
| transformed["enabled"] = |
| flattenDataFusionInstanceEventPublishConfigEnabled(original["enabled"], d, config) |
| transformed["topic"] = |
| flattenDataFusionInstanceEventPublishConfigTopic(original["topic"], d, config) |
| return []interface{}{transformed} |
| } |
| func flattenDataFusionInstanceEventPublishConfigEnabled(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceEventPublishConfigTopic(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceAccelerators(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| l := v.([]interface{}) |
| transformed := make([]interface{}, 0, len(l)) |
| for _, raw := range l { |
| original := raw.(map[string]interface{}) |
| if len(original) < 1 { |
| // Do not include empty json objects coming back from the api |
| continue |
| } |
| transformed = append(transformed, map[string]interface{}{ |
| "accelerator_type": flattenDataFusionInstanceAcceleratorsAcceleratorType(original["acceleratorType"], d, config), |
| "state": flattenDataFusionInstanceAcceleratorsState(original["state"], d, config), |
| }) |
| } |
| return transformed |
| } |
| func flattenDataFusionInstanceAcceleratorsAcceleratorType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceAcceleratorsState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenDataFusionInstanceTerraformLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| if v == nil { |
| return v |
| } |
| |
| transformed := make(map[string]interface{}) |
| if l, ok := d.GetOkExists("terraform_labels"); ok { |
| for k := range l.(map[string]interface{}) { |
| transformed[k] = v.(map[string]interface{})[k] |
| } |
| } |
| |
| return transformed |
| } |
| |
| func flattenDataFusionInstanceEffectiveLabels(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func expandDataFusionInstanceName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{region}}/instances/{{name}}") |
| } |
| |
| func expandDataFusionInstanceDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceEnableStackdriverLogging(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceEnableStackdriverMonitoring(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceEnableRbac(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceOptions(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 |
| } |
| |
| func expandDataFusionInstanceVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstancePrivateInstance(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceDataprocServiceAccount(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfig(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{}) |
| |
| transformedIpAllocation, err := expandDataFusionInstanceNetworkConfigIpAllocation(original["ip_allocation"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedIpAllocation); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["ipAllocation"] = transformedIpAllocation |
| } |
| |
| transformedNetwork, err := expandDataFusionInstanceNetworkConfigNetwork(original["network"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedNetwork); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["network"] = transformedNetwork |
| } |
| |
| transformedConnectionType, err := expandDataFusionInstanceNetworkConfigConnectionType(original["connection_type"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedConnectionType); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["connectionType"] = transformedConnectionType |
| } |
| |
| transformedPrivateServiceConnectConfig, err := expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfig(original["private_service_connect_config"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedPrivateServiceConnectConfig); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["privateServiceConnectConfig"] = transformedPrivateServiceConnectConfig |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigIpAllocation(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigNetwork(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigConnectionType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfig(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{}) |
| |
| transformedNetworkAttachment, err := expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfigNetworkAttachment(original["network_attachment"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedNetworkAttachment); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["networkAttachment"] = transformedNetworkAttachment |
| } |
| |
| transformedUnreachableCidrBlock, err := expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfigUnreachableCidrBlock(original["unreachable_cidr_block"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedUnreachableCidrBlock); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["unreachableCidrBlock"] = transformedUnreachableCidrBlock |
| } |
| |
| transformedEffectiveUnreachableCidrBlock, err := expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfigEffectiveUnreachableCidrBlock(original["effective_unreachable_cidr_block"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEffectiveUnreachableCidrBlock); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["effectiveUnreachableCidrBlock"] = transformedEffectiveUnreachableCidrBlock |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfigNetworkAttachment(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfigUnreachableCidrBlock(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceNetworkConfigPrivateServiceConnectConfigEffectiveUnreachableCidrBlock(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceZone(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceDisplayName(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceCryptoKeyConfig(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{}) |
| |
| transformedKeyReference, err := expandDataFusionInstanceCryptoKeyConfigKeyReference(original["key_reference"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedKeyReference); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["keyReference"] = transformedKeyReference |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDataFusionInstanceCryptoKeyConfigKeyReference(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceEventPublishConfig(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{}) |
| |
| transformedEnabled, err := expandDataFusionInstanceEventPublishConfigEnabled(original["enabled"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedEnabled); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["enabled"] = transformedEnabled |
| } |
| |
| transformedTopic, err := expandDataFusionInstanceEventPublishConfigTopic(original["topic"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedTopic); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["topic"] = transformedTopic |
| } |
| |
| return transformed, nil |
| } |
| |
| func expandDataFusionInstanceEventPublishConfigEnabled(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceEventPublishConfigTopic(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceAccelerators(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{}) |
| |
| transformedAcceleratorType, err := expandDataFusionInstanceAcceleratorsAcceleratorType(original["accelerator_type"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedAcceleratorType); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["acceleratorType"] = transformedAcceleratorType |
| } |
| |
| transformedState, err := expandDataFusionInstanceAcceleratorsState(original["state"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedState); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["state"] = transformedState |
| } |
| |
| req = append(req, transformed) |
| } |
| return req, nil |
| } |
| |
| func expandDataFusionInstanceAcceleratorsAcceleratorType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceAcceleratorsState(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandDataFusionInstanceEffectiveLabels(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 |
| } |