Skip to content

Commit 26ec8b0

Browse files
committed
feat(ppnlb): Add support for Reserved IP as member target of PPNLB
1 parent f7e3822 commit 26ec8b0

10 files changed

+192
-9
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.15
3939
github.com/IBM/vmware-go-sdk v0.1.5
4040
github.com/IBM/vpc-beta-go-sdk v0.8.0
41-
github.com/IBM/vpc-go-sdk v0.72.0
41+
github.com/IBM/vpc-go-sdk v0.73.0
4242
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
4343
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
4444
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ github.com/IBM/vpc-beta-go-sdk v0.8.0 h1:cEPpv4iw3Ba5W2d0AWg3TIbKeJ8y1nPuUuibR5J
171171
github.com/IBM/vpc-beta-go-sdk v0.8.0/go.mod h1:hORgIyTFRzXrZIK9IohaWmCRBBlYiDRagsufi7M6akE=
172172
github.com/IBM/vpc-go-sdk v0.72.0 h1:3Pj7nNuYmlaRPiMyC/5Uro3+5hzNBM6v2Lrq5UABBkQ=
173173
github.com/IBM/vpc-go-sdk v0.72.0/go.mod h1:K3vVlje72PYE3ZRt1iouE+jSIq+vCyYzT1HiFC06hUA=
174+
github.com/IBM/vpc-go-sdk v0.73.0 h1:gMVR6NSzw8Y7pCkcDa92+heQTzu5X64q8bnBBpLJpFE=
175+
github.com/IBM/vpc-go-sdk v0.73.0/go.mod h1:K3vVlje72PYE3ZRt1iouE+jSIq+vCyYzT1HiFC06hUA=
174176
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
175177
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:Zb3OT4l0mf7P/GOs2w2Ilj5sdm5Whoq3pa24dAEBHFc=
176178
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=

ibm/service/vpc/data_source_ibm_is_lb_profile.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,27 @@ func DataSourceIBMISLbProfile() *schema.Resource {
8686
Computed: true,
8787
Description: "The product family this load balancer profile belongs to",
8888
},
89+
"targetable_resource_types": &schema.Schema{
90+
Type: schema.TypeList,
91+
Computed: true,
92+
Elem: &schema.Resource{
93+
Schema: map[string]*schema.Schema{
94+
"type": &schema.Schema{
95+
Type: schema.TypeString,
96+
Computed: true,
97+
Description: "The type for this profile field.",
98+
},
99+
"values": &schema.Schema{
100+
Type: schema.TypeList,
101+
Computed: true,
102+
Description: "The resource types that pool members of load balancers with this profile can target",
103+
Elem: &schema.Schema{
104+
Type: schema.TypeString,
105+
},
106+
},
107+
},
108+
},
109+
},
89110
"route_mode_supported": {
90111
Type: schema.TypeBool,
91112
Computed: true,
@@ -275,10 +296,38 @@ func dataSourceIBMISLbProfileRead(context context.Context, d *schema.ResourceDat
275296
}
276297
}
277298
}
299+
300+
if loadBalancerProfile.TargetableResourceTypes != nil {
301+
err = d.Set("targetable_resource_types", dataSourceTargetableResourceTypes(*loadBalancerProfile.TargetableResourceTypes))
302+
if err != nil {
303+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting targetable_resource_types: %s", err), "(Data) ibm_is_lb_profile", "read", "set-targetable_resource_types").GetDiag()
304+
}
305+
}
278306
d.SetId(*loadBalancerProfile.Name)
279307
return nil
280308
}
281309

