Skip to content

Commit

Permalink
feat(ppnlb): UI-40655 Add support for Reserved IP as member target of…
Browse files Browse the repository at this point in the history
… PPNLB
  • Loading branch information
keerthi-gp committed Jan 21, 2025
1 parent 99d1b6f commit 211c2fc
Show file tree
Hide file tree
Showing 14 changed files with 11,360 additions and 10,209 deletions.
21,340 changes: 11,131 additions & 10,209 deletions common/github.com/IBM/vpc-go-sdk/vpcv1/vpc_v1.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func DataSourceIBMISLB() *schema.Resource {
Computed: true,
Description: "Indicates whether this load balancer supports source IP session persistence.",
},
isLBReservedIPtargetSupported: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this load balancer supports members with reserved IP as target.",
},
isLBUdpSupported: {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -420,6 +425,9 @@ func lbGetByName(d *schema.ResourceData, meta interface{}, name string) error {
if lb.RouteMode != nil {
d.Set(isLBRouteMode, *lb.RouteMode)
}
if lb.ReservedIPTargetSupported != nil {
d.Set(isLBReservedIPtargetSupported, *lb.ReservedIPTargetSupported)
}
if lb.UDPSupported != nil {
d.Set(isLBUdpSupported, *lb.UDPSupported)
}
Expand Down
38 changes: 38 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lb_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func DataSourceIBMISLbProfile() *schema.Resource {
Computed: true,
Description: "The product family this load balancer profile belongs to",
},
"reserved_ip_target_supported": {
Type: schema.TypeBool,
Computed: true,
Description: "The Reserved IP Target support for a load balancer with this profile",
},
"reserved_ip_type": {
Type: schema.TypeString,
Computed: true,
Description: "The Reserved IP Target support for a load balancer profile, one of [fixed, dependent]",
},
"route_mode_supported": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -175,6 +185,34 @@ func dataSourceIBMISLbProfileRead(context context.Context, d *schema.ResourceDat
}
}
}
if lbProfile.ReservedIPTargetSupported != nil {
reservedIPTargetSupported := lbProfile.ReservedIPTargetSupported
switch reflect.TypeOf(reservedIPTargetSupported).String() {
case "*vpcv1.LoadBalancerProfileReservedIPTargetSupportedFixed":
{
reservedIP := reservedIPTargetSupported.(*vpcv1.LoadBalancerProfileReservedIPTargetSupportedFixed)
d.Set("reserved_ip_target_supported", reservedIP.Value)
d.Set("reserved_ip_type", reservedIP.Type)
}
case "*vpcv1.LoadBalancerProfileReservedIPTargetSupportedDependent":
{
reservedIP := reservedIPTargetSupported.(*vpcv1.LoadBalancerProfileReservedIPTargetSupportedDependent)
if reservedIP.Type != nil {
d.Set("reserved_ip_type", *reservedIP.Type)
}
}
case "*vpcv1.LoadBalancerProfileReservedIPTargetSupported":
{
reservedIP := reservedIPTargetSupported.(*vpcv1.LoadBalancerProfileReservedIPTargetSupported)
if reservedIP.Type != nil {
d.Set("reserved_ip_type", *reservedIP.Type)
}
if reservedIP.Value != nil {
d.Set("reserved_ip_target_supported", *reservedIP.Value)
}
}
}
}
d.SetId(*lbProfile.Name)
return nil
}
1 change: 1 addition & 0 deletions ibm/service/vpc/data_source_ibm_is_lb_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", "reserved_ip_target_supported"),
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "udp_supported"),
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profile.test_profile", "access_modes.0.values.#"),
),
Expand Down
38 changes: 38 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lb_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ func DataSourceIBMISLbProfiles() *schema.Resource {
},
},
},
"reserved_ip_target_supported": {
Type: schema.TypeBool,
Computed: true,
Description: "The Reserved IP Target support for a load balancer with this profile",
},
"reserved_ip_type": {
Type: schema.TypeString,
Computed: true,
Description: "The Reserved IP Target support for a load balancer profile, one of [fixed, dependent]",
},
"route_mode_supported": {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -231,6 +241,34 @@ func dataSourceIBMISLbProfilesRead(d *schema.ResourceData, meta interface{}) err
}
}
}
if profileCollector.ReservedIPTargetSupported != nil {
reservedIPTargetSupported := profileCollector.ReservedIPTargetSupported
switch reflect.TypeOf(reservedIPTargetSupported).String() {
case "*vpcv1.LoadBalancerProfileReservedIPTargetSupportedFixed":
{
reservedIP := reservedIPTargetSupported.(*vpcv1.LoadBalancerProfileReservedIPTargetSupportedFixed)
l["reserved_ip_target_supported"] = reservedIP.Value
l["reserved_ip_type"] = reservedIP.Type
}
case "*vpcv1.LoadBalancerProfileReservedIPTargetSupportedDependent":
{
reservedIP := reservedIPTargetSupported.(*vpcv1.LoadBalancerProfileReservedIPTargetSupportedDependent)
if reservedIP.Type != nil {
l["reserved_ip_type"] = *reservedIP.Type
}
}
case "*vpcv1.LoadBalancerProfileReservedIPTargetSupported":
{
reservedIP := reservedIPTargetSupported.(*vpcv1.LoadBalancerProfileReservedIPTargetSupported)
if reservedIP.Type != nil {
l["reserved_ip_type"] = *reservedIP.Type
}
if reservedIP.Value != nil {
l["reserved_ip_target_supported"] = *reservedIP.Value
}
}
}
}
if profileCollector.RouteModeSupported != nil {
routeMode := profileCollector.RouteModeSupported
switch reflect.TypeOf(routeMode).String() {
Expand Down
2 changes: 2 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lb_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestAccIBMISLBProfilesDatasource_basic(t *testing.T) {
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.#"),
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.reserved_ip_target_supported"),
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"),
Expand All @@ -45,6 +46,7 @@ func TestAccIBMISLBProfilesDatasource_filter(t *testing.T) {
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.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.href"),
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.reserved_ip_target_supported"),
resource.TestCheckResourceAttrSet("data.ibm_is_lb_profiles.test_profiles", "lb_profiles.0.udp_supported"),
),
},
Expand Down
8 changes: 8 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func DataSourceIBMISLBS() *schema.Resource {
Computed: true,
Description: "Indicates whether this load balancer supports source IP session persistence.",
},
isLBReservedIPtargetSupported: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this load balancer supports members with reserved IP as target.",
},
isLBUdpSupported: {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -365,6 +370,9 @@ func getLbs(d *schema.ResourceData, meta interface{}) error {
if lb.RouteMode != nil {
lbInfo[isLBRouteMode] = *lb.RouteMode
}
if lb.ReservedIPTargetSupported != nil {
lbInfo[isLBReservedIPtargetSupported] = *lb.ReservedIPTargetSupported
}
if lb.UDPSupported != nil {
lbInfo[isLBUdpSupported] = *lb.UDPSupported
}
Expand Down
10 changes: 10 additions & 0 deletions ibm/service/vpc/resource_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
isLBDeleted = "done"
isLBProvisioning = "provisioning"
isLBProvisioningDone = "done"
isLBReservedIPtargetSupported = "reserved_ip_target_supported"
isLBResourceGroup = "resource_group"
isLBProfile = "profile"
isLBRouteMode = "route_mode"
Expand Down Expand Up @@ -256,6 +257,12 @@ func ResourceIBMISLB() *schema.Resource {
Description: "List of access management tags",
},

isLBReservedIPtargetSupported: {
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether this load balancer supports members with reserved IP as target.",
},

isLBResourceGroup: {
Type: schema.TypeString,
ForceNew: true,
Expand Down Expand Up @@ -666,6 +673,9 @@ func lbGet(d *schema.ResourceData, meta interface{}, id string) error {

d.Set(isLBResourceGroup, *lb.ResourceGroup.ID)
d.Set(isLBHostName, *lb.Hostname)
if lb.ReservedIPTargetSupported != nil {
d.Set(isLBReservedIPtargetSupported, *lb.ReservedIPTargetSupported)
}
if lb.UDPSupported != nil {
d.Set(isLBUdpSupported, *lb.UDPSupported)
}
Expand Down
105 changes: 105 additions & 0 deletions ibm/service/vpc/resource_ibm_is_lb_pool_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,51 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
})
}

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))
nlbName1 := fmt.Sprintf("tfnlbupdate%d", acctest.RandIntRange(10, 100))

