| // 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 vmwareengine |
| |
| import ( |
| "fmt" |
| "log" |
| "reflect" |
| "strings" |
| "time" |
| |
| "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" |
| ) |
| |
| func ResourceVmwareengineExternalAccessRule() *schema.Resource { |
| return &schema.Resource{ |
| Create: resourceVmwareengineExternalAccessRuleCreate, |
| Read: resourceVmwareengineExternalAccessRuleRead, |
| Update: resourceVmwareengineExternalAccessRuleUpdate, |
| Delete: resourceVmwareengineExternalAccessRuleDelete, |
| |
| Importer: &schema.ResourceImporter{ |
| State: resourceVmwareengineExternalAccessRuleImport, |
| }, |
| |
| Timeouts: &schema.ResourceTimeout{ |
| Create: schema.DefaultTimeout(20 * time.Minute), |
| Update: schema.DefaultTimeout(20 * time.Minute), |
| Delete: schema.DefaultTimeout(20 * time.Minute), |
| }, |
| |
| Schema: map[string]*schema.Schema{ |
| "action": { |
| Type: schema.TypeString, |
| Required: true, |
| ValidateFunc: verify.ValidateEnum([]string{"ALLOW", "DENY"}), |
| Description: `The action that the external access rule performs. Possible values: ["ALLOW", "DENY"]`, |
| }, |
| "destination_ip_ranges": { |
| Type: schema.TypeList, |
| Required: true, |
| Description: `If destination ranges are specified, the external access rule applies only to |
| traffic that has a destination IP address in these ranges.`, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "external_address": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `The name of an 'ExternalAddress' resource.`, |
| }, |
| "ip_address_range": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `An IP address range in the CIDR format.`, |
| }, |
| }, |
| }, |
| }, |
| "destination_ports": { |
| Type: schema.TypeList, |
| Required: true, |
| Description: `A list of destination ports to which the external access rule applies.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "ip_protocol": { |
| Type: schema.TypeString, |
| Required: true, |
| Description: `The IP protocol to which the external access rule applies.`, |
| }, |
| "name": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The ID of the external access rule.`, |
| }, |
| "parent": { |
| Type: schema.TypeString, |
| Required: true, |
| ForceNew: true, |
| Description: `The resource name of the network policy. |
| Resource names are schemeless URIs that follow the conventions in https://cloud.google.com/apis/design/resource_names. |
| For example: projects/my-project/locations/us-west1-a/networkPolicies/my-policy`, |
| }, |
| "priority": { |
| Type: schema.TypeInt, |
| Required: true, |
| Description: `External access rule priority, which determines the external access rule to use when multiple rules apply.`, |
| }, |
| "source_ip_ranges": { |
| Type: schema.TypeList, |
| Required: true, |
| Description: `If source ranges are specified, the external access rule applies only to |
| traffic that has a source IP address in these ranges.`, |
| Elem: &schema.Resource{ |
| Schema: map[string]*schema.Schema{ |
| "ip_address": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `A single IP address.`, |
| }, |
| "ip_address_range": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `An IP address range in the CIDR format.`, |
| }, |
| }, |
| }, |
| }, |
| "source_ports": { |
| Type: schema.TypeList, |
| Required: true, |
| Description: `A list of source ports to which the external access rule applies.`, |
| Elem: &schema.Schema{ |
| Type: schema.TypeString, |
| }, |
| }, |
| "description": { |
| Type: schema.TypeString, |
| Optional: true, |
| Description: `User-provided description for the external access rule.`, |
| }, |
| "create_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Creation time of this resource. |
| A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and |
| up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, |
| }, |
| "state": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `State of the Cluster.`, |
| }, |
| "uid": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `System-generated unique identifier for the resource.`, |
| }, |
| "update_time": { |
| Type: schema.TypeString, |
| Computed: true, |
| Description: `Last updated time of this resource. |
| A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine |
| fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`, |
| }, |
| }, |
| UseJSONNumber: true, |
| } |
| } |
| |
| func resourceVmwareengineExternalAccessRuleCreate(d *schema.ResourceData, meta interface{}) error { |
| var project string |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| obj := make(map[string]interface{}) |
| descriptionProp, err := expandVmwareengineExternalAccessRuleDescription(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 |
| } |
| priorityProp, err := expandVmwareengineExternalAccessRulePriority(d.Get("priority"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("priority"); !tpgresource.IsEmptyValue(reflect.ValueOf(priorityProp)) && (ok || !reflect.DeepEqual(v, priorityProp)) { |
| obj["priority"] = priorityProp |
| } |
| actionProp, err := expandVmwareengineExternalAccessRuleAction(d.Get("action"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("action"); !tpgresource.IsEmptyValue(reflect.ValueOf(actionProp)) && (ok || !reflect.DeepEqual(v, actionProp)) { |
| obj["action"] = actionProp |
| } |
| ipProtocolProp, err := expandVmwareengineExternalAccessRuleIpProtocol(d.Get("ip_protocol"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("ip_protocol"); !tpgresource.IsEmptyValue(reflect.ValueOf(ipProtocolProp)) && (ok || !reflect.DeepEqual(v, ipProtocolProp)) { |
| obj["ipProtocol"] = ipProtocolProp |
| } |
| sourceIpRangesProp, err := expandVmwareengineExternalAccessRuleSourceIpRanges(d.Get("source_ip_ranges"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("source_ip_ranges"); !tpgresource.IsEmptyValue(reflect.ValueOf(sourceIpRangesProp)) && (ok || !reflect.DeepEqual(v, sourceIpRangesProp)) { |
| obj["sourceIpRanges"] = sourceIpRangesProp |
| } |
| sourcePortsProp, err := expandVmwareengineExternalAccessRuleSourcePorts(d.Get("source_ports"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("source_ports"); !tpgresource.IsEmptyValue(reflect.ValueOf(sourcePortsProp)) && (ok || !reflect.DeepEqual(v, sourcePortsProp)) { |
| obj["sourcePorts"] = sourcePortsProp |
| } |
| destinationIpRangesProp, err := expandVmwareengineExternalAccessRuleDestinationIpRanges(d.Get("destination_ip_ranges"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("destination_ip_ranges"); !tpgresource.IsEmptyValue(reflect.ValueOf(destinationIpRangesProp)) && (ok || !reflect.DeepEqual(v, destinationIpRangesProp)) { |
| obj["destinationIpRanges"] = destinationIpRangesProp |
| } |
| destinationPortsProp, err := expandVmwareengineExternalAccessRuleDestinationPorts(d.Get("destination_ports"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("destination_ports"); !tpgresource.IsEmptyValue(reflect.ValueOf(destinationPortsProp)) && (ok || !reflect.DeepEqual(v, destinationPortsProp)) { |
| obj["destinationPorts"] = destinationPortsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{VmwareengineBasePath}}{{parent}}/externalAccessRules?externalAccessRuleId={{name}}") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Creating new ExternalAccessRule: %#v", obj) |
| billingProject := "" |
| |
| // 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: "POST", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutCreate), |
| }) |
| if err != nil { |
| return fmt.Errorf("Error creating ExternalAccessRule: %s", err) |
| } |
| |
| // Store the ID now |
| id, err := tpgresource.ReplaceVars(d, config, "{{parent}}/externalAccessRules/{{name}}") |
| if err != nil { |
| return fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| err = VmwareengineOperationWaitTime( |
| config, res, project, "Creating ExternalAccessRule", userAgent, |
| d.Timeout(schema.TimeoutCreate)) |
| |
| if err != nil { |
| // The resource didn't actually create |
| d.SetId("") |
| return fmt.Errorf("Error waiting to create ExternalAccessRule: %s", err) |
| } |
| |
| log.Printf("[DEBUG] Finished creating ExternalAccessRule %q: %#v", d.Id(), res) |
| |
| return resourceVmwareengineExternalAccessRuleRead(d, meta) |
| } |
| |
| func resourceVmwareengineExternalAccessRuleRead(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, "{{VmwareengineBasePath}}{{parent}}/externalAccessRules/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| // 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: "GET", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, fmt.Sprintf("VmwareengineExternalAccessRule %q", d.Id())) |
| } |
| |
| if err := d.Set("create_time", flattenVmwareengineExternalAccessRuleCreateTime(res["createTime"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("update_time", flattenVmwareengineExternalAccessRuleUpdateTime(res["updateTime"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("description", flattenVmwareengineExternalAccessRuleDescription(res["description"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("priority", flattenVmwareengineExternalAccessRulePriority(res["priority"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("action", flattenVmwareengineExternalAccessRuleAction(res["action"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("ip_protocol", flattenVmwareengineExternalAccessRuleIpProtocol(res["ipProtocol"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("source_ip_ranges", flattenVmwareengineExternalAccessRuleSourceIpRanges(res["sourceIpRanges"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("source_ports", flattenVmwareengineExternalAccessRuleSourcePorts(res["sourcePorts"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("destination_ip_ranges", flattenVmwareengineExternalAccessRuleDestinationIpRanges(res["destinationIpRanges"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("destination_ports", flattenVmwareengineExternalAccessRuleDestinationPorts(res["destinationPorts"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("state", flattenVmwareengineExternalAccessRuleState(res["state"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| if err := d.Set("uid", flattenVmwareengineExternalAccessRuleUid(res["uid"], d, config)); err != nil { |
| return fmt.Errorf("Error reading ExternalAccessRule: %s", err) |
| } |
| |
| return nil |
| } |
| |
| func resourceVmwareengineExternalAccessRuleUpdate(d *schema.ResourceData, meta interface{}) error { |
| var project string |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| obj := make(map[string]interface{}) |
| descriptionProp, err := expandVmwareengineExternalAccessRuleDescription(d.Get("description"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { |
| obj["description"] = descriptionProp |
| } |
| priorityProp, err := expandVmwareengineExternalAccessRulePriority(d.Get("priority"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("priority"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, priorityProp)) { |
| obj["priority"] = priorityProp |
| } |
| actionProp, err := expandVmwareengineExternalAccessRuleAction(d.Get("action"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("action"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, actionProp)) { |
| obj["action"] = actionProp |
| } |
| ipProtocolProp, err := expandVmwareengineExternalAccessRuleIpProtocol(d.Get("ip_protocol"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("ip_protocol"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, ipProtocolProp)) { |
| obj["ipProtocol"] = ipProtocolProp |
| } |
| sourceIpRangesProp, err := expandVmwareengineExternalAccessRuleSourceIpRanges(d.Get("source_ip_ranges"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("source_ip_ranges"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourceIpRangesProp)) { |
| obj["sourceIpRanges"] = sourceIpRangesProp |
| } |
| sourcePortsProp, err := expandVmwareengineExternalAccessRuleSourcePorts(d.Get("source_ports"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("source_ports"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, sourcePortsProp)) { |
| obj["sourcePorts"] = sourcePortsProp |
| } |
| destinationIpRangesProp, err := expandVmwareengineExternalAccessRuleDestinationIpRanges(d.Get("destination_ip_ranges"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("destination_ip_ranges"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, destinationIpRangesProp)) { |
| obj["destinationIpRanges"] = destinationIpRangesProp |
| } |
| destinationPortsProp, err := expandVmwareengineExternalAccessRuleDestinationPorts(d.Get("destination_ports"), d, config) |
| if err != nil { |
| return err |
| } else if v, ok := d.GetOkExists("destination_ports"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, destinationPortsProp)) { |
| obj["destinationPorts"] = destinationPortsProp |
| } |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{VmwareengineBasePath}}{{parent}}/externalAccessRules/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Updating ExternalAccessRule %q: %#v", d.Id(), obj) |
| updateMask := []string{} |
| |
| if d.HasChange("description") { |
| updateMask = append(updateMask, "description") |
| } |
| |
| if d.HasChange("priority") { |
| updateMask = append(updateMask, "priority") |
| } |
| |
| if d.HasChange("action") { |
| updateMask = append(updateMask, "action") |
| } |
| |
| if d.HasChange("ip_protocol") { |
| updateMask = append(updateMask, "ipProtocol") |
| } |
| |
| if d.HasChange("source_ip_ranges") { |
| updateMask = append(updateMask, "sourceIpRanges") |
| } |
| |
| if d.HasChange("source_ports") { |
| updateMask = append(updateMask, "sourcePorts") |
| } |
| |
| if d.HasChange("destination_ip_ranges") { |
| updateMask = append(updateMask, "destinationIpRanges") |
| } |
| |
| if d.HasChange("destination_ports") { |
| updateMask = append(updateMask, "destinationPorts") |
| } |
| // 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 |
| } |
| |
| // if updateMask is empty we are not updating anything so skip the post |
| if len(updateMask) > 0 { |
| 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), |
| }) |
| |
| if err != nil { |
| return fmt.Errorf("Error updating ExternalAccessRule %q: %s", d.Id(), err) |
| } else { |
| log.Printf("[DEBUG] Finished updating ExternalAccessRule %q: %#v", d.Id(), res) |
| } |
| |
| err = VmwareengineOperationWaitTime( |
| config, res, project, "Updating ExternalAccessRule", userAgent, |
| d.Timeout(schema.TimeoutUpdate)) |
| |
| if err != nil { |
| return err |
| } |
| } |
| |
| return resourceVmwareengineExternalAccessRuleRead(d, meta) |
| } |
| |
| func resourceVmwareengineExternalAccessRuleDelete(d *schema.ResourceData, meta interface{}) error { |
| var project string |
| config := meta.(*transport_tpg.Config) |
| userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) |
| if err != nil { |
| return err |
| } |
| |
| billingProject := "" |
| |
| url, err := tpgresource.ReplaceVars(d, config, "{{VmwareengineBasePath}}{{parent}}/externalAccessRules/{{name}}") |
| if err != nil { |
| return err |
| } |
| |
| var obj map[string]interface{} |
| log.Printf("[DEBUG] Deleting ExternalAccessRule %q", d.Id()) |
| |
| // 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: "DELETE", |
| Project: billingProject, |
| RawURL: url, |
| UserAgent: userAgent, |
| Body: obj, |
| Timeout: d.Timeout(schema.TimeoutDelete), |
| }) |
| if err != nil { |
| return transport_tpg.HandleNotFoundError(err, d, "ExternalAccessRule") |
| } |
| |
| err = VmwareengineOperationWaitTime( |
| config, res, project, "Deleting ExternalAccessRule", userAgent, |
| d.Timeout(schema.TimeoutDelete)) |
| |
| if err != nil { |
| return err |
| } |
| |
| log.Printf("[DEBUG] Finished deleting ExternalAccessRule %q: %#v", d.Id(), res) |
| return nil |
| } |
| |
| func resourceVmwareengineExternalAccessRuleImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { |
| config := meta.(*transport_tpg.Config) |
| if err := tpgresource.ParseImportId([]string{ |
| "^(?P<parent>.+)/externalAccessRules/(?P<name>[^/]+)$", |
| }, d, config); err != nil { |
| return nil, err |
| } |
| |
| // Replace import id for the resource id |
| id, err := tpgresource.ReplaceVars(d, config, "{{parent}}/externalAccessRules/{{name}}") |
| if err != nil { |
| return nil, fmt.Errorf("Error constructing id: %s", err) |
| } |
| d.SetId(id) |
| |
| return []*schema.ResourceData{d}, nil |
| } |
| |
| func flattenVmwareengineExternalAccessRuleCreateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleUpdateTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleDescription(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRulePriority(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| // Handles the string fixed64 format |
| if strVal, ok := v.(string); ok { |
| if intVal, err := tpgresource.StringToFixed64(strVal); err == nil { |
| return intVal |
| } |
| } |
| |
| // number values are represented as float64 |
| if floatVal, ok := v.(float64); ok { |
| intVal := int(floatVal) |
| return intVal |
| } |
| |
| return v // let terraform core handle it otherwise |
| } |
| |
| func flattenVmwareengineExternalAccessRuleAction(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleIpProtocol(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleSourceIpRanges(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{}{ |
| "ip_address": flattenVmwareengineExternalAccessRuleSourceIpRangesIpAddress(original["ipAddress"], d, config), |
| "ip_address_range": flattenVmwareengineExternalAccessRuleSourceIpRangesIpAddressRange(original["ipAddressRange"], d, config), |
| }) |
| } |
| return transformed |
| } |
| func flattenVmwareengineExternalAccessRuleSourceIpRangesIpAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleSourceIpRangesIpAddressRange(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleSourcePorts(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleDestinationIpRanges(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{}{ |
| "ip_address_range": flattenVmwareengineExternalAccessRuleDestinationIpRangesIpAddressRange(original["ipAddressRange"], d, config), |
| "external_address": flattenVmwareengineExternalAccessRuleDestinationIpRangesExternalAddress(original["externalAddress"], d, config), |
| }) |
| } |
| return transformed |
| } |
| func flattenVmwareengineExternalAccessRuleDestinationIpRangesIpAddressRange(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleDestinationIpRangesExternalAddress(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleDestinationPorts(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func flattenVmwareengineExternalAccessRuleUid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { |
| return v |
| } |
| |
| func expandVmwareengineExternalAccessRuleDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRulePriority(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleAction(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleIpProtocol(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleSourceIpRanges(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{}) |
| |
| transformedIpAddress, err := expandVmwareengineExternalAccessRuleSourceIpRangesIpAddress(original["ip_address"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedIpAddress); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["ipAddress"] = transformedIpAddress |
| } |
| |
| transformedIpAddressRange, err := expandVmwareengineExternalAccessRuleSourceIpRangesIpAddressRange(original["ip_address_range"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedIpAddressRange); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["ipAddressRange"] = transformedIpAddressRange |
| } |
| |
| req = append(req, transformed) |
| } |
| return req, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleSourceIpRangesIpAddress(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleSourceIpRangesIpAddressRange(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleSourcePorts(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleDestinationIpRanges(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{}) |
| |
| transformedIpAddressRange, err := expandVmwareengineExternalAccessRuleDestinationIpRangesIpAddressRange(original["ip_address_range"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedIpAddressRange); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["ipAddressRange"] = transformedIpAddressRange |
| } |
| |
| transformedExternalAddress, err := expandVmwareengineExternalAccessRuleDestinationIpRangesExternalAddress(original["external_address"], d, config) |
| if err != nil { |
| return nil, err |
| } else if val := reflect.ValueOf(transformedExternalAddress); val.IsValid() && !tpgresource.IsEmptyValue(val) { |
| transformed["externalAddress"] = transformedExternalAddress |
| } |
| |
| req = append(req, transformed) |
| } |
| return req, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleDestinationIpRangesIpAddressRange(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleDestinationIpRangesExternalAddress(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |
| |
| func expandVmwareengineExternalAccessRuleDestinationPorts(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { |
| return v, nil |
| } |