diff --git a/go.mod b/go.mod index 4e3356c4b9..7b35fe9b2b 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( github.com/IBM/secrets-manager-go-sdk/v2 v2.0.15 github.com/IBM/vmware-go-sdk v0.1.5 github.com/IBM/vpc-beta-go-sdk v0.8.0 - github.com/IBM/vpc-go-sdk v0.72.0 + github.com/IBM/vpc-go-sdk v0.73.0 github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2 github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0 diff --git a/go.sum b/go.sum index d2e8728dde..2b1bc1ebc5 100644 --- a/go.sum +++ b/go.sum @@ -171,6 +171,8 @@ github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5J github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE= github.com/IBM/vpc-go-sdk v0.72.0 h1:3Pj7nNuYmlaRPiMyC/5Uro3+5hzNBM6v2Lrq5UABBkQ= github.com/IBM/vpc-go-sdk v0.72.0/go.mod h1:K3vVlje72PYE3ZRt1iouE+jSIq+vCyYzT1HiFC06hUA= +github.com/IBM/vpc-go-sdk v0.73.0 h1:gMVR6NSzw8Y7pCkcDa92+heQTzu5X64q8bnBBpLJpFE= +github.com/IBM/vpc-go-sdk v0.73.0/go.mod h1:K3vVlje72PYE3ZRt1iouE+jSIq+vCyYzT1HiFC06hUA= github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0= github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc= github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= diff --git a/ibm/service/vpc/data_source_ibm_is_lb_profile.go b/ibm/service/vpc/data_source_ibm_is_lb_profile.go index e3e0f0a92c..c28faf1437 100644 --- a/ibm/service/vpc/data_source_ibm_is_lb_profile.go +++ b/ibm/service/vpc/data_source_ibm_is_lb_profile.go @@ -86,6 +86,27 @@ func DataSourceIBMISLbProfile() *schema.Resource { Computed: true, Description: "The product family this load balancer profile belongs to", }, + "targetable_resource_types": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The type for this profile field.", + }, + "values": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The resource types that pool members of load balancers with this profile can target", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, "route_mode_supported": { Type: schema.TypeBool, Computed: true, @@ -275,10 +296,38 @@ func dataSourceIBMISLbProfileRead(context context.Context, d *schema.ResourceDat } } } + + if loadBalancerProfile.TargetableResourceTypes != nil { + err = d.Set("targetable_resource_types", dataSourceTargetableResourceTypes(*loadBalancerProfile.TargetableResourceTypes)) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting targetable_resource_types: %s", err), "(Data) ibm_is_lb_profile", "read", "set-targetable_resource_types").GetDiag() + } + } d.SetId(*loadBalancerProfile.Name) return nil } +func dataSourceTargetableResourceTypes(result vpcv1.LoadBalancerProfileTargetableResourceTypes) (finalList []map[string]interface{}) { + finalList = []map[string]interface{}{} + finalMap := dataSourceTargetableResourceTypesToMap(result) + finalList = append(finalList, finalMap) + + return finalList +} + +func dataSourceTargetableResourceTypesToMap(resTermItem vpcv1.LoadBalancerProfileTargetableResourceTypes) map[string]interface{} { + resTermMap := map[string]interface{}{} + + if resTermItem.Type != nil { + resTermMap["type"] = resTermItem.Type + } + if resTermItem.Values != nil { + resTermMap["values"] = resTermItem.Values + } + + return resTermMap +} + func dataSourceIBMIsLbProfileLoadBalancerProfileFailsafePolicyActionsToMap(model vpcv1.LoadBalancerProfileFailsafePolicyActionsIntf) (map[string]interface{}, error) { if _, ok := model.(*vpcv1.LoadBalancerProfileFailsafePolicyActionsEnum); ok { return dataSourceIBMIsLbProfileLoadBalancerProfileFailsafePolicyActionsEnumToMap(model.(*vpcv1.LoadBalancerProfileFailsafePolicyActionsEnum)) diff --git a/ibm/service/vpc/data_source_ibm_is_lb_profile_test.go b/ibm/service/vpc/data_source_ibm_is_lb_profile_test.go index 4a4a2d6649..05750b0915 100644 --- a/ibm/service/vpc/data_source_ibm_is_lb_profile_test.go +++ b/ibm/service/vpc/data_source_ibm_is_lb_profile_test.go @@ -25,6 +25,7 @@ func TestAccIBMISLBProfileDatasource_basic(t *testing.T) { resource.TestCheckResourceAttr("data.ibm_is_lb_profile.test_profile", "family", "network"), resource.TestCheckResourceAttr("data.ibm_is_lb_profile.test_profile", "route_mode_supported", "true"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "href"), + resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "targetable_resource_types.#"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "udp_supported"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "access_modes.0.values.#"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "targetable_load_balancer_profiles.#"), diff --git a/ibm/service/vpc/data_source_ibm_is_lb_profiles.go b/ibm/service/vpc/data_source_ibm_is_lb_profiles.go index c24c227f71..2ffb0a78f4 100644 --- a/ibm/service/vpc/data_source_ibm_is_lb_profiles.go +++ b/ibm/service/vpc/data_source_ibm_is_lb_profiles.go @@ -160,6 +160,27 @@ func DataSourceIBMISLbProfiles() *schema.Resource { }, }, }, + "targetable_resource_types": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The type for this profile field.", + }, + "values": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "The resource types that pool members of load balancers with this profile can target", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, "route_mode_supported": { Type: schema.TypeBool, Computed: true, @@ -342,6 +363,10 @@ func dataSourceIBMISLbProfilesRead(context context.Context, d *schema.ResourceDa l["targetable_load_balancer_profiles"] = dataSourceLbProfileFlattenTargetableLoadBalancerProfiles(profileCollector.TargetableLoadBalancerProfiles) } + if profileCollector.TargetableResourceTypes != nil { + l["targetable_resource_types"] = dataSourceTargetableResourceTypes(*profileCollector.TargetableResourceTypes) + } + if profileCollector.Availability != nil { availabilitySupport := profileCollector.Availability.(*vpcv1.LoadBalancerProfileAvailability) availabilitySupportMap := map[string]interface{}{} diff --git a/ibm/service/vpc/data_source_ibm_is_lb_profiles_test.go b/ibm/service/vpc/data_source_ibm_is_lb_profiles_test.go index 914ef842a8..610d4ad07d 100644 --- a/ibm/service/vpc/data_source_ibm_is_lb_profiles_test.go +++ b/ibm/service/vpc/data_source_ibm_is_lb_profiles_test.go @@ -25,6 +25,7 @@ func TestAccIBMISLBProfilesDatasource_basic(t *testing.T) { resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.access_modes.#"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.access_modes.0.values.#"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.targetable_load_balancer_profiles.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.targetable_resource_types.#"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.route_mode_supported"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.href"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.udp_supported"), @@ -69,8 +70,9 @@ func TestAccIBMISLBProfilesDatasource_filter(t *testing.T) { Config: testDSCheckIBMISLBProfilesFilterConfig(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.name", "network-fixed"), - resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.family", "Network"), + resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.family", "network"), resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.route_mode_supported", "true"), + resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.targetable_resource_types.0.values.0", "instance"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.href"), resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.udp_supported"), ), diff --git a/ibm/service/vpc/resource_ibm_is_lb_pool_member_test.go b/ibm/service/vpc/resource_ibm_is_lb_pool_member_test.go index 4393a333a5..b4c05116b0 100644 --- a/ibm/service/vpc/resource_ibm_is_lb_pool_member_test.go +++ b/ibm/service/vpc/resource_ibm_is_lb_pool_member_test.go @@ -230,6 +230,34 @@ func TestAccIBMISLBPoolMember_basic_network_target_application_load_balancer(t * }) } +func TestAccIBMISLBPoolMember_basic_network_target_reservedIP(t *testing.T) { + var lb string + + vpcname := fmt.Sprintf("tflbpm-vpc-%d", acctest.RandIntRange(10, 100)) + subnetname := fmt.Sprintf("tflbpmc-name-%d", acctest.RandIntRange(10, 100)) + resIpSubnetName := fmt.Sprintf("tflbpmc-name-%d", acctest.RandIntRange(10, 100)) + nlbPoolName := fmt.Sprintf("tfnlbpoolc%d", acctest.RandIntRange(10, 100)) + + nlbName := fmt.Sprintf("tfnlbcreate%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMISLBPoolMemberDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget( + vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, resIpSubnetName, nlbName, nlbPoolName), + Check: resource.ComposeTestCheckFunc( + testAccCheckIBMISLBPoolMemberExists("ibm_is_lb_pool_member.testacc_nlb_mem", lb), + resource.TestCheckResourceAttr( + "ibm_is_lb_pool_member.testacc_nlb_mem", "weight", "20"), + ), + }, + }, + }) +} + // Weight set to zero from TF when it wasn't passed, must be kept blank so that backend could set it to default. // Function to validate if the weight is set to default as 50, when it is not provided in TF config. func TestAccIBMISLBPoolMember_basic_opt_weight_check(t *testing.T) { @@ -543,3 +571,44 @@ func testAccCheckIBMISLBPoolMemberIDConfigWithLBTarget(vpcname, subnetname, zone } `, vpcname, subnetname, zone, cidr, albName, nlbName, nlbPoolName) } + +func testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget(vpcname, subnetname, zone, cidr, resIpSubnetName, nlbName, nlbPoolName string) string { + return fmt.Sprintf(` + resource "ibm_is_vpc" "testacc_vpc" { + name = "%s" + } + resource "ibm_is_subnet" "testacc_subnet" { + name = "%s" + vpc = "${ibm_is_vpc.testacc_vpc.id}" + zone = "%s" + ipv4_cidr_block = "%s" + } + resource "ibm_is_subnet_reserved_ip" "testacc_rip" { + subnet = ibm_is_subnet.testacc_subnet.id + name = "%s" + } + resource "ibm_is_lb" "testacc_NLB" { + name = "%s" + subnets = ["${ibm_is_subnet.testacc_subnet.id}"] + profile = "network-private-path" + type = "private_path" + } + resource "ibm_is_lb_pool" "testacc_nlb_pool" { + name = "%s" + lb = "${ibm_is_lb.testacc_NLB.id}" + algorithm = "weighted_round_robin" + protocol = "tcp" + health_delay = 60 + health_retries = 5 + health_timeout = 30 + health_type = "tcp" + } + resource "ibm_is_lb_pool_member" "testacc_nlb_mem" { + lb = "${ibm_is_lb.testacc_NLB.id}" + pool = "${element(split("/",ibm_is_lb_pool.testacc_nlb_pool.id),1)}" + port = 8080 + weight = 20 + target_id = "${element(split("/",ibm_is_subnet_reserved_ip.testacc_rip.id),1)}" + } +`, vpcname, subnetname, zone, cidr, resIpSubnetName, nlbName, nlbPoolName) +} diff --git a/website/docs/d/is_lb_profile.html.markdown b/website/docs/d/is_lb_profile.html.markdown index c7942278c9..04376203d1 100644 --- a/website/docs/d/is_lb_profile.html.markdown +++ b/website/docs/d/is_lb_profile.html.markdown @@ -56,10 +56,16 @@ You can access the following attribute references after your data source is crea - `route_mode_supported` - (Bool) The route mode support for a load balancer with this profile. - `route_mode_type` - (String) The route mode type for this load balancer profile, one of [fixed, dependent] - `targetable_load_balancer_profiles` - (List) The load balancer profiles that load balancers with this profile can target. - Nested scheme for `targetable_load_balancer_profiles`: - - `family` - (String) The product family this load balancer profile belongs to. - - `href` - (String) The URL for this load balancer profile. - - `name` - (String) The name for this load balancer profile. + + Nested scheme for `targetable_load_balancer_profiles`: + - `family` - (String) The product family this load balancer profile belongs to. + - `href` - (String) The URL for this load balancer profile. + - `name` - (String) The name for this load balancer profile. +- `targetable_resource_types` - (List) The targetable resource types configuration for a load balancer with this profile. + + Nested schema for `targetable_resource_types`: + - `type` - (String) The type for this profile field. + - `values` - (List) The resource types that pool members of load balancers with this profile can target. - `udp_supported` - (Bool) The UDP support for a load balancer with this profile. - `udp_supported_type` - (String) The UDP support type for a load balancer with this profile, one of [fixed, dependent] diff --git a/website/docs/d/is_lb_profiles.html.markdown b/website/docs/d/is_lb_profiles.html.markdown index 5e724ea394..65ccf0621d 100644 --- a/website/docs/d/is_lb_profiles.html.markdown +++ b/website/docs/d/is_lb_profiles.html.markdown @@ -84,8 +84,12 @@ You can access the following attribute references after your data source is crea Nested scheme for `targetable_load_balancer_profiles`: - `family` - (String) The product family this load balancer profile belongs to. - `href` - (String) The URL for this load balancer profile. - - `name` - (String) The name for this load balancer profile. - + - `name` - (String) The name for this load balancer profile. + - `targetable_resource_types` - (List) The targetable resource types configuration for a load balancer with this profile. + + Nested schema for `targetable_resource_types`: + - `type` - (String) The type for this profile field. + - `values` - (List) The resource types that pool members of load balancers with this profile can target. - `udp_supported` - (Bool) The UDP support for a load balancer with this profile. - `udp_supported_type` - (String) The UDP support type for a load balancer with this profile, one of [fixed, dependent] diff --git a/website/docs/r/is_lb_pool_member.html.markdown b/website/docs/r/is_lb_pool_member.html.markdown index 87ab987286..1e548f2399 100644 --- a/website/docs/r/is_lb_pool_member.html.markdown +++ b/website/docs/r/is_lb_pool_member.html.markdown @@ -60,6 +60,31 @@ resource "ibm_is_lb_pool_member" "example" { } ``` + +### Sample to create a application load balancer as member target for private path network load balancer. + +```terraform +resource "ibm_is_lb_pool_member" "example" { + lb = ibm_is_lb.example.id + pool = element(split("/", ibm_is_lb_pool.example.id), 1) + port = 8080 + weight = 60 + target_id = ibm_is_lb.example.id +} +``` + +### Sample to create a reserved ip as a member target for network load balancer. + +```terraform + resource "ibm_is_lb_pool_member" "example" { + lb = ibm_is_lb.example.id + pool = element(split("/", ibm_is_lb_pool.example.id), 1) + port = 8080 + weight = 20 + target_id = ibm_is_subnet_reserved_ip.example.id + } +``` + ## Timeouts The `ibm_is_lb_pool_member` resource provides the following [Timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options: @@ -75,7 +100,7 @@ Review the argument references that you can specify for your resource. - `pool` - (Required, Forces new resource, String) The load balancer pool unique identifier. - `port`- (Required, Integer) The port number of the application running in the server member. - `target_address` - (Required, String) The IP address of the pool member.(Mutually exclusive with `target_id`) -- `target_id` - (Required, String) The unique identifier for the virtual server instance or application load balancer pool member. Required for network load balancer. (Mutually exclusive with `target_address`) +- `target_id` - (Required, String) The unique identifier for the virtual server instance or application load balancer pool member or subnet reserved ip. Required for network load balancer. (Mutually exclusive with `target_address`) - `weight` - (Optional, Integer) Weight of the server member. This option takes effect only when the load-balancing algorithm of its belonging pool is `weighted_round_robin`, Minimum allowed weight is `0` and Maximum allowed weight is `100`. Default: 50, Weight of the server member. Applicable only if the pool algorithm is weighted_round_robin.