diff --git a/go.mod b/go.mod index 8cb87062ad..7dc3cae43d 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.4 require ( github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3 github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 - github.com/IBM-Cloud/power-go-client v1.9.0 + github.com/IBM-Cloud/power-go-client v1.10.0-beta5 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.4.4 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index 90f669e72b..e776ec717b 100644 --- a/go.sum +++ b/go.sum @@ -95,8 +95,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3/go.mod h1:/7h github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk= github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= -github.com/IBM-Cloud/power-go-client v1.9.0 h1:nnErpb/7TJQe8P7OfIlJPhSJVq5oyuCJlMje9Ry6XEY= -github.com/IBM-Cloud/power-go-client v1.9.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0= +github.com/IBM-Cloud/power-go-client v1.10.0-beta5 h1:K44Ua8faecM85dF4GQ1fdNIVH9pbW4rpOPCDnymCzbk= +github.com/IBM-Cloud/power-go-client v1.10.0-beta5/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0= github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw= github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4= github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs= diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 4c93778d71..fe4ec374ca 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -40,6 +40,7 @@ const ( Arg_DeploymentTarget = "pi_deployment_target" Arg_DeploymentType = "pi_deployment_type" Arg_Description = "pi_description" + Arg_DestinationPort = "pi_destination_port" Arg_DestinationPorts = "pi_destination_ports" Arg_DhcpID = "pi_dhcp_id" Arg_DhcpName = "pi_dhcp_name" @@ -127,6 +128,7 @@ const ( Arg_SnapShotName = "pi_snap_shot_name" Arg_SnapshotName = "pi_snapshot_name" Arg_SourceCRN = "pi_source_crn" + Arg_SourcePort = "pi_source_port" Arg_SourcePorts = "pi_source_ports" Arg_SPPPlacementGroupID = "pi_spp_placement_group_id" Arg_SPPPlacementGroupName = "pi_spp_placement_group_name" diff --git a/ibm/service/power/resource_ibm_pi_network_security_group_rule.go b/ibm/service/power/resource_ibm_pi_network_security_group_rule.go index 704e775de5..690a739ef8 100644 --- a/ibm/service/power/resource_ibm_pi_network_security_group_rule.go +++ b/ibm/service/power/resource_ibm_pi_network_security_group_rule.go @@ -49,8 +49,33 @@ func ResourceIBMPINetworkSecurityGroupRule() *schema.Resource { Type: schema.TypeString, ValidateFunc: validation.NoZeroValues, }, + Arg_DestinationPort: { + ConflictsWith: []string{Arg_DestinationPorts, Arg_NetworkSecurityGroupRuleID}, + Description: "Destination port ranges.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Maximum: { + Default: 65535, + Description: "The end of the port range, if applicable. If the value is not present then the default value of 65535 will be the maximum port number.", + Optional: true, + Type: schema.TypeInt, + }, + Attr_Minimum: { + Default: 1, + Description: "The start of the port range, if applicable. If the value is not present then the default value of 1 will be the minimum port number.", + Optional: true, + Type: schema.TypeInt, + }, + }, + }, + ForceNew: true, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + }, Arg_DestinationPorts: { - ConflictsWith: []string{Arg_NetworkSecurityGroupRuleID}, + ConflictsWith: []string{Arg_DestinationPort, Arg_NetworkSecurityGroupRuleID}, + Deprecated: "This field is deprecated. Please use 'pi_destination_port' instead.", Description: "Destination port ranges.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -80,7 +105,7 @@ func ResourceIBMPINetworkSecurityGroupRule() *schema.Resource { Type: schema.TypeString, }, Arg_NetworkSecurityGroupRuleID: { - ConflictsWith: []string{Arg_Action, Arg_DestinationPorts, Arg_Protocol, Arg_Remote, Arg_SourcePorts}, + ConflictsWith: []string{Arg_Action, Arg_DestinationPort, Arg_DestinationPorts, Arg_Protocol, Arg_Remote, Arg_SourcePort, Arg_SourcePorts}, Description: "The network security group rule id to remove.", ForceNew: true, Optional: true, @@ -147,8 +172,33 @@ func ResourceIBMPINetworkSecurityGroupRule() *schema.Resource { Optional: true, Type: schema.TypeList, }, + Arg_SourcePort: { + ConflictsWith: []string{Arg_NetworkSecurityGroupRuleID, Arg_SourcePorts}, + Description: "Source port ranges.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + Attr_Maximum: { + Default: 65535, + Description: "The end of the port range, if applicable. If the value is not present then the default value of 65535 will be the maximum port number.", + Optional: true, + Type: schema.TypeInt, + }, + Attr_Minimum: { + Default: 1, + Description: "The start of the port range, if applicable. If the value is not present then the default value of 1 will be the minimum port number.", + Optional: true, + Type: schema.TypeInt, + }, + }, + }, + ForceNew: true, + MaxItems: 1, + Optional: true, + Type: schema.TypeList, + }, Arg_SourcePorts: { - ConflictsWith: []string{Arg_NetworkSecurityGroupRuleID}, + ConflictsWith: []string{Arg_NetworkSecurityGroupRuleID, Arg_SourcePort}, + Deprecated: "This field is deprecated. 'Please use pi_source_port' instead.", Description: "Source port ranges.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ @@ -378,11 +428,21 @@ func resourceIBMPINetworkSecurityGroupRuleCreate(ctx context.Context, d *schema. networkSecurityGroupAddRule.Remote = networkSecurityGroupRuleMapToRemote(remote) // Optional fields - destinationPort := d.Get(Arg_DestinationPorts + ".0").(map[string]interface{}) - networkSecurityGroupAddRule.DestinationPorts = networkSecurityGroupRuleMapToPort(destinationPort) + if _, ok := d.GetOk(Arg_DestinationPorts); ok { + destinationPort := d.Get(Arg_DestinationPorts + ".0").(map[string]interface{}) + networkSecurityGroupAddRule.DestinationPorts = networkSecurityGroupRuleMapToPort(destinationPort) + } else { + destinationPort := d.Get(Arg_DestinationPort + ".0").(map[string]interface{}) + networkSecurityGroupAddRule.DestinationPort = networkSecurityGroupRuleMapToPort(destinationPort) + } - sourcePort := d.Get(Arg_SourcePorts + ".0").(map[string]interface{}) - networkSecurityGroupAddRule.SourcePorts = networkSecurityGroupRuleMapToPort(sourcePort) + if _, ok := d.GetOk(Arg_SourcePorts); ok { + sourcePort := d.Get(Arg_SourcePorts + ".0").(map[string]interface{}) + networkSecurityGroupAddRule.SourcePorts = networkSecurityGroupRuleMapToPort(sourcePort) + } else { + sourcePort := d.Get(Arg_SourcePort + ".0").(map[string]interface{}) + networkSecurityGroupAddRule.SourcePort = networkSecurityGroupRuleMapToPort(sourcePort) + } networkSecurityGroup, err := nsgClient.AddRule(nsgID, &networkSecurityGroupAddRule) ruleID := *networkSecurityGroup.ID diff --git a/ibm/service/power/resource_ibm_pi_network_security_group_rule_test.go b/ibm/service/power/resource_ibm_pi_network_security_group_rule_test.go index f6234b2abf..274c9045ee 100644 --- a/ibm/service/power/resource_ibm_pi_network_security_group_rule_test.go +++ b/ibm/service/power/resource_ibm_pi_network_security_group_rule_test.go @@ -50,6 +50,26 @@ func TestAccIBMPINetworkSecurityGroupRuleTCP(t *testing.T) { }) } +func TestAccIBMPINetworkSecurityGroupRulePorts(t *testing.T) { + destinationPortBegin := "1200" + sourcePortBegin := "1000" + destinationPortEnd := "2000" + sourcePortEnd := "2000" + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMPINetworkSecurityGroupRuleConfigPorts(sourcePortBegin, sourcePortEnd, destinationPortBegin, destinationPortEnd), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPINetworkSecurityGroupRuleExists("ibm_pi_network_security_group_rule.network_security_group_rule"), + resource.TestCheckResourceAttrSet("ibm_pi_network_security_group_rule.network_security_group_rule", power.Arg_NetworkSecurityGroupID), + ), + }, + }, + }) +} + func TestAccIBMPINetworkSecurityGroupRuleRemove(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { acc.TestAccPreCheck(t) }, @@ -115,6 +135,30 @@ func testAccCheckIBMPINetworkSecurityGroupRuleConfigAddRuleTCP() string { }`, acc.Pi_cloud_instance_id, acc.Pi_network_security_group_id, acc.Pi_remote_id, acc.Pi_remote_type) } +func testAccCheckIBMPINetworkSecurityGroupRuleConfigPorts(sourcePortBegin string, sourcePortEnd string, destinationPortBegin string, destinationPortEnd string) string { + return fmt.Sprintf(` + resource "ibm_pi_network_security_group_rule" "network_security_group_rule" { + pi_cloud_instance_id = "%[1]s" + pi_network_security_group_id = "%[2]s" + pi_action = "allow" + pi_protocol { + type = "tcp" + } + pi_source_port { + minimum = %[5]s + maximum = %[6]s + } + pi_destination_port { + minimum = %[7]s + maximum = %[8]s + } + pi_remote { + id = "%[3]s" + type = "%[4]s" + } + }`, acc.Pi_cloud_instance_id, acc.Pi_network_security_group_id, acc.Pi_remote_id, acc.Pi_remote_type, sourcePortBegin, sourcePortEnd, destinationPortBegin, destinationPortEnd) +} + func testAccCheckIBMPINetworkSecurityGroupRuleConfigRemoveRule() string { return fmt.Sprintf(` resource "ibm_pi_network_security_group_rule" "network_security_group_rule" { diff --git a/website/docs/r/pi_network_security_group_rule.html.markdown b/website/docs/r/pi_network_security_group_rule.html.markdown index 4dc7aba8ed..54d019722e 100644 --- a/website/docs/r/pi_network_security_group_rule.html.markdown +++ b/website/docs/r/pi_network_security_group_rule.html.markdown @@ -78,6 +78,11 @@ Review the argument references that you can specify for your resource. Nested schema for `pi_destination_port`: - `maximum` - (Optional, Int) The end of the port range, if applicable. If the value is not present then the default value of 65535 will be the maximum port number. - `minimum` - (Optional, Int) The start of the port range, if applicable. If the value is not present then the default value of 1 will be the minimum port number. +- `pi_destination_ports` - (Deprecated, Optional, List) The list of destination port. Deprecated, please use `pi_destination_port`. + + Nested schema for `pi_destination_ports`: + - `maximum` - (Optional, Int) The end of the port range, if applicable. If the value is not present then the default value of 65535 will be the maximum port number. + - `minimum` - (Optional, Int) The start of the port range, if applicable. If the value is not present then the default value of 1 will be the minimum port number. - `pi_network_security_group_id` - (Required, String) The unique identifier of the network security group. - `pi_network_security_group_rule_id` - (Optional, String) The network security group rule id to remove. Required if none of the other optional fields are provided. - `pi_protocol` - (Optional, List) The list of protocol. Required if `pi_network_security_group_rule_id` is not provided. @@ -96,6 +101,11 @@ Review the argument references that you can specify for your resource. Nested schema for `pi_source_port`: - `maximum` - (Optional, Int) The end of the port range, if applicable. If the value is not present then the default value of 65535 will be the maximum port number. - `minimum` - (Optional, Int) The start of the port range, if applicable. If the value is not present then the default value of 1 will be the minimum port number. +- `pi_source_ports` - (Deprecated, Optional, List) List of source port. Deprecated, please use `pi_source_port`. + + Nested schema for `pi_source_ports`: + - `maximum` - (Optional, Int) The end of the port range, if applicable. If the value is not present then the default value of 65535 will be the maximum port number. + - `minimum` - (Optional, Int) The start of the port range, if applicable. If the value is not present then the default value of 1 will be the minimum port number. - `pi_name` - (Optional, String) The name of the network security group rule. Required if `pi_network_security_group_rule_id` is not provided.