Skip to content

Commit

Permalink
fix(reserved ip) : bare metal server reserved ip multi nic changes, d…
Browse files Browse the repository at this point in the history
…oc fix
  • Loading branch information
ujjwal-ibm committed May 2, 2022
1 parent 588d7bd commit 2f863a1
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 139 deletions.
31 changes: 28 additions & 3 deletions ibm/service/vpc/data_source_ibm_is_subnet_reserved_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vpc

import (
"fmt"
"reflect"

"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -132,9 +133,33 @@ func dataSdataSourceIBMISReservedIPRead(d *schema.ResourceData, meta interface{}
}
d.Set(isReservedIPType, *reserveIP.ResourceType)
if reserveIP.Target != nil {
target, ok := reserveIP.Target.(*vpcv1.ReservedIPTarget)
if ok {
d.Set(isReservedIPTarget, target.ID)
targetIntf := reserveIP.Target
switch reflect.TypeOf(targetIntf).String() {
case "*vpcv1.ReservedIPTargetEndpointGatewayReference":
{
target := targetIntf.(*vpcv1.ReservedIPTargetEndpointGatewayReference)
d.Set(isReservedIPTarget, target.ID)
}
case "*vpcv1.ReservedIPTargetNetworkInterfaceReferenceTargetContext":
{
target := targetIntf.(*vpcv1.ReservedIPTargetNetworkInterfaceReferenceTargetContext)
d.Set(isReservedIPTarget, target.ID)
}
case "*vpcv1.ReservedIPTargetLoadBalancerReference":
{
target := targetIntf.(*vpcv1.ReservedIPTargetLoadBalancerReference)
d.Set(isReservedIPTarget, target.ID)
}
case "*vpcv1.ReservedIPTargetVPNGatewayReference":
{
target := targetIntf.(*vpcv1.ReservedIPTargetVPNGatewayReference)
d.Set(isReservedIPTarget, target.ID)
}
case "*vpcv1.ReservedIPTarget":
{
target := targetIntf.(*vpcv1.ReservedIPTarget)
d.Set(isReservedIPTarget, target.ID)
}
}
}
return nil // By default there should be no error
Expand Down
33 changes: 30 additions & 3 deletions ibm/service/vpc/data_source_ibm_is_subnet_reserved_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package vpc

import (
"fmt"
"reflect"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
Expand Down Expand Up @@ -152,9 +153,35 @@ func dataSdataSourceIBMISReservedIPsRead(d *schema.ResourceData, meta interface{
ipsOutput[isReservedIPName] = *data.Name
ipsOutput[isReservedIPOwner] = *data.Owner
ipsOutput[isReservedIPType] = *data.ResourceType
target, ok := data.Target.(*vpcv1.ReservedIPTarget)
if ok {
ipsOutput[isReservedIPTarget] = target.ID
if data.Target != nil {
targetIntf := data.Target
switch reflect.TypeOf(targetIntf).String() {
case "*vpcv1.ReservedIPTargetEndpointGatewayReference":
{
target := targetIntf.(*vpcv1.ReservedIPTargetEndpointGatewayReference)
ipsOutput[isReservedIPTarget] = target.ID
}
case "*vpcv1.ReservedIPTargetNetworkInterfaceReferenceTargetContext":
{
target := targetIntf.(*vpcv1.ReservedIPTargetNetworkInterfaceReferenceTargetContext)
ipsOutput[isReservedIPTarget] = target.ID
}
case "*vpcv1.ReservedIPTargetLoadBalancerReference":
{
target := targetIntf.(*vpcv1.ReservedIPTargetLoadBalancerReference)
ipsOutput[isReservedIPTarget] = target.ID
}
case "*vpcv1.ReservedIPTargetVPNGatewayReference":
{
target := targetIntf.(*vpcv1.ReservedIPTargetVPNGatewayReference)
ipsOutput[isReservedIPTarget] = target.ID
}
case "*vpcv1.ReservedIPTarget":
{
target := targetIntf.(*vpcv1.ReservedIPTarget)
ipsOutput[isReservedIPTarget] = target.ID
}
}
}
reservedIPs = append(reservedIPs, ipsOutput)
}
Expand Down
Loading

0 comments on commit 2f863a1

Please sign in to comment.