From f5b47e9c54e60ae65c358eceeb22575db6892288 Mon Sep 17 00:00:00 2001 From: Axel Ismirlian Date: Wed, 20 Nov 2024 10:41:07 -0600 Subject: [PATCH] Refactor Cloud Connection --- ibm/service/power/ibm_pi_constants.go | 294 +++++++++--------- .../power/resource_ibm_pi_cloud_connection.go | 265 ++++++++-------- .../resource_ibm_pi_cloud_connection_test.go | 174 ++++++----- .../docs/d/pi_cloud_connection.html.markdown | 12 +- .../docs/d/pi_cloud_connections.html.markdown | 10 +- .../docs/r/pi_cloud_connection.html.markdown | 34 +- 6 files changed, 402 insertions(+), 387 deletions(-) diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index f587aa1c9a..68b1f19fb6 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -4,133 +4,146 @@ import "time" const ( // Arguments - Arg_Action = "pi_action" - Arg_AffinityInstance = "pi_affinity_instance" - Arg_AffinityPolicy = "pi_affinity_policy" - Arg_AffinityVolume = "pi_affinity_volume" - Arg_AntiAffinityInstances = "pi_anti_affinity_instances" - Arg_AntiAffinityVolumes = "pi_anti_affinity_volumes" - Arg_BootVolumeReplicationEnabled = "pi_boot_volume_replication_enabled" - Arg_Cidr = "pi_cidr" - Arg_CloudConnectionID = "pi_cloud_connection_id" - Arg_CloudConnectionName = "pi_cloud_connection_name" - Arg_CloudInstanceID = "pi_cloud_instance_id" - Arg_ConsistencyGroupName = "pi_consistency_group_name" - Arg_Datacenter = "pi_datacenter" - Arg_DatacenterZone = "pi_datacenter_zone" - Arg_DeploymentTarget = "pi_deployment_target" - Arg_DeploymentType = "pi_deployment_type" - Arg_Description = "pi_description" - Arg_DestinationPorts = "pi_destination_ports" - Arg_DhcpID = "pi_dhcp_id" - Arg_DhcpName = "pi_dhcp_name" - Arg_DhcpSnatEnabled = "pi_dhcp_snat_enabled" - Arg_DNS = "pi_dns" - Arg_DnsServer = "pi_dns_server" - Arg_EndingIPAddress = "pi_ending_ip_address" - Arg_Gateway = "pi_gateway" - Arg_HealthStatus = "pi_health_status" - Arg_Host = "pi_host" - Arg_HostGroupID = "pi_host_group_id" - Arg_HostID = "pi_host_id" - Arg_Hosts = "pi_hosts" - Arg_IBMiCSS = "pi_ibmi_css" - Arg_IBMiPHA = "pi_ibmi_pha" - Arg_IBMiRDSUsers = "pi_ibmi_rds_users" - Arg_ImageID = "pi_image_id" - Arg_ImageImportDetails = "pi_image_import_details" - Arg_ImageName = "pi_image_name" - Arg_InstanceID = "pi_instance_id" - Arg_InstanceName = "pi_instance_name" - Arg_IPAddress = "pi_ip_address" - Arg_IPAddressRange = "pi_ipaddress_range" - Arg_Key = "pi_ssh_key" - Arg_KeyName = "pi_key_name" - Arg_KeyPairName = "pi_key_pair_name" - Arg_LanguageCode = "pi_language_code" - Arg_LicenseRepositoryCapacity = "pi_license_repository_capacity" - Arg_Memory = "pi_memory" - Arg_Name = "pi_name" - Arg_Network = "pi_network" - Arg_NetworkAccessConfig = "pi_network_access_config" - Arg_NetworkAddressGroupID = "pi_network_address_group_id" - Arg_NetworkAddressGroupMemberID = "pi_network_address_group_member_id" - Arg_NetworkID = "pi_network_id" - Arg_NetworkInterfaceID = "pi_network_interface_id" - Arg_NetworkJumbo = "pi_network_jumbo" - Arg_NetworkMTU = "pi_network_mtu" - Arg_NetworkName = "pi_network_name" - Arg_NetworkPeer = "pi_network_peer" - Arg_NetworkSecurityGroupID = "pi_network_security_group_id" - Arg_NetworkSecurityGroupMemberID = "pi_network_security_group_member_id" - Arg_NetworkSecurityGroupRuleID = "pi_network_security_group_rule_id" - Arg_NetworkType = "pi_network_type" - Arg_PinPolicy = "pi_pin_policy" - Arg_PlacementGroupID = "pi_placement_group_id" - Arg_PlacementGroupName = "pi_placement_group_name" - Arg_PlacementGroupPolicy = "pi_placement_group_policy" - Arg_Plan = "pi_plan" - Arg_Processors = "pi_processors" - Arg_ProcType = "pi_proc_type" - Arg_Protocol = "pi_protocol" - Arg_Remote = "pi_remote" - Arg_Remove = "pi_remove" - Arg_Replicants = "pi_replicants" - Arg_ReplicationEnabled = "pi_replication_enabled" - Arg_ReplicationPolicy = "pi_replication_policy" - Arg_ReplicationScheme = "pi_replication_scheme" - Arg_ReplicationSites = "pi_replication_sites" - Arg_ResourceGroupID = "pi_resource_group_id" - Arg_RetainVirtualSerialNumber = "pi_retain_virtual_serial_number" - Arg_SAP = "sap" - Arg_SAPDeploymentType = "pi_sap_deployment_type" - Arg_SAPProfileID = "pi_sap_profile_id" - Arg_Secondaries = "pi_secondaries" - Arg_Serial = "pi_serial" - Arg_SharedProcessorPool = "pi_shared_processor_pool" - Arg_SharedProcessorPoolHostGroup = "pi_shared_processor_pool_host_group" - Arg_SharedProcessorPoolID = "pi_shared_processor_pool_id" - Arg_SharedProcessorPoolName = "pi_shared_processor_pool_name" - Arg_SharedProcessorPoolPlacementGroupID = "pi_shared_processor_pool_placement_group_id" - Arg_SharedProcessorPoolPlacementGroups = "pi_shared_processor_pool_placement_groups" - Arg_SharedProcessorPoolReservedCores = "pi_shared_processor_pool_reserved_cores" - Arg_SnapshotID = "pi_snapshot_id" - Arg_SnapShotName = "pi_snap_shot_name" - Arg_SnapshotName = "pi_snapshot_name" - Arg_SourcePorts = "pi_source_ports" - Arg_SPPPlacementGroupID = "pi_spp_placement_group_id" - Arg_SPPPlacementGroupName = "pi_spp_placement_group_name" - Arg_SPPPlacementGroupPolicy = "pi_spp_placement_group_policy" - Arg_SSHKey = "pi_ssh_key" - Arg_StartingIPAddress = "pi_starting_ip_address" - Arg_StorageConnection = "pi_storage_connection" - Arg_StoragePool = "pi_storage_pool" - Arg_StoragePoolAffinity = "pi_storage_pool_affinity" - Arg_StorageType = "pi_storage_type" - Arg_SysType = "pi_sys_type" - Arg_Target = "pi_target" - Arg_TargetStorageTier = "pi_target_storage_tier" - Arg_Type = "pi_type" - Arg_UserData = "pi_user_data" - Arg_UserTags = "pi_user_tags" - Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned" - Arg_VirtualOpticalDevice = "pi_virtual_optical_device" - Arg_VirtualSerialNumber = "pi_virtual_serial_number" - Arg_VolumeCloneName = "pi_volume_clone_name" - Arg_VolumeCloneTaskID = "pi_volume_clone_task_id" - Arg_VolumeGroupAction = "pi_volume_group_action" - Arg_VolumeGroupID = "pi_volume_group_id" - Arg_VolumeGroupName = "pi_volume_group_name" - Arg_VolumeID = "pi_volume_id" - Arg_VolumeIDs = "pi_volume_ids" - Arg_VolumeName = "pi_volume_name" - Arg_VolumeOnboardingID = "pi_volume_onboarding_id" - Arg_VolumePool = "pi_volume_pool" - Arg_VolumeShareable = "pi_volume_shareable" - Arg_VolumeSize = "pi_volume_size" - Arg_VolumeSnapshotID = "pi_volume_snapshot_id" - Arg_VolumeType = "pi_volume_type" - Arg_VTL = "vtl" + Arg_Action = "pi_action" + Arg_AffinityInstance = "pi_affinity_instance" + Arg_AffinityPolicy = "pi_affinity_policy" + Arg_AffinityVolume = "pi_affinity_volume" + Arg_AntiAffinityInstances = "pi_anti_affinity_instances" + Arg_AntiAffinityVolumes = "pi_anti_affinity_volumes" + Arg_BootVolumeReplicationEnabled = "pi_boot_volume_replication_enabled" + Arg_Cidr = "pi_cidr" + Arg_CloudConnectionClassicEnabled = "pi_cloud_connection_classic_enabled" + Arg_CloudConnectionGlobalRouting = "pi_cloud_connection_global_routing" + Arg_CloudConnectionGreCidr = "pi_cloud_connection_gre_cidr" + Arg_CloudConnectionGreDestinationAddress = "pi_cloud_connection_gre_destination_address" + Arg_CloudConnectionID = "pi_cloud_connection_id" + Arg_CloudConnectionMetered = "pi_cloud_connection_metered" + Arg_CloudConnectionName = "pi_cloud_connection_name" + Arg_CloudConnectionNetworks = "pi_cloud_connection_networks" + Arg_CloudConnectionSpeed = "pi_cloud_connection_speed" + Arg_CloudConnectionTransitEnabled = "pi_cloud_connection_transit_enabled" + Arg_CloudConnectionVPCCRNs = "pi_cloud_connection_vpc_crns" + Arg_CloudConnectionVPCEnabled = "pi_cloud_connection_vpc_enabled" + Arg_CloudInstanceID = "pi_cloud_instance_id" + Arg_ConsistencyGroupName = "pi_consistency_group_name" + Arg_Datacenter = "pi_datacenter" + Arg_DatacenterZone = "pi_datacenter_zone" + Arg_DeploymentTarget = "pi_deployment_target" + Arg_DeploymentType = "pi_deployment_type" + Arg_Description = "pi_description" + Arg_DestinationPorts = "pi_destination_ports" + Arg_DhcpID = "pi_dhcp_id" + Arg_DhcpName = "pi_dhcp_name" + Arg_DhcpSnatEnabled = "pi_dhcp_snat_enabled" + Arg_DNS = "pi_dns" + Arg_DnsServer = "pi_dns_server" + Arg_EndingIPAddress = "pi_ending_ip_address" + Arg_Gateway = "pi_gateway" + Arg_HealthStatus = "pi_health_status" + Arg_Host = "pi_host" + Arg_HostGroupID = "pi_host_group_id" + Arg_HostID = "pi_host_id" + Arg_Hosts = "pi_hosts" + Arg_IBMiCSS = "pi_ibmi_css" + Arg_IBMiPHA = "pi_ibmi_pha" + Arg_IBMiRDSUsers = "pi_ibmi_rds_users" + Arg_ImageID = "pi_image_id" + Arg_ImageImportDetails = "pi_image_import_details" + Arg_ImageName = "pi_image_name" + Arg_InstanceID = "pi_instance_id" + Arg_InstanceName = "pi_instance_name" + Arg_IPAddress = "pi_ip_address" + Arg_IPAddressRange = "pi_ipaddress_range" + Arg_Key = "pi_ssh_key" + Arg_KeyName = "pi_key_name" + Arg_KeyPairName = "pi_key_pair_name" + Arg_LanguageCode = "pi_language_code" + Arg_LicenseRepositoryCapacity = "pi_license_repository_capacity" + Arg_Memory = "pi_memory" + Arg_Name = "pi_name" + Arg_Network = "pi_network" + Arg_NetworkAccessConfig = "pi_network_access_config" + Arg_NetworkAddressGroupID = "pi_network_address_group_id" + Arg_NetworkAddressGroupMemberID = "pi_network_address_group_member_id" + Arg_NetworkID = "pi_network_id" + Arg_NetworkInterfaceID = "pi_network_interface_id" + Arg_NetworkJumbo = "pi_network_jumbo" + Arg_NetworkMTU = "pi_network_mtu" + Arg_NetworkName = "pi_network_name" + Arg_NetworkPeer = "pi_network_peer" + Arg_NetworkSecurityGroupID = "pi_network_security_group_id" + Arg_NetworkSecurityGroupMemberID = "pi_network_security_group_member_id" + Arg_NetworkSecurityGroupRuleID = "pi_network_security_group_rule_id" + Arg_NetworkType = "pi_network_type" + Arg_PinPolicy = "pi_pin_policy" + Arg_PlacementGroupID = "pi_placement_group_id" + Arg_PlacementGroupName = "pi_placement_group_name" + Arg_PlacementGroupPolicy = "pi_placement_group_policy" + Arg_Plan = "pi_plan" + Arg_Processors = "pi_processors" + Arg_ProcType = "pi_proc_type" + Arg_Protocol = "pi_protocol" + Arg_PVMInstanceActionType = "pi_action" + Arg_PVMInstanceHealthStatus = "pi_health_status" + Arg_PVMInstanceId = "pi_instance_id" + Arg_Remote = "pi_remote" + Arg_Remove = "pi_remove" + Arg_Replicants = "pi_replicants" + Arg_ReplicationEnabled = "pi_replication_enabled" + Arg_ReplicationPolicy = "pi_replication_policy" + Arg_ReplicationScheme = "pi_replication_scheme" + Arg_ReplicationSites = "pi_replication_sites" + Arg_ResourceGroupID = "pi_resource_group_id" + Arg_RetainVirtualSerialNumber = "pi_retain_virtual_serial_number" + Arg_SAP = "sap" + Arg_SAPDeploymentType = "pi_sap_deployment_type" + Arg_SAPProfileID = "pi_sap_profile_id" + Arg_Secondaries = "pi_secondaries" + Arg_Serial = "pi_serial" + Arg_SharedProcessorPool = "pi_shared_processor_pool" + Arg_SharedProcessorPoolHostGroup = "pi_shared_processor_pool_host_group" + Arg_SharedProcessorPoolID = "pi_shared_processor_pool_id" + Arg_SharedProcessorPoolName = "pi_shared_processor_pool_name" + Arg_SharedProcessorPoolPlacementGroupID = "pi_shared_processor_pool_placement_group_id" + Arg_SharedProcessorPoolPlacementGroups = "pi_shared_processor_pool_placement_groups" + Arg_SharedProcessorPoolReservedCores = "pi_shared_processor_pool_reserved_cores" + Arg_SnapshotID = "pi_snapshot_id" + Arg_SnapShotName = "pi_snap_shot_name" + Arg_SnapshotName = "pi_snapshot_name" + Arg_SourcePorts = "pi_source_ports" + Arg_SPPPlacementGroupID = "pi_spp_placement_group_id" + Arg_SPPPlacementGroupName = "pi_spp_placement_group_name" + Arg_SPPPlacementGroupPolicy = "pi_spp_placement_group_policy" + Arg_SSHKey = "pi_ssh_key" + Arg_StartingIPAddress = "pi_starting_ip_address" + Arg_StorageConnection = "pi_storage_connection" + Arg_StoragePool = "pi_storage_pool" + Arg_StoragePoolAffinity = "pi_storage_pool_affinity" + Arg_StorageType = "pi_storage_type" + Arg_SysType = "pi_sys_type" + Arg_Target = "pi_target" + Arg_TargetStorageTier = "pi_target_storage_tier" + Arg_Type = "pi_type" + Arg_UserData = "pi_user_data" + Arg_UserTags = "pi_user_tags" + Arg_VirtualCoresAssigned = "pi_virtual_cores_assigned" + Arg_VirtualOpticalDevice = "pi_virtual_optical_device" + Arg_VirtualSerialNumber = "pi_virtual_serial_number" + Arg_VolumeCloneName = "pi_volume_clone_name" + Arg_VolumeCloneTaskID = "pi_volume_clone_task_id" + Arg_VolumeGroupAction = "pi_volume_group_action" + Arg_VolumeGroupID = "pi_volume_group_id" + Arg_VolumeGroupName = "pi_volume_group_name" + Arg_VolumeID = "pi_volume_id" + Arg_VolumeIDs = "pi_volume_ids" + Arg_VolumeName = "pi_volume_name" + Arg_VolumeOnboardingID = "pi_volume_onboarding_id" + Arg_VolumePool = "pi_volume_pool" + Arg_VolumeShareable = "pi_volume_shareable" + Arg_VolumeSize = "pi_volume_size" + Arg_VolumeSnapshotID = "pi_volume_snapshot_id" + Arg_VolumeType = "pi_volume_type" + Arg_VTL = "vtl" // Attributes Attr_Access = "access" @@ -485,15 +498,6 @@ const ( Attr_WorkspaceType = "pi_workspace_type" Attr_WWN = "wwn" - // Duplicate Attributes, will be removed as refactoring take course. - PICloudConnectionClassicGreSource = "gre_source_address" - PICloudConnectionConnectionMode = "connection_mode" - PICloudConnectionIBMIPAddress = "ibm_ip_address" - PICloudConnectionId = "cloud_connection_id" - PICloudConnectionPort = "port" - PICloudConnectionUserIPAddress = "user_ip_address" - PIVPNConnectionDeadPeerDetectionAction = "action" - // OS Type OS_IBMI = "ibmi" StockVTL = "stock-vtl" @@ -511,6 +515,7 @@ const ( Bidirectional_Static_Route = "bidirectional-static-route" BYOL = "byol" Capped = "capped" + Create = "create" Critical = "CRITICAL" CUSTOM_VIRTUAL_CORES = "custom-virtualcores" Dedicated = "dedicated" @@ -557,6 +562,7 @@ const ( TCP = "tcp" TimeExceeded = "time-exceeded" UDP = "udp" + Update = "update" UserTagType = "user" Vlan = "vlan" vSCSI = "vSCSI" @@ -610,21 +616,21 @@ const ( State_VerifyResize = "verify_resize" // Timeout values - Timeout_Active = 2 * time.Minute - Timeout_Delay = 60 * time.Second - Timeout_Warning = 60 * time.Second + Timeout_Active = 2 * time.Minute + Timeout_Delay = 60 * time.Second + Timeout_Warning = 60 * time.Second + vpcRetryCount = 2 + vpcRetryDuration = time.Minute // TODO: Second Half Cleanup, remove extra variables // VPN - PIVPNConnectionId = "connection_id" - PIVPNConnectionStatus = "connection_status" PIVPNConnectionDeadPeerDetection = "dead_peer_detections" + PIVPNConnectionDeadPeerDetectionAction = "action" PIVPNConnectionDeadPeerDetectionInterval = "interval" PIVPNConnectionDeadPeerDetectionThreshold = "threshold" + PIVPNConnectionId = "connection_id" PIVPNConnectionLocalGatewayAddress = "local_gateway_address" + PIVPNConnectionStatus = "connection_status" PIVPNConnectionVpnGatewayAddress = "gateway_address" - - // Cloud Connections - PICloudConnectionTransitEnabled = "pi_cloud_connection_transit_enabled" ) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection.go b/ibm/service/power/resource_ibm_pi_cloud_connection.go index 76da0e4932..f6eae40734 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection.go @@ -10,28 +10,22 @@ import ( "regexp" "time" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - st "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/power-go-client/errors" - "github.com/IBM-Cloud/power-go-client/helpers" "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_cloud_connections" "github.com/IBM-Cloud/power-go-client/power/models" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) var ( vpcUnavailable = regexp.MustCompile("pcloudCloudconnectionsPostServiceUnavailable|pcloudCloudconnectionsPutServiceUnavailable") ) -const ( - vpcRetryCount = 2 - vpcRetryDuration = time.Minute -) - func ResourceIBMPICloudConnection() *schema.Resource { return &schema.Resource{ CreateContext: resourceIBMPICloudConnectionCreate, @@ -47,118 +41,119 @@ func ResourceIBMPICloudConnection() *schema.Resource { }, Schema: map[string]*schema.Schema{ - // Required Attributes - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, - Description: "PI cloud instance ID", - }, - helpers.PICloudConnectionName: { - Type: schema.TypeString, - Required: true, - Description: "Name of the cloud connection", - }, - helpers.PICloudConnectionSpeed: { - Type: schema.TypeInt, - Required: true, - ValidateFunc: validate.ValidateAllowedIntValues([]int{50, 100, 200, 500, 1000, 2000, 5000, 10000}), - Description: "Speed of the cloud connection (speed in megabits per second)", - }, - - // Optional Attributes - helpers.PICloudConnectionGlobalRouting: { - Type: schema.TypeBool, + // Arguments + Arg_CloudConnectionClassicEnabled: { + Default: false, + Description: "Enable classic endpoint destination", Optional: true, + Type: schema.TypeBool, + }, + Arg_CloudConnectionGlobalRouting: { Default: false, Description: "Enable global routing for this cloud connection", - }, - helpers.PICloudConnectionMetered: { - Type: schema.TypeBool, Optional: true, + Type: schema.TypeBool, + }, + Arg_CloudConnectionGreCidr: { + Description: "GRE network in CIDR notation", + Optional: true, + RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionGreDestinationAddress}, + Type: schema.TypeString, + }, + Arg_CloudConnectionGreDestinationAddress: { + Description: "GRE destination IP address", + Optional: true, + RequiredWith: []string{Arg_CloudConnectionClassicEnabled, Arg_CloudConnectionGreCidr}, + Type: schema.TypeString, + }, + Arg_CloudConnectionMetered: { Default: false, Description: "Enable metered for this cloud connection", - }, - helpers.PICloudConnectionNetworks: { - Type: schema.TypeSet, Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Description: "Set of Networks to attach to this cloud connection", - }, - helpers.PICloudConnectionClassicEnabled: { Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "Enable classic endpoint destination", }, - helpers.PICloudConnectionClassicGreCidr: { + Arg_CloudConnectionName: { + Description: "Name of the cloud connection", + Required: true, Type: schema.TypeString, - Optional: true, - RequiredWith: []string{helpers.PICloudConnectionClassicEnabled, helpers.PICloudConnectionClassicGreDest}, - Description: "GRE network in CIDR notation", + ValidateFunc: validation.NoZeroValues, }, - helpers.PICloudConnectionClassicGreDest: { - Type: schema.TypeString, - Optional: true, - RequiredWith: []string{helpers.PICloudConnectionClassicEnabled, helpers.PICloudConnectionClassicGreCidr}, - Description: "GRE destination IP address", + Arg_CloudConnectionNetworks: { + Computed: true, + Description: "Set of Networks to attach to this cloud connection", + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + Type: schema.TypeSet, }, - helpers.PICloudConnectionVPCEnabled: { - Type: schema.TypeBool, - Optional: true, + Arg_CloudConnectionSpeed: { + Description: "Speed of the cloud connection (speed in megabits per second)", + Required: true, + Type: schema.TypeInt, + ValidateFunc: validate.ValidateAllowedIntValues([]int{50, 100, 200, 500, 1000, 2000, 5000, 10000}), + }, + Arg_CloudConnectionVPCEnabled: { Default: false, - RequiredWith: []string{helpers.PICloudConnectionVPCCRNs}, Description: "Enable VPC for this cloud connection", - }, - helpers.PICloudConnectionVPCCRNs: { - Type: schema.TypeSet, Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - RequiredWith: []string{helpers.PICloudConnectionVPCEnabled}, + RequiredWith: []string{Arg_CloudConnectionVPCCRNs}, + Type: schema.TypeBool, + }, + Arg_CloudConnectionVPCCRNs: { Description: "Set of VPCs to attach to this cloud connection", + Elem: &schema.Schema{Type: schema.TypeString}, + Optional: true, + RequiredWith: []string{Arg_CloudConnectionVPCEnabled}, + Type: schema.TypeSet, }, - PICloudConnectionTransitEnabled: { - Type: schema.TypeBool, - Optional: true, + Arg_CloudConnectionTransitEnabled: { Default: false, Description: "Enable transit gateway for this cloud connection", + Optional: true, + Type: schema.TypeBool, + }, + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + ForceNew: true, + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, }, - //Computed Attributes - PICloudConnectionId: { - Type: schema.TypeString, + // Attributes + Attr_CloudConnectionID: { Computed: true, Description: "Cloud connection ID", - }, - Attr_Status: { Type: schema.TypeString, + }, + Attr_ConnectionMode: { Computed: true, - Description: "Link status", + Description: "Type of service the gateway is attached to", + Type: schema.TypeString, }, - PICloudConnectionIBMIPAddress: { + Attr_GreSourceAddress: { + Computed: true, + Description: "GRE auto-assigned source IP address", Type: schema.TypeString, + }, + Attr_IBMIPAddress: { Computed: true, Description: "IBM IP address", - }, - PICloudConnectionUserIPAddress: { Type: schema.TypeString, - Computed: true, - Description: "User IP address", }, - PICloudConnectionPort: { - Type: schema.TypeString, + Attr_Port: { Computed: true, Description: "Port", - }, - PICloudConnectionClassicGreSource: { Type: schema.TypeString, - Computed: true, - Description: "GRE auto-assigned source IP address", }, - PICloudConnectionConnectionMode: { + Attr_Status: { + Computed: true, + Description: "Link status", Type: schema.TypeString, + }, + Attr_UserIPAddress: { Computed: true, - Description: "Type of service the gateway is attached to", + Description: "User IP address", + Type: schema.TypeString, }, }, } @@ -170,37 +165,37 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - name := d.Get(helpers.PICloudConnectionName).(string) - speed := int64(d.Get(helpers.PICloudConnectionSpeed).(int)) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + name := d.Get(Arg_CloudConnectionName).(string) + speed := int64(d.Get(Arg_CloudConnectionSpeed).(int)) body := &models.CloudConnectionCreate{ Name: &name, Speed: &speed, } - if v, ok := d.GetOk(helpers.PICloudConnectionGlobalRouting); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGlobalRouting); ok { body.GlobalRouting = v.(bool) } - if v, ok := d.GetOk(helpers.PICloudConnectionMetered); ok { + if v, ok := d.GetOk(Arg_CloudConnectionMetered); ok { body.Metered = v.(bool) } // networks - if v, ok := d.GetOk(helpers.PICloudConnectionNetworks); ok && v.(*schema.Set).Len() > 0 { + if v, ok := d.GetOk(Arg_CloudConnectionNetworks); ok && v.(*schema.Set).Len() > 0 { body.Subnets = flex.ExpandStringList(v.(*schema.Set).List()) } // classic - if v, ok := d.GetOk(helpers.PICloudConnectionClassicEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicEnabled); ok { classicEnabled := v.(bool) classic := &models.CloudConnectionEndpointClassicUpdate{ Enabled: classicEnabled, } gre := &models.CloudConnectionGRETunnelCreate{} - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreCidr); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGreCidr); ok { greCIDR := v.(string) gre.Cidr = &greCIDR classic.Gre = gre } - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreDest); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGreDestinationAddress); ok { greDest := v.(string) gre.DestIPAddress = &greDest classic.Gre = gre @@ -209,12 +204,12 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD } // VPC - if v, ok := d.GetOk(helpers.PICloudConnectionVPCEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionVPCEnabled); ok { vpcEnabled := v.(bool) vpc := &models.CloudConnectionEndpointVPC{ Enabled: vpcEnabled, } - if v, ok := d.GetOk(helpers.PICloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { + if v, ok := d.GetOk(Arg_CloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { vpcIds := flex.ExpandStringList(v.(*schema.Set).List()) vpcs := make([]*models.CloudConnectionVPC, len(vpcIds)) for i, vpcId := range vpcIds { @@ -229,18 +224,18 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD } // Transit Gateway - if v, ok := d.GetOk(PICloudConnectionTransitEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionTransitEnabled); ok { body.TransitEnabled = v.(bool) } - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) cloudConnection, cloudConnectionJob, err := client.Create(body) if err != nil { if vpcUnavailable.Match([]byte(err.Error())) { err = retryCloudConnectionsVPC(func() (err error) { cloudConnection, cloudConnectionJob, err = client.Create(body) return - }, "create", err) + }, Create, err) } if err != nil { log.Printf("[DEBUG] create cloud connection failed %v", err) @@ -255,7 +250,7 @@ func resourceIBMPICloudConnectionCreate(ctx context.Context, d *schema.ResourceD jobID := *cloudConnectionJob.JobRef.ID - client := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, err = waitForIBMPIJobCompleted(ctx, client, jobID, d.Timeout(schema.TimeoutCreate)) if err != nil { return diag.FromErr(err) @@ -279,39 +274,39 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD cloudInstanceID := parts[0] cloudConnectionID := parts[1] - ccName := d.Get(helpers.PICloudConnectionName).(string) - ccSpeed := int64(d.Get(helpers.PICloudConnectionSpeed).(int)) + ccName := d.Get(Arg_CloudConnectionName).(string) + ccSpeed := int64(d.Get(Arg_CloudConnectionSpeed).(int)) - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) - jobClient := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + jobClient := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) - if d.HasChangesExcept(helpers.PICloudConnectionNetworks) { + if d.HasChangesExcept(Arg_CloudConnectionNetworks) { body := &models.CloudConnectionUpdate{ Name: &ccName, Speed: &ccSpeed, } - if v, ok := d.GetOk(helpers.PICloudConnectionGlobalRouting); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGlobalRouting); ok { globalRouting := v.(bool) body.GlobalRouting = &globalRouting } - if v, ok := d.GetOk(helpers.PICloudConnectionMetered); ok { + if v, ok := d.GetOk(Arg_CloudConnectionMetered); ok { metered := v.(bool) body.Metered = &metered } // classic - if v, ok := d.GetOk(helpers.PICloudConnectionClassicEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionClassicEnabled); ok { classicEnabled := v.(bool) classic := &models.CloudConnectionEndpointClassicUpdate{ Enabled: classicEnabled, } gre := &models.CloudConnectionGRETunnelCreate{} - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreCidr); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGreCidr); ok { greCIDR := v.(string) gre.Cidr = &greCIDR classic.Gre = gre } - if v, ok := d.GetOk(helpers.PICloudConnectionClassicGreDest); ok { + if v, ok := d.GetOk(Arg_CloudConnectionGreDestinationAddress); ok { greDest := v.(string) gre.DestIPAddress = &greDest classic.Gre = gre @@ -325,12 +320,12 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD body.Classic = classic } // vpc - if v, ok := d.GetOk(helpers.PICloudConnectionVPCEnabled); ok { + if v, ok := d.GetOk(Arg_CloudConnectionVPCEnabled); ok { vpcEnabled := v.(bool) vpc := &models.CloudConnectionEndpointVPC{ Enabled: vpcEnabled, } - if v, ok := d.GetOk(helpers.PICloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { + if v, ok := d.GetOk(Arg_CloudConnectionVPCCRNs); ok && v.(*schema.Set).Len() > 0 { vpcIds := flex.ExpandStringList(v.(*schema.Set).List()) vpcs := make([]*models.CloudConnectionVPC, len(vpcIds)) for i, vpcId := range vpcIds { @@ -355,7 +350,7 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD err = retryCloudConnectionsVPC(func() (err error) { _, cloudConnectionJob, err = client.Update(cloudConnectionID, body) return - }, "update", err) + }, Update, err) } if err != nil { log.Printf("[DEBUG] update cloud connection failed %v", err) @@ -369,8 +364,8 @@ func resourceIBMPICloudConnectionUpdate(ctx context.Context, d *schema.ResourceD } } } - if d.HasChange(helpers.PICloudConnectionNetworks) { - oldRaw, newRaw := d.GetChange(helpers.PICloudConnectionNetworks) + if d.HasChange(Arg_CloudConnectionNetworks) { + oldRaw, newRaw := d.GetChange(Arg_CloudConnectionNetworks) old := oldRaw.(*schema.Set) new := newRaw.(*schema.Set) @@ -423,7 +418,7 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat cloudInstanceID := parts[0] cloudConnectionID := parts[1] - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) cloudConnection, err := client.Get(cloudConnectionID) if err != nil { uErr := errors.Unwrap(err) @@ -437,17 +432,17 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat return diag.FromErr(err) } - d.Set(PICloudConnectionId, cloudConnection.CloudConnectionID) - d.Set(helpers.PICloudConnectionName, cloudConnection.Name) - d.Set(helpers.PICloudConnectionGlobalRouting, cloudConnection.GlobalRouting) - d.Set(helpers.PICloudConnectionMetered, cloudConnection.Metered) - d.Set(PICloudConnectionIBMIPAddress, cloudConnection.IbmIPAddress) - d.Set(PICloudConnectionUserIPAddress, cloudConnection.UserIPAddress) + d.Set(Arg_CloudConnectionGlobalRouting, cloudConnection.GlobalRouting) + d.Set(Arg_CloudConnectionMetered, cloudConnection.Metered) + d.Set(Arg_CloudConnectionName, cloudConnection.Name) + d.Set(Arg_CloudConnectionSpeed, cloudConnection.Speed) + d.Set(Arg_CloudInstanceID, cloudInstanceID) + d.Set(Attr_CloudConnectionID, cloudConnection.CloudConnectionID) + d.Set(Attr_ConnectionMode, cloudConnection.ConnectionMode) + d.Set(Attr_IBMIPAddress, cloudConnection.IbmIPAddress) + d.Set(Attr_Port, cloudConnection.Port) d.Set(Attr_Status, cloudConnection.LinkStatus) - d.Set(PICloudConnectionPort, cloudConnection.Port) - d.Set(helpers.PICloudConnectionSpeed, cloudConnection.Speed) - d.Set(helpers.PICloudInstanceId, cloudInstanceID) - d.Set(PICloudConnectionConnectionMode, cloudConnection.ConnectionMode) + d.Set(Attr_UserIPAddress, cloudConnection.UserIPAddress) if cloudConnection.Networks != nil { networks := make([]string, 0) for _, ccNetwork := range cloudConnection.Networks { @@ -455,28 +450,29 @@ func resourceIBMPICloudConnectionRead(ctx context.Context, d *schema.ResourceDat networks = append(networks, *ccNetwork.NetworkID) } } - d.Set(helpers.PICloudConnectionNetworks, networks) + d.Set(Arg_CloudConnectionNetworks, networks) } if cloudConnection.Classic != nil { - d.Set(helpers.PICloudConnectionClassicEnabled, cloudConnection.Classic.Enabled) + d.Set(Arg_CloudConnectionClassicEnabled, cloudConnection.Classic.Enabled) if cloudConnection.Classic.Gre != nil { - d.Set(helpers.PICloudConnectionClassicGreDest, cloudConnection.Classic.Gre.DestIPAddress) - d.Set(PICloudConnectionClassicGreSource, cloudConnection.Classic.Gre.SourceIPAddress) + d.Set(Arg_CloudConnectionGreDestinationAddress, cloudConnection.Classic.Gre.DestIPAddress) + d.Set(Attr_GreSourceAddress, cloudConnection.Classic.Gre.SourceIPAddress) } } if cloudConnection.Vpc != nil { - d.Set(helpers.PICloudConnectionVPCEnabled, cloudConnection.Vpc.Enabled) + d.Set(Arg_CloudConnectionVPCEnabled, cloudConnection.Vpc.Enabled) if cloudConnection.Vpc.Vpcs != nil && len(cloudConnection.Vpc.Vpcs) > 0 { vpcCRNs := make([]string, len(cloudConnection.Vpc.Vpcs)) for i, vpc := range cloudConnection.Vpc.Vpcs { vpcCRNs[i] = *vpc.VpcID } - d.Set(helpers.PICloudConnectionVPCCRNs, vpcCRNs) + d.Set(Arg_CloudConnectionVPCCRNs, vpcCRNs) } } return nil } + func resourceIBMPICloudConnectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { @@ -491,7 +487,7 @@ func resourceIBMPICloudConnectionDelete(ctx context.Context, d *schema.ResourceD cloudInstanceID := parts[0] cloudConnectionID := parts[1] - client := st.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(ctx, sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err != nil { uErr := errors.Unwrap(err) @@ -513,8 +509,7 @@ func resourceIBMPICloudConnectionDelete(ctx context.Context, d *schema.ResourceD } if deleteJob != nil { jobID := *deleteJob.ID - - client := st.NewIBMPIJobClient(ctx, sess, cloudInstanceID) + client := instance.NewIBMPIJobClient(ctx, sess, cloudInstanceID) _, err = waitForIBMPIJobCompleted(ctx, client, jobID, d.Timeout(schema.TimeoutDelete)) if err != nil { return diag.FromErr(err) diff --git a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go index a70f85763f..34888b126b 100644 --- a/ibm/service/power/resource_ibm_pi_cloud_connection_test.go +++ b/ibm/service/power/resource_ibm_pi_cloud_connection_test.go @@ -10,14 +10,13 @@ import ( "testing" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + + "github.com/IBM-Cloud/power-go-client/clients/instance" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - - st "github.com/IBM-Cloud/power-go-client/clients/instance" ) func TestAccIBMPICloudConnectionbasic(t *testing.T) { @@ -42,6 +41,7 @@ func TestAccIBMPICloudConnectionbasic(t *testing.T) { }, }) } + func testAccCheckIBMPICloudConnectionDestroy(s *terraform.State) error { sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession() if err != nil { @@ -55,7 +55,7 @@ func testAccCheckIBMPICloudConnectionDestroy(s *terraform.State) error { if err != nil { return err } - client := st.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err == nil { return fmt.Errorf("Cloud Connection still exists: %s", rs.Primary.ID) @@ -63,6 +63,7 @@ func testAccCheckIBMPICloudConnectionDestroy(s *terraform.State) error { } return nil } + func splitID(id string) (id1, id2 string, err error) { parts, err := flex.IdParts(id) if err != nil { @@ -72,6 +73,7 @@ func splitID(id string) (id1, id2 string, err error) { id2 = parts[1] return } + func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -90,7 +92,7 @@ func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc { if err != nil { return err } - client := st.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPICloudConnectionClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(cloudConnectionID) if err != nil { @@ -100,21 +102,22 @@ func testAccCheckIBMPICloudConnectionExists(n string) resource.TestCheckFunc { return nil } } + func testAccCheckIBMPICloudConnectionConfig(name string) string { return fmt.Sprintf(` - resource "ibm_pi_cloud_connection" "cloud_connection" { - pi_cloud_instance_id = "%[1]s" - pi_cloud_connection_name = "%[2]s" - pi_cloud_connection_speed = 100 - pi_cloud_connection_networks = [ibm_pi_network.network1.network_id] - } - resource "ibm_pi_network" "network1" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s" - pi_network_type = "vlan" - pi_cidr = "192.112.111.0/24" - } - `, acc.Pi_cloud_instance_id, name) + resource "ibm_pi_cloud_connection" "cloud_connection" { + pi_cloud_instance_id = "%[1]s" + pi_cloud_connection_name = "%[2]s" + pi_cloud_connection_speed = 100 + pi_cloud_connection_networks = [ibm_pi_network.network1.network_id] + } + resource "ibm_pi_network" "network1" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s" + pi_network_type = "vlan" + pi_cidr = "192.112.111.0/24" + } + `, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionNetworks(t *testing.T) { @@ -150,48 +153,48 @@ func TestAccIBMPICloudConnectionNetworks(t *testing.T) { func testAccCheckIBMPICloudConnectionNetworkConfig(name string) string { return fmt.Sprintf(` - resource "ibm_pi_cloud_connection" "cc_network" { - pi_cloud_instance_id = "%[1]s" - pi_cloud_connection_name = "%[2]s" - pi_cloud_connection_speed = 1000 - pi_cloud_connection_networks = [ibm_pi_network.network1.network_id] - } - resource "ibm_pi_network" "network1" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s_net1" - pi_network_type = "vlan" - pi_cidr = "192.112.112.0/24" - } - resource "ibm_pi_network" "network2" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s_net2" - pi_network_type = "vlan" - pi_cidr = "192.112.113.0/24" - } - `, acc.Pi_cloud_instance_id, name) + resource "ibm_pi_cloud_connection" "cc_network" { + pi_cloud_instance_id = "%[1]s" + pi_cloud_connection_name = "%[2]s" + pi_cloud_connection_speed = 1000 + pi_cloud_connection_networks = [ibm_pi_network.network1.network_id] + } + resource "ibm_pi_network" "network1" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s_net1" + pi_network_type = "vlan" + pi_cidr = "192.112.112.0/24" + } + resource "ibm_pi_network" "network2" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s_net2" + pi_network_type = "vlan" + pi_cidr = "192.112.113.0/24" + } + `, acc.Pi_cloud_instance_id, name) } func testAccCheckIBMPICloudConnectionNetworkUpdateConfig(name string) string { return fmt.Sprintf(` - resource "ibm_pi_cloud_connection" "cc_network" { - pi_cloud_instance_id = "%[1]s" - pi_cloud_connection_name = "%[2]s" - pi_cloud_connection_speed = 1000 - pi_cloud_connection_networks = [ibm_pi_network.network2.network_id] - } - resource "ibm_pi_network" "network1" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s_net1" - pi_network_type = "vlan" - pi_cidr = "192.112.112.0/24" - } - resource "ibm_pi_network" "network2" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s_net2" - pi_network_type = "vlan" - pi_cidr = "192.112.113.0/24" - } - `, acc.Pi_cloud_instance_id, name) + resource "ibm_pi_cloud_connection" "cc_network" { + pi_cloud_instance_id = "%[1]s" + pi_cloud_connection_name = "%[2]s" + pi_cloud_connection_speed = 1000 + pi_cloud_connection_networks = [ibm_pi_network.network2.network_id] + } + resource "ibm_pi_network" "network1" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s_net1" + pi_network_type = "vlan" + pi_cidr = "192.112.112.0/24" + } + resource "ibm_pi_network" "network2" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s_net2" + pi_network_type = "vlan" + pi_cidr = "192.112.113.0/24" + } + `, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionClassic(t *testing.T) { @@ -218,15 +221,16 @@ func TestAccIBMPICloudConnectionClassic(t *testing.T) { }, }) } + func testAccCheckIBMPICloudConnectionClassicConfig(name string) string { return fmt.Sprintf(` - resource "ibm_pi_cloud_connection" "classic" { - pi_cloud_instance_id = "%[1]s" - pi_cloud_connection_name = "%[2]s" - pi_cloud_connection_speed = 50 - pi_cloud_connection_classic_enabled = true - } - `, acc.Pi_cloud_instance_id, name) + resource "ibm_pi_cloud_connection" "classic" { + pi_cloud_instance_id = "%[1]s" + pi_cloud_connection_name = "%[2]s" + pi_cloud_connection_speed = 50 + pi_cloud_connection_classic_enabled = true + } + `, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionVPC(t *testing.T) { @@ -258,14 +262,14 @@ func TestAccIBMPICloudConnectionVPC(t *testing.T) { func testAccCheckIBMPICloudConnectionVPCConfig(name string) string { return fmt.Sprintf(` - resource "ibm_pi_cloud_connection" "vpc" { - pi_cloud_instance_id = "%[1]s" - pi_cloud_connection_name = "%[2]s" - pi_cloud_connection_speed = 50 - pi_cloud_connection_vpc_enabled = true - pi_cloud_connection_vpc_crns = ["crn:v1:bluemix:public:is:us-south:a/d9cec80d0adc400ead8e2076afe26698::vpc:r006-6486cf73-451d-4d44-b90d-83dff504cbed"] - } - `, acc.Pi_cloud_instance_id, name) + resource "ibm_pi_cloud_connection" "vpc" { + pi_cloud_instance_id = "%[1]s" + pi_cloud_connection_name = "%[2]s" + pi_cloud_connection_speed = 50 + pi_cloud_connection_vpc_enabled = true + pi_cloud_connection_vpc_crns = ["crn:v1:bluemix:public:is:us-south:a/d9cec80d0adc400ead8e2076afe26698::vpc:r006-6486cf73-451d-4d44-b90d-83dff504cbed"] + } + `, acc.Pi_cloud_instance_id, name) } func TestAccIBMPICloudConnectionTransitGateway(t *testing.T) { @@ -295,18 +299,18 @@ func TestAccIBMPICloudConnectionTransitGateway(t *testing.T) { func testAccCheckIBMPICloudConnectionConfigTransitGateway(name string) string { return fmt.Sprintf(` - resource "ibm_pi_cloud_connection" "cloud_connection_transit" { - pi_cloud_instance_id = "%[1]s" - pi_cloud_connection_name = "%[2]s" - pi_cloud_connection_speed = 100 - pi_cloud_connection_networks = [ibm_pi_network.network1.network_id] - pi_cloud_connection_transit_enabled = true - } - resource "ibm_pi_network" "network1" { - pi_cloud_instance_id = "%[1]s" - pi_network_name = "%[2]s" - pi_network_type = "vlan" - pi_cidr = "192.112.111.0/24" - } - `, acc.Pi_cloud_instance_id, name) + resource "ibm_pi_cloud_connection" "cloud_connection_transit" { + pi_cloud_instance_id = "%[1]s" + pi_cloud_connection_name = "%[2]s" + pi_cloud_connection_speed = 100 + pi_cloud_connection_networks = [ibm_pi_network.network1.network_id] + pi_cloud_connection_transit_enabled = true + } + resource "ibm_pi_network" "network1" { + pi_cloud_instance_id = "%[1]s" + pi_network_name = "%[2]s" + pi_network_type = "vlan" + pi_cidr = "192.112.111.0/24" + } + `, acc.Pi_cloud_instance_id, name) } diff --git a/website/docs/d/pi_cloud_connection.html.markdown b/website/docs/d/pi_cloud_connection.html.markdown index 2e6de4d4bd..173b7f983d 100644 --- a/website/docs/d/pi_cloud_connection.html.markdown +++ b/website/docs/d/pi_cloud_connection.html.markdown @@ -7,23 +7,27 @@ description: |- --- # ibm_pi_cloud_connection + Retrieve information about an existing IBM Cloud Power Virtual Server Cloud cloud connection. For more information, about IBM power virtual server cloud, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage + ```terraform data "ibm_pi_cloud_connection" "example" { - pi_cloud_connection_name = "test_cloud_connection" - pi_cloud_instance_id = "" + pi_cloud_connection_name = "test_cloud_connection" + pi_cloud_instance_id = "" } ``` -**Notes** +### Notes + - Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. - If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - `region` - `lon` - `zone` - `lon04` Example usage: + ```terraform provider "ibm" { region = "lon" @@ -32,12 +36,14 @@ Example usage: ``` ## Argument reference + Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_cloud_connection_name` - (Required, String) The cloud connection name to be used. ## Attribute reference + In addition to all argument reference list, you can access the following attribute references after your data source is created. - `classic_enabled` - (Boolean) Enable classic endpoint destination. diff --git a/website/docs/d/pi_cloud_connections.html.markdown b/website/docs/d/pi_cloud_connections.html.markdown index 0ab04e36da..8dad7a411c 100644 --- a/website/docs/d/pi_cloud_connections.html.markdown +++ b/website/docs/d/pi_cloud_connections.html.markdown @@ -7,16 +7,19 @@ description: |- --- # ibm_pi_cloud_connections + Retrieve information about all cloud connections as a read-only data source. For more information, about IBM power virtual server cloud, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). ## Example usage + ```terraform data "ibm_pi_cloud_connections" "example" { - pi_cloud_instance_id = "" + pi_cloud_instance_id = "" } ``` -**Notes** +### Notes + - Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. - If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: @@ -24,6 +27,7 @@ data "ibm_pi_cloud_connections" "example" { - `zone` - `lon04` Example usage: + ```terraform provider "ibm" { region = "lon" @@ -32,11 +36,13 @@ Example usage: ``` ## Argument reference + Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. ## Attribute reference + In addition to all argument reference list, you can access the following attribute references after your data source is created. - `connections` - (List) List of all the Cloud Connections. diff --git a/website/docs/r/pi_cloud_connection.html.markdown b/website/docs/r/pi_cloud_connection.html.markdown index 2bd9284239..0c14578a1f 100644 --- a/website/docs/r/pi_cloud_connection.html.markdown +++ b/website/docs/r/pi_cloud_connection.html.markdown @@ -10,30 +10,28 @@ description: |- Create, update, or delete for a Power Systems Virtual Server cloud connection. For more information, about IBM power virtual server cloud, see [getting started with IBM Power Systems Virtual Servers](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-getting-started). -**Note** +~> **NOTE:** `Cloud connection` are not supported in **new** workspaces in `DAL10 data center.` -`Cloud connection are not supported in new workspaces in DAL10 data center.` ## Example usage The following example enables you to create a cloud connection: ```terraform resource "ibm_pi_cloud_connection" "cloud_connection" { - pi_cloud_instance_id = "" - pi_cloud_connection_name = "test_cloud_connection" - pi_cloud_connection_speed = 50 + pi_cloud_instance_id = "" + pi_cloud_connection_name = "test_cloud_connection" + pi_cloud_connection_speed = 50 } ``` -**Note** +### Notes - Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. - If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - - `region` - `lon` - `zone` - `lon04` - Example usage: +Example usage: ```terraform provider "ibm" { @@ -46,15 +44,14 @@ resource "ibm_pi_cloud_connection" "cloud_connection" { The `ibm_pi_cloud_connection` provides the following [timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options: -- **Create** The creation of the cloud connection is considered failed if no response is received for 30 minutes. -- **Update** The updation of the cloud connection is considered failed if no response is received for 30 minutes. -- **Delete** The deletion of the cloud connection is considered failed if no response is received for 30 minutes. +- **create** - (Default 30 minutes) Used for creating cloud connection. +- **update** - (Default 30 minutes) Used for updating cloud connection. +- **delete** - (Default 30 minutes) Used for deleting cloud connection. ## Argument reference Review the argument references that you can specify for your resource. -- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_cloud_connection_classic_enabled` - (Optional, Bool) Enable classic endpoint destination. - `pi_cloud_connection_global_routing` - (Optional, Bool) Enable global routing for this cloud connection. - `pi_cloud_connection_gre_cidr` - (Optional, String) The GRE network in CIDR notation. @@ -63,19 +60,20 @@ Review the argument references that you can specify for your resource. - `pi_cloud_connection_name` - (Required, String) The name of the cloud connection. - `pi_cloud_connection_networks` - (Optional, Set of String) Set of Networks to attach to this cloud connection. - `pi_cloud_connection_speed` - (Required, String) Speed of the cloud connection (speed in megabits per second). Supported values are `50`, `100`, `200`, `500`, `1000`, `2000`, `5000`, `10000`. -- `pi_cloud_connection_vpc_enabled` - (Optional, Bool) Enable VPC for this cloud connection. -- `pi_cloud_connection_vpc_crns` - (Optional, Set of String) Set of VPC CRNs to attach to this cloud connection. - `pi_cloud_connection_transit_enabled` - (Optional, Bool) Enable transit gateway for this cloud connection. +- `pi_cloud_connection_vpc_crns` - (Optional, Set of String) Set of VPC CRNs to attach to this cloud connection. +- `pi_cloud_connection_vpc_enabled` - (Optional, Bool) Enable VPC for this cloud connection. +- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. ## Attribute reference In addition to all argument reference list, you can access the following attribute reference after your resource is created. -- `id` - (String) The unique identifier of cloud connection. - `cloud_connection_id` - (String) The cloud connection ID. - `connection_mode` - (String) Type of service the gateway is attached to. - `gre_source_address` - (String) The GRE auto-assigned source IP address. - `ibm_ip_address` - (String) The IBM IP address. +- `id` - (String) The unique identifier of cloud connection. - `port` - (String) Port. - `status` - (String) Link status. - `user_ip_address` - (String) User IP address. @@ -84,8 +82,8 @@ In addition to all argument reference list, you can access the following attribu The `ibm_pi_cloud_connection` can be imported by using `power_instance_id` and `cloud_connection_id`. -**Example** +### Example -```sh -$ terraform import ibm_pi_cloud_connection.example d7bec597-4726-451f-8a63-e62e6f19c32c/cea6651a-bc0a-4438-9f8a-a0770bbf3ebb +```bash +terraform import ibm_pi_cloud_connection.example d7bec597-4726-451f-8a63-e62e6f19c32c/cea6651a-bc0a-4438-9f8a-a0770bbf3ebb ```