sshname := "terraform-test-ssh-key"
vsiName := fmt.Sprintf("tf-instance-%d", acctest.RandIntRange(10, 100))
publicKey := strings.TrimSpace(`
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVERRN7/9484SOBJ3HSKxxNG5JN8owAjy5f9yYwcUg+JaUVuytn5Pv3aeYROHGGg+5G346xaq3DAwX6Y5ykr2fvjObgncQBnuU5KHWCECO/4h8uWuwh/kfniXPVjFToc+gnkqA+3RKpAecZhFXwfalQ9mMuYGFxn+fwn8cYEApsJbsEmb0iJwPiZ5hjFC8wREuiTlhPHDgkBLOiycd20op2nXzDbHfCHInquEe/gYxEitALONxm0swBOwJZwlTDOB7C6y2dzlrtxr1L59m7pCkWI4EtTRLvleehBoj3u7jB4usR
`)
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISLBPoolMemberDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget(
vpcname, subnetname, resIpSubnetName, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, acc.IsImageName,
vsiName, 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"),
),
},
{
Config: testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget(
vpcname, subnetname, resIpSubnetName, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, acc.IsImageName,
vsiName, nlbName1, nlbPoolName),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISLBPoolMemberExists("ibm_is_lb_pool_member.testacc_nlb_mem", lb),
resource.TestCheckResourceAttr(
"ibm_is_lb_pool_member.testacc_nlb_mem", "port", "8080"),
),
},
},
})
}