310+
func dataSourceTargetableResourceTypes(result vpcv1.LoadBalancerProfileTargetableResourceTypes) (finalList []map[string]interface{}) {
311+
finalList = []map[string]interface{}{}
312+
finalMap := dataSourceTargetableResourceTypesToMap(result)
313+
finalList = append(finalList, finalMap)
314+
315+
return finalList
316+
}
317+
318+
func dataSourceTargetableResourceTypesToMap(resTermItem vpcv1.LoadBalancerProfileTargetableResourceTypes) map[string]interface{} {
319+
resTermMap := map[string]interface{}{}
320+
321+
if resTermItem.Type != nil {
322+
resTermMap["type"] = resTermItem.Type
323+
}
324+
if resTermItem.Values != nil {
325+
resTermMap["values"] = resTermItem.Values
326+
}
327+
328+
return resTermMap
329+
}
330+
282331
func dataSourceIBMIsLbProfileLoadBalancerProfileFailsafePolicyActionsToMap(model vpcv1.LoadBalancerProfileFailsafePolicyActionsIntf) (map[string]interface{}, error) {
283332
if _, ok := model.(*vpcv1.LoadBalancerProfileFailsafePolicyActionsEnum); ok {
284333
return dataSourceIBMIsLbProfileLoadBalancerProfileFailsafePolicyActionsEnumToMap(model.(*vpcv1.LoadBalancerProfileFailsafePolicyActionsEnum))

ibm/service/vpc/data_source_ibm_is_lb_profile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestAccIBMISLBProfileDatasource_basic(t *testing.T) {
2525
resource.TestCheckResourceAttr("data.ibm_is_lb_profile.test_profile", "family", "network"),
2626
resource.TestCheckResourceAttr("data.ibm_is_lb_profile.test_profile", "route_mode_supported", "true"),
2727
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "href"),
28+
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "targetable_resource_types.#"),
2829
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "udp_supported"),
2930
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "access_modes.0.values.#"),
3031
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "targetable_load_balancer_profiles.#"),

