Skip to content

Commit

Permalink
fix(lb): fix for lb data source collection (IBM-Cloud#5763)
Browse files Browse the repository at this point in the history
* fix(lb): fix for lb data source collection

* added more nil checks for safety

* test update
  • Loading branch information
deepaksibm authored Nov 6, 2024
1 parent 03caa9e commit c5551eb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ibm/service/vpc/data_source_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ func lbGetByName(d *schema.ResourceData, meta interface{}, name string) error {
if lb.Logging != nil && lb.Logging.Datapath != nil {
d.Set(isLBLogging, *lb.Logging.Datapath.Active)
}
if *lb.IsPublic {
if lb.IsPublic != nil && *lb.IsPublic {
d.Set(isLBType, "public")
} else if lb.IsPrivatePath != nil && *lb.IsPrivatePath {
d.Set(isLBType, "private_path")
Expand Down
4 changes: 2 additions & 2 deletions ibm/service/vpc/data_source_ibm_is_lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ func getLbs(d *schema.ResourceData, meta interface{}) error {
lbInfo[ProvisioningStatus] = *lb.ProvisioningStatus

lbInfo[CreatedAt] = lb.CreatedAt.String()
if *lb.IsPublic {
if lb.IsPublic != nil && *lb.IsPublic {
lbInfo[isLBType] = "public"
} else if *lb.IsPrivatePath {
} else if lb.IsPrivatePath != nil && *lb.IsPrivatePath {
lbInfo[isLBType] = "private_path"
} else {
lbInfo[isLBType] = "private"
Expand Down
12 changes: 8 additions & 4 deletions ibm/service/vpc/data_source_ibm_is_lbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ func TestAccIBMISLBSDatasource_basic(t *testing.T) {
testAccCheckIBMISLBExists("ibm_is_lb.testacc_lb", lb),
resource.TestCheckResourceAttr(
"data.ibm_is_lb.ds_lb", "name", name),
resource.TestCheckResourceAttrSet("data.ibm_is_lbs.ds_lb", "load_balancers.0.availability"),
resource.TestCheckResourceAttrSet("data.ibm_is_lbs.ds_lb", "load_balancers.0.instance_groups_supported"),
resource.TestCheckResourceAttrSet("data.ibm_is_lbs.ds_lb", "load_balancers.0.source_ip_persistence_supported"),
resource.TestCheckResourceAttrSet("data.ibm_is_lbs.test_lbs", "load_balancers.0.availability"),
resource.TestCheckResourceAttrSet("data.ibm_is_lbs.test_lbs", "load_balancers.0.instance_groups_supported"),
resource.TestCheckResourceAttrSet("data.ibm_is_lbs.test_lbs", "load_balancers.0.source_ip_session_persistence_supported"),
),
},
{
Expand Down Expand Up @@ -101,7 +101,11 @@ func testDSCheckIBMISLBSConfig(vpcname, subnetname, zone, cidr, name string) str
}
data "ibm_is_lb" "ds_lb" {
name = ibm_is_lb.testacc_lb.name
}`, vpcname, subnetname, zone, cidr, name)
}
data "ibm_is_lbs" "test_lbs" {
depends_on = [ibm_is_lb.testacc_lb]
}
`, vpcname, subnetname, zone, cidr, name)
}
func testDSCheckIBMISLBSDatasourceConfig() string {
// status filter defaults to empty
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/vpc/resource_ibm_is_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ func lbGet(d *schema.ResourceData, meta interface{}, id string) error {
d.Set("dns", nil)
}
d.Set(isLBName, *lb.Name)
if *lb.IsPublic {
if lb.IsPublic != nil && *lb.IsPublic {
d.Set(isLBType, "public")
} else {
if lb.IsPrivatePath != nil && *lb.IsPrivatePath {
Expand Down

0 comments on commit c5551eb

Please sign in to comment.