diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 53513daffce..45c39a5ce31 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -25,7 +25,10 @@ const ( 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" @@ -40,6 +43,7 @@ const ( 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" @@ -48,15 +52,19 @@ const ( 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" @@ -91,6 +99,7 @@ const ( 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" @@ -447,59 +456,64 @@ const ( StockVTL = "stock-vtl" // Allowed Values - Affinity = "affinity" - All = "all" - Allow = "allow" - AntiAffinity = "anti-affinity" - Attach = "attach" - BYOL = "byol" - Capped = "capped" - Critical = "CRITICAL" - CUSTOM_VIRTUAL_CORES = "custom-virtualcores" - Dedicated = "dedicated" - DefaultNAG = "default-network-address-group" - Deny = "deny" - DeploymentTypeEpic = "EPIC" - DeploymentTypeVMNoStorage = "VMNoStorage" - DestinationUnreach = "destination-unreach" - DHCPVlan = "dhcp-vlan" - Disable = "disable" - Echo = "echo" - EchoReply = "echo-reply" - Enable = "enable" - Hana = "Hana" - Hard = "hard" - Host = "host" - HostGroup = "hostGroup" - ICMP = "icmp" - IPV4_Address = "ipv4-address" - L2 = "L2" - L3BGP = "L3BGP" - L3Static = "L3Static" - MaxVolumeSupport = "maxVolumeSupport" - NAG = "network-address-group" - Netweaver = "Netweaver" - Network_Interface = "network-interface" - None = "none" - NSG = "network-security-group" - OK = "OK" - PER = "power-edge-router" - Prefix = "prefix" - Private = "private" - Public = "public" - PubVlan = "pub-vlan" - SAP = "SAP" - Shared = "shared" - Soft = "soft" - SourceQuench = "source-quench" - Suffix = "suffix" - TCP = "tcp" - TimeExceeded = "time-exceeded" - UDP = "udp" - UserTagType = "user" - Vlan = "vlan" - vSCSI = "vSCSI" - Warning = "WARNING" + Affinity = "affinity" + All = "all" + Allow = "allow" + AntiAffinity = "anti-affinity" + Attach = "attach" + Bidirectional_BGP = "bidirectional-bgp" + Bidirectional_L2Out = "bidirectional-l2out" + Bidirectional_Static_Route = "bidirectional-static-route" + BYOL = "byol" + Capped = "capped" + Critical = "CRITICAL" + CUSTOM_VIRTUAL_CORES = "custom-virtualcores" + Dedicated = "dedicated" + DefaultNAG = "default-network-address-group" + Deny = "deny" + DeploymentTypeEpic = "EPIC" + DeploymentTypeVMNoStorage = "VMNoStorage" + DestinationUnreach = "destination-unreach" + DHCPVlan = "dhcp-vlan" + Disable = "disable" + Echo = "echo" + EchoReply = "echo-reply" + Enable = "enable" + Hana = "Hana" + Hard = "hard" + Host = "host" + HostGroup = "hostGroup" + ICMP = "icmp" + Internal_Only = "internal-only" + IPV4_Address = "ipv4-address" + L2 = "L2" + L3BGP = "L3BGP" + L3Static = "L3Static" + MaxVolumeSupport = "maxVolumeSupport" + NAG = "network-address-group" + Netweaver = "Netweaver" + Network_Interface = "network-interface" + None = "none" + NSG = "network-security-group" + OK = "OK" + Outbound_Only = "outbound-only" + PER = "power-edge-router" + Prefix = "prefix" + Private = "private" + Public = "public" + PubVlan = "pub-vlan" + SAP = "SAP" + Shared = "shared" + Soft = "soft" + SourceQuench = "source-quench" + Suffix = "suffix" + TCP = "tcp" + TimeExceeded = "time-exceeded" + UDP = "udp" + UserTagType = "user" + Vlan = "vlan" + vSCSI = "vSCSI" + Warning = "WARNING" // Actions Action_HardReboot = "hard-reboot" diff --git a/ibm/service/power/resource_ibm_pi_network.go b/ibm/service/power/resource_ibm_pi_network.go index b336156aa9b..c954f1172c0 100644 --- a/ibm/service/power/resource_ibm_pi_network.go +++ b/ibm/service/power/resource_ibm_pi_network.go @@ -11,24 +11,18 @@ import ( "strconv" "time" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "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/apparentlymart/go-cidr/cidr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - - "github.com/IBM-Cloud/power-go-client/clients/instance" - "github.com/IBM-Cloud/power-go-client/helpers" - "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" -) - -const ( - piEndingIPAaddress = "pi_ending_ip_address" - piStartingIPAaddress = "pi_starting_ip_address" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) func ResourceIBMPINetwork() *schema.Resource { @@ -51,58 +45,82 @@ func ResourceIBMPINetwork() *schema.Resource { ), Schema: map[string]*schema.Schema{ - helpers.PINetworkType: { - Type: schema.TypeString, - Required: true, - ValidateFunc: validate.ValidateAllowedStringValues([]string{DHCPVlan, PubVlan, Vlan}), - Description: "PI network type", - }, - helpers.PINetworkName: { + // Arguments + Arg_Cidr: { + Computed: true, + Description: "The network CIDR. Required for `vlan` network type.", + Optional: true, Type: schema.TypeString, - Required: true, - Description: "PI network name", }, - helpers.PINetworkDNS: { - Type: schema.TypeSet, - Optional: true, + Arg_CloudInstanceID: { + Description: "The GUID of the service instance associated with an account.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, + Arg_DNS: { Computed: true, + Description: "The DNS Servers for the network.", Elem: &schema.Schema{Type: schema.TypeString}, - Description: "List of PI network DNS name", - }, - helpers.PINetworkCidr: { - Type: schema.TypeString, Optional: true, - Computed: true, - Description: "PI network CIDR", + Type: schema.TypeSet, }, - helpers.PINetworkGateway: { - Type: schema.TypeString, + Arg_Gateway: { + Computed: true, + Description: "The gateway ip address.", Optional: true, + Type: schema.TypeString, + }, + Arg_IPAddressRange: { Computed: true, - Description: "PI network gateway", + Description: "List of one or more ip address range(s).", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Arg_EndingIPAddress: { + Description: "The ending ip address.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, + Arg_StartingIPAddress: { + Description: "The staring ip address.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, + }, + }, + Optional: true, + Type: schema.TypeList, }, - helpers.PINetworkJumbo: { - Type: schema.TypeBool, - Optional: true, + Arg_NetworkAccessConfig: { + Computed: true, + Deprecated: "This field is deprecated please use pi_network_peer instead", + Description: "The network communication configuration option of the network (for satellite locations only).", + Optional: true, + Type: schema.TypeString, + ValidateFunc: validate.ValidateAllowedStringValues([]string{Internal_Only, Outbound_Only, Bidirectional_Static_Route, Bidirectional_BGP, Bidirectional_L2Out}), + }, + Arg_NetworkJumbo: { Computed: true, + ConflictsWith: []string{Arg_NetworkMTU}, Deprecated: "This field is deprecated, use pi_network_mtu instead.", - ConflictsWith: []string{helpers.PINetworkMtu}, - Description: "PI network enable MTU Jumbo option", - }, - helpers.PINetworkMtu: { - Type: schema.TypeInt, + Description: "MTU Jumbo option of the network (for multi-zone locations only).", Optional: true, + Type: schema.TypeBool, + }, + Arg_NetworkMTU: { Computed: true, - ConflictsWith: []string{helpers.PINetworkJumbo}, - Description: "PI Maximum Transmission Unit", + ConflictsWith: []string{Arg_NetworkJumbo}, + Description: "Maximum Transmission Unit option of the network. Minimum is 1450 and maximum is 9000.", + Optional: true, + Type: schema.TypeInt, }, - helpers.PINetworkAccessConfig: { + Arg_NetworkName: { + Description: "The name of the network.", + Required: true, Type: schema.TypeString, - Optional: true, - Computed: true, - Deprecated: "This field is deprecated please use pi_network_peer instead", - ValidateFunc: validate.ValidateAllowedStringValues([]string{"internal-only", "outbound-only", "bidirectional-static-route", "bidirectional-bgp", "bidirectional-l2out"}), - Description: "PI network communication configuration", + ValidateFunc: validation.NoZeroValues, }, Arg_NetworkPeer: { Description: "Network peer information.", @@ -141,30 +159,11 @@ func ResourceIBMPINetwork() *schema.Resource { Optional: true, Type: schema.TypeList, }, - helpers.PICloudInstanceId: { - Type: schema.TypeString, - Required: true, - Description: "PI cloud instance ID", - }, - helpers.PINetworkIPAddressRange: { - Type: schema.TypeList, - Optional: true, - Computed: true, - Description: "List of one or more ip address range(s)", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - piEndingIPAaddress: { - Type: schema.TypeString, - Required: true, - Description: "Ending ip address", - }, - piStartingIPAaddress: { - Type: schema.TypeString, - Required: true, - Description: "Starting ip address", - }, - }, - }, + Arg_NetworkType: { + Description: "The type of network that you want to create. Valid values are `pub-vlan`, `vlan` and `dhcp-vlan`.", + Required: true, + Type: schema.TypeString, + ValidateFunc: validate.ValidateAllowedStringValues([]string{DHCPVlan, PubVlan, Vlan}), }, Arg_UserTags: { Computed: true, @@ -181,11 +180,6 @@ func ResourceIBMPINetwork() *schema.Resource { Description: "The CRN of this resource.", Type: schema.TypeString, }, - "network_id": { - Type: schema.TypeString, - Computed: true, - Description: "PI network ID", - }, Attr_NetworkAddressTranslation: { Computed: true, Description: "Contains the Network Address Translation Details (for on-prem locations only).", @@ -200,15 +194,20 @@ func ResourceIBMPINetwork() *schema.Resource { }, Type: schema.TypeList, }, + Attr_NetworkID: { + Computed: true, + Description: "The unique identifier of the network.", + Type: schema.TypeString, + }, Attr_PeerID: { Computed: true, Description: "Network Peer ID (for on-prem locations only).", Type: schema.TypeString, }, - "vlan_id": { - Type: schema.TypeFloat, + Attr_VLanID: { Computed: true, - Description: "VLAN Id value", + Description: "The ID of the VLAN that your network is attached to.", + Type: schema.TypeFloat, }, }, } @@ -219,15 +218,16 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met if err != nil { return diag.FromErr(err) } - cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string) - networkname := d.Get(helpers.PINetworkName).(string) - networktype := d.Get(helpers.PINetworkType).(string) + cloudInstanceID := d.Get(Arg_CloudInstanceID).(string) + networkname := d.Get(Arg_NetworkName).(string) + networktype := d.Get(Arg_NetworkType).(string) + client := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID) var body = &models.NetworkCreate{ Type: &networktype, Name: networkname, } - if v, ok := d.GetOk(helpers.PINetworkDNS); ok { + if v, ok := d.GetOk(Arg_DNS); ok { networkdns := flex.ExpandStringList((v.(*schema.Set)).List()) if len(networkdns) > 0 { body.DNSServers = networkdns @@ -236,14 +236,14 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met if tags, ok := d.GetOk(Arg_UserTags); ok { body.UserTags = flex.FlattenSet(tags.(*schema.Set)) } - if v, ok := d.GetOk(helpers.PINetworkJumbo); ok { + if v, ok := d.GetOk(Arg_NetworkJumbo); ok { body.Jumbo = v.(bool) } - if v, ok := d.GetOk(helpers.PINetworkMtu); ok { + if v, ok := d.GetOk(Arg_NetworkMTU); ok { var mtu int64 = int64(v.(int)) body.Mtu = &mtu } - if v, ok := d.GetOk(helpers.PINetworkAccessConfig); ok { + if v, ok := d.GetOk(Arg_NetworkAccessConfig); ok { body.AccessConfig = models.AccessConfig(v.(string)) } if _, ok := d.GetOk(Arg_NetworkPeer); ok { @@ -254,10 +254,10 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met if networktype == DHCPVlan || networktype == Vlan { var networkcidr string var ipBodyRanges []*models.IPAddressRange - if v, ok := d.GetOk(helpers.PINetworkCidr); ok { + if v, ok := d.GetOk(Arg_Cidr); ok { networkcidr = v.(string) } else { - return diag.Errorf("%s is required when %s is vlan", helpers.PINetworkCidr, helpers.PINetworkType) + return diag.Errorf("%s is required when %s is vlan", Arg_Cidr, Arg_NetworkType) } gateway, firstip, lastip, err := generateIPData(networkcidr) @@ -267,11 +267,11 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met ipBodyRanges = []*models.IPAddressRange{{EndingIPAddress: &lastip, StartingIPAddress: &firstip}} - if g, ok := d.GetOk(helpers.PINetworkGateway); ok { + if g, ok := d.GetOk(Arg_Gateway); ok { gateway = g.(string) } - if ips, ok := d.GetOk(helpers.PINetworkIPAddressRange); ok { + if ips, ok := d.GetOk(Arg_IPAddressRange); ok { ipBodyRanges = getIPAddressRanges(ips.([]interface{})) } @@ -279,6 +279,11 @@ func resourceIBMPINetworkCreate(ctx context.Context, d *schema.ResourceData, met body.Gateway = gateway body.Cidr = networkcidr } + + if _, ok := d.GetOk(Arg_Cidr); ok && networktype == PubVlan { + return diag.Errorf("%s cannot be set when %s is dhcp-vlan or vlan", Arg_Cidr, Arg_NetworkType) + } + if !sess.IsOnPrem() { wsclient := instance.NewIBMPIWorkspacesClient(ctx, sess, cloudInstanceID) wsData, err := wsclient.Get(cloudInstanceID) @@ -344,36 +349,36 @@ func resourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, meta } d.Set(Arg_UserTags, tags) } - d.Set("network_id", networkdata.NetworkID) - d.Set(helpers.PINetworkCidr, networkdata.Cidr) - d.Set(helpers.PINetworkDNS, networkdata.DNSServers) - d.Set("vlan_id", networkdata.VlanID) - d.Set(helpers.PINetworkName, networkdata.Name) - d.Set(helpers.PINetworkType, networkdata.Type) - d.Set(helpers.PINetworkJumbo, networkdata.Jumbo) - d.Set(helpers.PINetworkMtu, networkdata.Mtu) - d.Set(helpers.PINetworkAccessConfig, networkdata.AccessConfig) - d.Set(helpers.PINetworkGateway, networkdata.Gateway) - d.Set(Attr_PeerID, networkdata.PeerID) + d.Set(Arg_Cidr, networkdata.Cidr) + d.Set(Arg_DNS, networkdata.DNSServers) + d.Set(Arg_Gateway, networkdata.Gateway) + d.Set(Arg_NetworkAccessConfig, networkdata.AccessConfig) + d.Set(Arg_NetworkJumbo, networkdata.Jumbo) + d.Set(Arg_NetworkMTU, networkdata.Mtu) + d.Set(Arg_NetworkName, networkdata.Name) + d.Set(Arg_NetworkType, networkdata.Type) + d.Set(Attr_NetworkID, networkdata.NetworkID) networkAddressTranslation := []map[string]interface{}{} if networkdata.NetworkAddressTranslation != nil { natMap := networkAddressTranslationToMap(networkdata.NetworkAddressTranslation) networkAddressTranslation = append(networkAddressTranslation, natMap) } d.Set(Attr_NetworkAddressTranslation, networkAddressTranslation) + d.Set(Attr_PeerID, networkdata.PeerID) + d.Set(Attr_VLanID, networkdata.VlanID) ipRangesMap := []map[string]interface{}{} if networkdata.IPAddressRanges != nil { for _, n := range networkdata.IPAddressRanges { if n != nil { v := map[string]interface{}{ - piEndingIPAaddress: n.EndingIPAddress, - piStartingIPAaddress: n.StartingIPAddress, + Arg_EndingIPAddress: n.EndingIPAddress, + Arg_StartingIPAddress: n.StartingIPAddress, } ipRangesMap = append(ipRangesMap, v) } } } - d.Set(helpers.PINetworkIPAddressRange, ipRangesMap) + d.Set(Arg_IPAddressRange, ipRangesMap) return nil } @@ -389,27 +394,27 @@ func resourceIBMPINetworkUpdate(ctx context.Context, d *schema.ResourceData, met return diag.FromErr(err) } - if d.HasChanges(helpers.PINetworkName, helpers.PINetworkDNS, helpers.PINetworkGateway, helpers.PINetworkIPAddressRange) { + if d.HasChanges(Arg_NetworkName, Arg_DNS, Arg_Gateway, Arg_IPAddressRange) { networkC := instance.NewIBMPINetworkClient(ctx, sess, cloudInstanceID) body := &models.NetworkUpdate{ - DNSServers: flex.ExpandStringList((d.Get(helpers.PINetworkDNS).(*schema.Set)).List()), + DNSServers: flex.ExpandStringList((d.Get(Arg_DNS).(*schema.Set)).List()), } - networkType := d.Get(helpers.PINetworkType).(string) - if d.HasChange(helpers.PINetworkIPAddressRange) || d.HasChange(helpers.PINetworkGateway) { + networkType := d.Get(Arg_NetworkType).(string) + if d.HasChange(Arg_IPAddressRange) || d.HasChange(Arg_Gateway) { if networkType == Vlan { - if d.HasChange(helpers.PINetworkIPAddressRange) { - body.IPAddressRanges = getIPAddressRanges(d.Get(helpers.PINetworkIPAddressRange).([]interface{})) + if d.HasChange(Arg_IPAddressRange) { + body.IPAddressRanges = getIPAddressRanges(d.Get(Arg_IPAddressRange).([]interface{})) } - if d.HasChange(helpers.PINetworkGateway) { - body.Gateway = flex.PtrToString(d.Get(helpers.PINetworkGateway).(string)) + if d.HasChange(Arg_Gateway) { + body.Gateway = flex.PtrToString(d.Get(Arg_Gateway).(string)) } } else { return diag.Errorf("%v type does not allow ip-address range or gateway update", networkType) } } - if d.HasChange(helpers.PINetworkName) { - body.Name = flex.PtrToString(d.Get(helpers.PINetworkName).(string)) + if d.HasChange(Arg_NetworkName) { + body.Name = flex.PtrToString(d.Get(Arg_NetworkName).(string)) } _, err = networkC.Update(networkID, body) @@ -432,7 +437,6 @@ func resourceIBMPINetworkUpdate(ctx context.Context, d *schema.ResourceData, met } func resourceIBMPINetworkDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { - log.Printf("Calling the network delete functions. ") sess, err := meta.(conns.ClientSession).IBMPISession() if err != nil { @@ -460,9 +464,9 @@ func resourceIBMPINetworkDelete(ctx context.Context, d *schema.ResourceData, met } func isWaitForIBMPINetworkAvailable(ctx context.Context, client *instance.IBMPINetworkClient, id string, timeout time.Duration) (interface{}, error) { - stateConf := &resource.StateChangeConf{ - Pending: []string{"retry", helpers.PINetworkProvisioning}, - Target: []string{"NETWORK_READY"}, + stateConf := &retry.StateChangeConf{ + Pending: []string{State_Retry, State_Build}, + Target: []string{State_Available}, Refresh: isIBMPINetworkRefreshFunc(client, id), Timeout: timeout, Delay: 10 * time.Second, @@ -472,7 +476,7 @@ func isWaitForIBMPINetworkAvailable(ctx context.Context, client *instance.IBMPIN return stateConf.WaitForStateContext(ctx) } -func isIBMPINetworkRefreshFunc(client *instance.IBMPINetworkClient, id string) resource.StateRefreshFunc { +func isIBMPINetworkRefreshFunc(client *instance.IBMPINetworkClient, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { network, err := client.Get(id) if err != nil { @@ -480,10 +484,10 @@ func isIBMPINetworkRefreshFunc(client *instance.IBMPINetworkClient, id string) r } if network.VlanID != nil { - return network, "NETWORK_READY", nil + return network, State_Available, nil } - return network, helpers.PINetworkProvisioning, nil + return network, State_Build, nil } } @@ -531,8 +535,6 @@ func generateIPData(cdir string) (gway, firstip, lastip string, err error) { "31": 2, } - //subnetsize, _ := ipv4Net.Mask.Size() - gateway, err := cidr.Host(ipv4Net, 1) if err != nil { log.Printf("Failed to get the gateway for this cidr passed in %s", cdir) @@ -562,14 +564,15 @@ func getIPAddressRanges(ipAddressRanges []interface{}) []*models.IPAddressRange if v != nil { ipAddressRange := v.(map[string]interface{}) ipRange := &models.IPAddressRange{ - EndingIPAddress: flex.PtrToString(ipAddressRange[piEndingIPAaddress].(string)), - StartingIPAddress: flex.PtrToString(ipAddressRange[piStartingIPAaddress].(string)), + EndingIPAddress: flex.PtrToString(ipAddressRange[Arg_EndingIPAddress].(string)), + StartingIPAddress: flex.PtrToString(ipAddressRange[Arg_StartingIPAddress].(string)), } ipRanges = append(ipRanges, ipRange) } } return ipRanges } + func waitForPERWorkspaceActive(ctx context.Context, client *instance.IBMPIWorkspacesClient, id string, timeout time.Duration) (interface{}, error) { stateConf := &retry.StateChangeConf{ Pending: []string{State_Inactive, State_Configuring}, @@ -606,6 +609,7 @@ func isPERWorkspaceRefreshFunc(client *instance.IBMPIWorkspacesClient, id string return ws, State_Configuring, nil } } + func networkMapToNetworkCreatePeer(networkCreatePeerMap map[string]interface{}) *models.NetworkCreatePeer { ncp := &models.NetworkCreatePeer{} if networkCreatePeerMap[Attr_ID].(string) != "" { @@ -621,6 +625,7 @@ func networkMapToNetworkCreatePeer(networkCreatePeerMap map[string]interface{}) } return ncp } + func natMapToNetworkAddressTranslation(networkAddressTranslationMap map[string]interface{}) *models.NetworkAddressTranslation { nat := &models.NetworkAddressTranslation{} if networkAddressTranslationMap[Attr_SourceIP].(string) != "" { diff --git a/ibm/service/power/resource_ibm_pi_network_test.go b/ibm/service/power/resource_ibm_pi_network_test.go index a3cd335ac02..9cb6bad0c01 100644 --- a/ibm/service/power/resource_ibm_pi_network_test.go +++ b/ibm/service/power/resource_ibm_pi_network_test.go @@ -10,13 +10,12 @@ import ( "testing" acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/power-go-client/clients/instance" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "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 TestAccIBMPINetworkbasic(t *testing.T) { @@ -51,6 +50,7 @@ func TestAccIBMPINetworkbasic(t *testing.T) { }, }) } + func TestAccIBMPINetworkGatewaybasic(t *testing.T) { name := fmt.Sprintf("tf-pi-network-%d", acctest.RandIntRange(10, 100)) resource.Test(t, resource.TestCase{ @@ -221,7 +221,7 @@ func testAccCheckIBMPINetworkDestroy(s *terraform.State) error { if err != nil { return err } - networkC := st.NewIBMPINetworkClient(context.Background(), sess, cloudInstanceID) + networkC := instance.NewIBMPINetworkClient(context.Background(), sess, cloudInstanceID) _, err = networkC.Get(networkID) if err == nil { return fmt.Errorf("PI Network still exists: %s", rs.Primary.ID) @@ -252,7 +252,7 @@ func testAccCheckIBMPINetworkExists(n string) resource.TestCheckFunc { if err != nil { return err } - client := st.NewIBMPINetworkClient(context.Background(), sess, cloudInstanceID) + client := instance.NewIBMPINetworkClient(context.Background(), sess, cloudInstanceID) _, err = client.Get(networkID) if err != nil { @@ -286,10 +286,11 @@ func testAccCheckIBMPINetworkConfigUpdateDNS(name string) string { func testAccCheckIBMPINetworkGatewayConfig(name string) string { return fmt.Sprintf(` resource "ibm_pi_network" "power_networks" { - pi_cloud_instance_id = "%s" + pi_cloud_instance_id = "%s" + pi_cidr = "192.168.17.0/24" + pi_gateway = "192.168.17.1" pi_network_name = "%s" pi_network_type = "vlan" - pi_cidr = "192.168.17.0/24" } `, acc.Pi_cloud_instance_id, name) } @@ -311,10 +312,11 @@ func testAccCheckIBMPINetworkConfigGatewayUpdateDNS(name string) string { return fmt.Sprintf(` resource "ibm_pi_network" "power_networks" { pi_cloud_instance_id = "%s" + pi_cidr = "192.168.17.0/24" + pi_dns = ["127.0.0.1"] + pi_gateway = "192.168.17.2" pi_network_name = "%s" pi_network_type = "vlan" - pi_dns = ["127.0.0.1"] - pi_cidr = "192.168.17.0/24" pi_ipaddress_range { pi_ending_ip_address = "192.168.17.254" pi_starting_ip_address = "192.168.17.3" diff --git a/website/docs/r/pi_network.html.markdown b/website/docs/r/pi_network.html.markdown index e2ddbd8c0fd..e1fc79daf01 100644 --- a/website/docs/r/pi_network.html.markdown +++ b/website/docs/r/pi_network.html.markdown @@ -38,7 +38,7 @@ resource "ibm_pi_network" "power_networks" { - `region` - `lon` - `zone` - `lon04` - Example usage: +Example usage: ```terraform provider "ibm" { @@ -59,25 +59,24 @@ The `ibm_pi_network` provides the following [Timeouts](https://www.terraform.io/ Review the argument references that you can specify for your resource. +- `pi_cidr` - (Optional, String) The network CIDR. Required for `vlan` network type. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. -- `pi_network_name` - (Required, String) The name of the network. -- `pi_network_type` - (Required, String) The type of network that you want to create. Valid values are `pub-vlan`, `vlan` and `dhcp-vlan`. - `pi_dns` - (Optional, Set of String) The DNS Servers for the network. If not specified, default is 127.0.0.1 for 'vlan' (private network) and 9.9.9.9 for 'pub-vlan' (public network). A maximum of one DNS server can be specified for private networks in Power Edge Router workspaces. -- `pi_cidr` - (Optional, String) The network CIDR. Required for `vlan` network type. - `pi_gateway` - (Optional, String) The gateway ip address. -- `pi_ipaddress_range` - (Optional, List of Map) List of one or more ip address range. The `pi_ipaddress_range` object structure is documented below. - The `pi_ipaddress_range` block supports: +- `pi_ipaddress_range` - (Optional, List of Map) List of one or more ip address range(s). The `pi_ipaddress_range` object structure is documented below. The `pi_ipaddress_range` block supports: - `pi_ending_ip_address` - (Required, String) The ending ip address. - `pi_starting_ip_address` - (Required, String) The staring ip address. **Note** if the `pi_gateway` or `pi_ipaddress_range` is not provided, it will calculate the value based on CIDR respectively. -- `pi_network_jumbo` - (Deprecated, Optional, Bool) MTU Jumbo option of the network (for multi-zone locations only). -- `pi_network_mtu` - (Optional, Integer) Maximum Transmission Unit option of the network, min size = 1450 & max size = 9000. - `pi_network_access_config` - (Deprecated, Optional, String) The network communication configuration option of the network (for on-prem locations only). Please use `pi_network_peer`. +- `pi_network_jumbo` - (Deprecated, Optional, Bool) MTU Jumbo option of the network (for multi-zone locations only). +- `pi_network_mtu` - (Optional, Integer) Maximum Transmission Unit option of the network. Minimum is 1450 and maximum is 9000. +- `pi_network_name` - (Required, String) The name of the network. +- `pi_network_type` - (Required, String) The type of network that you want to create. Valid values are `pub-vlan`, `vlan` and `dhcp-vlan`. - `pi_network_peer` - (Optional, List) Network peer information (for on-prem locations only). Max items: 1. Nested schema for `pi_network_peer`: - `id` - (Required, String) ID of the network peer. - `network_address_translation` - (Optional, List) Contains the Network Address Translation Details. Max items: 1. - + Nested schema for `network_address_translation`: - `source_ip` - (Optional, String) source IP address, required if network peer type is `L3BGP` or `L3STATIC` and if NAT is enabled. - `type` - (Optional, String) Type of the network peer. Allowable values are: `L2`, `L3BGP`, `L3Static`. @@ -88,20 +87,20 @@ Review the argument references that you can specify for your resource. In addition to all argument reference list, you can access the following attribute reference after your resource is created. - `crn` - (String) The CRN of this resource. -- `id` - (String) The unique identifier of the network. The ID is composed of `/`. -- `network_id` - (String) The unique identifier of the network. +- `id` - (String) The unique identifier of the network. The ID is composed of `/`. - `network_address_translation` - (List) Contains the network address translation details (for on-prem locations only). Nested schema for `network_address_translation`: - `source_ip` - (String) source IP address. +- `network_id` - (String) The unique identifier of the network. - `peer_id` - (String) Network peer ID (for on-prem locations only). - `vlan_id` - (Integer) The ID of the VLAN that your network is attached to. ## Import -The `ibm_pi_network` resource can be imported by using `power_instance_id` and `network_id`. +The `ibm_pi_network` resource can be imported by using `pi_cloud_instance_id` and `network_id`. -## Example +### Example ```bash terraform import ibm_pi_network.example d7bec597-4726-451f-8a63-e62e6f19c32c/cea6651a-bc0a-4438-9f8a-a0770bbf3ebb