// 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) {
Expand Down Expand Up @@ -463,3 +508,63 @@ func testAccCheckIBMISLBPoolMemberWeightConfig(vpcname, subnetname, zone, cidr,
target_address = "%s"
}`, vpcname, subnetname, zone, cidr, name, poolName, port, address)
}

func testAccCheckIBMISLBPoolMemberIDConfigWithReservedIPTarget(vpcname, subnetname, resIpSubnetName, zone, cidr, sshname, publickey,
isImageName, vsiName, 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_ssh_key" "testacc_sshkey" {
name = "%s"
public_key = "%s"
}
data "ibm_is_image" "ds_image" {
name = "%s"
}
resource "ibm_is_instance" "testacc_instance" {
name = "%s"
image = data.ibm_is_image.ds_image.id
profile = "%s"
primary_network_interface {
subnet = ibm_is_subnet.testacc_subnet.id
}
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
keys = [ibm_is_ssh_key.testacc_sshkey.id]
}
resource "ibm_is_lb" "testacc_NLB" {
name = "%s"
subnets = ["${ibm_is_subnet.testacc_subnet.id}"]
profile = "network-fixed"
}
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 = "${ibm_is_subnet_reserved_ip.testacc_subnet.id}"
}
`, vpcname, subnetname, resIpSubnetName, zone, cidr, sshname, publickey, isImageName, vsiName,
acc.InstanceProfileName, zone, nlbName, nlbPoolName)
}
1 change: 1 addition & 0 deletions website/docs/d/is_lb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ In addition to all argument reference list, you can access the following attribu
- `reserved_ip`- (String) The unique identifier for this reserved IP
- `resource_type`- (String) The resource type.
- `private_ips` - (List) The private IP addresses assigned to this load balancer. Same as `private_ip.[].address`
- `reserved_ip_target_supported`- (Bool) Indicates whether this load balancer supports members with reserved IP as target.
- `resource_group` - (String) The resource group id, where the load balancer is created.
- `route_mode` - (Bool) Indicates whether route mode is enabled for this load balancer.
- `security_groups`- (String) A list of security groups that are used with this load balancer. This option is supported only for application load balancers.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/is_lb_profile.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ You can access the following attribute references after your data source is crea
- `href` - (String) The URL for this load balancer profile.
- `id` - (String) The id(`name`) for this load balancer profile.
- `name` - (String) The name for this load balancer profile.
- `reserved_ip_target_supported` - (Bool) The Reserved IP Target support for a load balancer with this profile.
- `reserved_ip_type` - (String) The reserved ip type for this load balancer profile, one of [fixed, dependent]
- `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]
- `udp_supported` - (Bool) The UDP support for a load balancer with this profile.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/d/is_lb_profiles.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ You can access the following attribute references after your data source is crea
- `value` - (String) Indicated whether source ip session persistence is supported. Applicable only if `type` is **fixed**

- `name` - (String) The name for this load balancer profile.
- `reserved_ip_target_supported` - (Bool) The Reserved IP Target support for a load balancer with this profile.
- `reserved_ip_type` - (String) The reserved ip type for this load balancer profile, one of [fixed, dependent]

- `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]

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/is_lb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ In addition to all argument reference list, you can access the following attribu
- `private_ips` - (String) The private IP addresses (Reserved IP address reference) assigned to this load balancer.
- `status` - (String) The status of the load balancer.
- `security_groups_supported`- (Bool) Indicates if this load balancer supports security groups.
- `reserved_ip_target_supported`- (Bool) Indicates whether this load balancer supports members with reserved IP as target.
- `source_ip_session_persistence_supported` - (Boolean) Indicates whether this load balancer supports source IP session persistence.
- `udp_supported`- (Bool) Indicates whether this load balancer supports UDP.

Expand Down
12 changes: 12 additions & 0 deletions website/docs/r/is_lb_pool_member.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ resource "ibm_is_lb_pool_member" "example" {
}
```

### 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:

Expand Down

0 comments on commit 211c2fc

Please sign in to comment.