ibm/service/vpc/data_source_ibm_is_lb_profiles.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,27 @@ func DataSourceIBMISLbProfiles() *schema.Resource {
160160
},
161161
},
162162
},
163+
"targetable_resource_types": &schema.Schema{
164+
Type: schema.TypeList,
165+
Computed: true,
166+
Elem: &schema.Resource{
167+
Schema: map[string]*schema.Schema{
168+
"type": &schema.Schema{
169+
Type: schema.TypeString,
170+
Computed: true,
171+
Description: "The type for this profile field.",
172+
},
173+
"values": &schema.Schema{
174+
Type: schema.TypeList,
175+
Computed: true,
176+
Description: "The resource types that pool members of load balancers with this profile can target",
177+
Elem: &schema.Schema{
178+
Type: schema.TypeString,
179+
},
180+
},
181+
},
182+
},
183+
},
163184
"route_mode_supported": {
164185
Type: schema.TypeBool,
165186
Computed: true,
@@ -342,6 +363,10 @@ func dataSourceIBMISLbProfilesRead(context context.Context, d *schema.ResourceDa
342363
l["targetable_load_balancer_profiles"] = dataSourceLbProfileFlattenTargetableLoadBalancerProfiles(profileCollector.TargetableLoadBalancerProfiles)
343364
}
344365

366+
if profileCollector.TargetableResourceTypes != nil {
367+
l["targetable_resource_types"] = dataSourceTargetableResourceTypes(*profileCollector.TargetableResourceTypes)
368+
}
369+
345370
if profileCollector.Availability != nil {
346371
availabilitySupport := profileCollector.Availability.(*vpcv1.LoadBalancerProfileAvailability)
347372
availabilitySupportMap := map[string]interface{}{}

ibm/service/vpc/data_source_ibm_is_lb_profiles_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestAccIBMISLBProfilesDatasource_basic(t *testing.T) {
2525
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.access_modes.#"),
2626
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.access_modes.0.values.#"),
2727
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.targetable_load_balancer_profiles.#"),
28+
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.targetable_resource_types.#"),
2829
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.route_mode_supported"),
2930
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.href"),
3031
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.udp_supported"),
@@ -69,8 +70,9 @@ func TestAccIBMISLBProfilesDatasource_filter(t *testing.T) {
6970
Config: testDSCheckIBMISLBProfilesFilterConfig(),
7071
Check: resource.ComposeTestCheckFunc(
7172
resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.name", "network-fixed"),
72-
resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.family", "Network"),
73+
resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.family", "network"),
7374
resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.route_mode_supported", "true"),
75+
resource.TestCheckResourceAttr("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.targetable_resource_types.0.values.0", "instance"),
7476
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.href"),
7577
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.udp_supported"),
7678
),

ibm/service/vpc/resource_ibm_is_lb_pool_member_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,34 @@ func TestAccIBMISLBPoolMember_basic_network_target_application_load_balancer(t *
230230
})
231231
}
232232

233+
func TestAccIBMISLBPoolMember_basic_network_target_reservedIP(t *testing.T) {
234+
var lb string
235+
236+
vpcname := fmt.Sprintf("tflbpm-vpc-%d", acctest.RandIntRange(10, 100))
237+
subnetname := fmt.Sprintf("tflbpmc-name-%d", acctest.RandIntRange(10, 100))
238+
resIpSubnetName := fmt.Sprintf("tflbpmc-name-%d", acctest.RandIntRange(10, 100))
239+
nlbPoolName := fmt.Sprintf("tfnlbpoolc%d", acctest.RandIntRange(10, 100))
240+
241+
nlbName := fmt.Sprintf("tfnlbcreate%d", acctest.RandIntRange(10, 100))
242+
243+
resource.Test(t, resource.TestCase{
244+
PreCheck: func() { acc.TestAccPreCheck(t) },
245+
Providers: acc.TestAccProviders,
246+
CheckDestroy: testAccCheckIBMISLBPoolMemberDestroy,
247+
Steps: []resource.TestStep{
248+
{
249+
Config: testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget(
250+
vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, resIpSubnetName, nlbName, nlbPoolName),
251+
Check: resource.ComposeTestCheckFunc(
252+
testAccCheckIBMISLBPoolMemberExists("ibm_is_lb_pool_member.testacc_nlb_mem", lb),
253+
resource.TestCheckResourceAttr(
254+
"ibm_is_lb_pool_member.testacc_nlb_mem", "weight", "20"),
255+
),
256+
},
257+
},
258+
})
259+
}
260+
233261
// Weight set to zero from TF when it wasn't passed, must be kept blank so that backend could set it to default.
234262
// Function to validate if the weight is set to default as 50, when it is not provided in TF config.
235263
func TestAccIBMISLBPoolMember_basic_opt_weight_check(t *testing.T) {
@@ -543,3 +571,44 @@ func testAccCheckIBMISLBPoolMemberIDConfigWithLBTarget(vpcname, subnetname, zone
543571
}
544572
`, vpcname, subnetname, zone, cidr, albName, nlbName, nlbPoolName)
545573
}
574+
575+
func testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget(vpcname, subnetname, zone, cidr, resIpSubnetName, nlbName, nlbPoolName string) string {
576+
return fmt.Sprintf(`
577+
resource "ibm_is_vpc" "testacc_vpc" {
578+
name = "%s"
579+
}
580+
resource "ibm_is_subnet" "testacc_subnet" {
581+
name = "%s"
582+
vpc = "${ibm_is_vpc.testacc_vpc.id}"
583+
zone = "%s"
584+
ipv4_cidr_block = "%s"
585+
}
586+
resource "ibm_is_subnet_reserved_ip" "testacc_rip" {
587+
subnet = ibm_is_subnet.testacc_subnet.id
588+
name = "%s"
589+
}
590+
resource "ibm_is_lb" "testacc_NLB" {
591+
name = "%s"
592+
subnets = ["${ibm_is_subnet.testacc_subnet.id}"]
593+
profile = "network-private-path"
594+
type = "private_path"
595+
}
596+
resource "ibm_is_lb_pool" "testacc_nlb_pool" {
597+
name = "%s"
598+
lb = "${ibm_is_lb.testacc_NLB.id}"
599+
algorithm = "weighted_round_robin"
600+
protocol = "tcp"
601+
health_delay = 60
602+
health_retries = 5
603+
health_timeout = 30
604+
health_type = "tcp"
605+
}
606+
resource "ibm_is_lb_pool_member" "testacc_nlb_mem" {
607+
lb = "${ibm_is_lb.testacc_NLB.id}"
608+
pool = "${element(split("/",ibm_is_lb_pool.testacc_nlb_pool.id),1)}"
609+
port = 8080
610+
weight = 20
611+
target_id = "${element(split("/",ibm_is_subnet_reserved_ip.testacc_rip.id),1)}"
612+
}
613+
`, vpcname, subnetname, zone, cidr, resIpSubnetName, nlbName, nlbPoolName)
614+
}

website/docs/d/is_lb_profile.html.markdown

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ You can access the following attribute references after your data source is crea
5656
- `route_mode_supported` - (Bool) The route mode support for a load balancer with this profile.
5757
- `route_mode_type` - (String) The route mode type for this load balancer profile, one of [fixed, dependent]
5858
- `targetable_load_balancer_profiles` - (List) The load balancer profiles that load balancers with this profile can target.
59-
Nested scheme for `targetable_load_balancer_profiles`:
60-
- `family` - (String) The product family this load balancer profile belongs to.
61-
- `href` - (String) The URL for this load balancer profile.
62-
- `name` - (String) The name for this load balancer profile.
59+
60+
Nested scheme for `targetable_load_balancer_profiles`:
61+
- `family` - (String) The product family this load balancer profile belongs to.
62+
- `href` - (String) The URL for this load balancer profile.
63+
- `name` - (String) The name for this load balancer profile.
64+
- `targetable_resource_types` - (List) The targetable resource types configuration for a load balancer with this profile.
65+
66+
Nested schema for `targetable_resource_types`:
67+
- `type` - (String) The type for this profile field.
68+
- `values` - (List) The resource types that pool members of load balancers with this profile can target.
6369
- `udp_supported` - (Bool) The UDP support for a load balancer with this profile.
6470
- `udp_supported_type` - (String) The UDP support type for a load balancer with this profile, one of [fixed, dependent]
6571

website/docs/d/is_lb_profiles.html.markdown

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ You can access the following attribute references after your data source is crea
8484
Nested scheme for `targetable_load_balancer_profiles`:
8585
- `family` - (String) The product family this load balancer profile belongs to.
8686
- `href` - (String) The URL for this load balancer profile.
87-
- `name` - (String) The name for this load balancer profile.
88-
87+
- `name` - (String) The name for this load balancer profile.
88+
- `targetable_resource_types` - (List) The targetable resource types configuration for a load balancer with this profile.
89+
90+
Nested schema for `targetable_resource_types`:
91+
- `type` - (String) The type for this profile field.
92+
- `values` - (List) The resource types that pool members of load balancers with this profile can target.
8993
- `udp_supported` - (Bool) The UDP support for a load balancer with this profile.
9094
- `udp_supported_type` - (String) The UDP support type for a load balancer with this profile, one of [fixed, dependent]
9195

website/docs/r/is_lb_pool_member.html.markdown

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,31 @@ resource "ibm_is_lb_pool_member" "example" {
6060
}
6161
```
6262

63+
64+
### Sample to create a application load balancer as member target for private path network load balancer.
65+
66+
```terraform
67+
resource "ibm_is_lb_pool_member" "example" {
68+
lb = ibm_is_lb.example.id
69+
pool = element(split("/", ibm_is_lb_pool.example.id), 1)
70+
port = 8080
71+
weight = 60
72+
target_id = ibm_is_lb.example.id
73+
}
74+
```
75+
76+
### Sample to create a reserved ip as a member target for network load balancer.
77+
78+
```terraform
79+
resource "ibm_is_lb_pool_member" "example" {
80+
lb = ibm_is_lb.example.id
81+
pool = element(split("/", ibm_is_lb_pool.example.id), 1)
82+
port = 8080
83+
weight = 20
84+
target_id = ibm_is_subnet_reserved_ip.example.id
85+
}
86+
```
87+
6388
## Timeouts
6489
The `ibm_is_lb_pool_member` resource provides the following [Timeouts](https://www.terraform.io/docs/language/resources/syntax.html) configuration options:
6590

@@ -75,7 +100,7 @@ Review the argument references that you can specify for your resource.
75100
- `pool` - (Required, Forces new resource, String) The load balancer pool unique identifier.
76101
- `port`- (Required, Integer) The port number of the application running in the server member.
77102
- `target_address` - (Required, String) The IP address of the pool member.(Mutually exclusive with `target_id`)
78-
- `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`)
103+
- `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`)
79104

80105
- `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.
81106

0 commit comments

Comments
 (0)