Skip to content

Commit

Permalink
Add Network Interface and NSG Href To Instance Network (#5991)
Browse files Browse the repository at this point in the history
update change with new sdk version

update change with new sdk version

Update text for nsg ids attr

remove duplicate line

Update sdk

Remove deprecated attr

fix conflict

update go.mod
  • Loading branch information
michaelkad authored Feb 21, 2025
1 parent 96b20a2 commit 1452f36
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 49 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ require (
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/jinzhu/copier v0.3.2
github.com/minsikl/netscaler-nitro-go v0.0.0-20170827154432-5b14ce3643e3
github.com/mitchellh/go-homedir v1.1.0
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae2311
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.10.0 h1:yBUHWwvNBmLkWpbZJQJEXoxBa1Dm+eJgMSbk9ljmXUU=
github.com/IBM-Cloud/power-go-client v1.10.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/power-go-client v1.10.0-beta7 h1:nxAuY/0axYwOq2jb2jVZqu3nmPP/7/sFC6HCi8RhMUA=
github.com/IBM-Cloud/power-go-client v1.10.0-beta7/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/power-go-client v1.10.0 h1:yBUHWwvNBmLkWpbZJQJEXoxBa1Dm+eJgMSbk9ljmXUU=
github.com/IBM-Cloud/power-go-client v1.10.0/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
Expand Down
21 changes: 16 additions & 5 deletions ibm/service/power/data_source_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,33 @@ func DataSourceIBMPIInstance() *schema.Resource {
Description: "The MAC address of the instance.",
Type: schema.TypeString,
},
Attr_Macaddress: {
Attr_NetworkID: {
Computed: true,
Deprecated: "Deprecated, use mac_address instead",
Description: "The MAC address of the instance.",
Description: "The network ID of the instance.",
Type: schema.TypeString,
},
Attr_NetworkID: {
Attr_NetworkInterfaceID: {
Computed: true,
Description: "The network ID of the instance.",
Description: "ID of the network interface.",
Type: schema.TypeString,
},
Attr_NetworkName: {
Computed: true,
Description: "The network name of the instance.",
Type: schema.TypeString,
},
Attr_NetworkSecurityGroupIDs: {
Computed: true,
Description: "IDs of the network necurity groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeSet,
},
Attr_NetworkSecurityGroupsHref: {
Computed: true,
Description: "Links to the network security groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
Attr_Type: {
Computed: true,
Description: "The type of the network.",
Expand Down
34 changes: 28 additions & 6 deletions ibm/service/power/data_source_ibm_pi_instance_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package power

import (
"context"
"log"
"net"
"strconv"

Expand Down Expand Up @@ -56,14 +55,14 @@ func DataSourceIBMPIInstanceIP() *schema.Resource {
Description: "The IP octet of the network that is attached to this instance.",
Type: schema.TypeString,
},
Attr_Macaddress: {
Attr_MacAddress: {
Computed: true,
Deprecated: "Deprecated, use mac_address instead",
Description: "The MAC address of the network that is attached to this instance.",
Type: schema.TypeString,
},
Attr_MacAddress: {
Attr_Macaddress: {
Computed: true,
Deprecated: "Deprecated, use mac_address instead",
Description: "The MAC address of the network that is attached to this instance.",
Type: schema.TypeString,
},
Expand All @@ -72,6 +71,23 @@ func DataSourceIBMPIInstanceIP() *schema.Resource {
Description: "ID of the network.",
Type: schema.TypeString,
},
Attr_NetworkInterfaceID: {
Computed: true,
Description: "ID of the network interface.",
Type: schema.TypeString,
},
Attr_NetworkSecurityGroupIDs: {
Computed: true,
Description: "IDs of the network necurity groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeSet,
},
Attr_NetworkSecurityGroupsHref: {
Computed: true,
Description: "Links to the network security groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
Attr_Type: {
Computed: true,
Description: "The type of the network that is attached to this instance.",
Expand All @@ -98,19 +114,25 @@ func dataSourceIBMPIInstancesIPRead(ctx context.Context, d *schema.ResourceData,

for _, network := range powervmdata.Networks {
if network.NetworkName == networkName {
log.Printf("Printing the ip %s", network.IPAddress)
d.SetId(network.NetworkID)
d.Set(Attr_ExternalIP, network.ExternalIP)
d.Set(Attr_IP, network.IPAddress)
d.Set(Attr_Macaddress, network.MacAddress)
d.Set(Attr_MacAddress, network.MacAddress)
d.Set(Attr_Macaddress, network.MacAddress)
d.Set(Attr_NetworkID, network.NetworkID)
d.Set(Attr_NetworkInterfaceID, network.NetworkInterfaceID)
d.Set(Attr_Type, network.Type)

IPObject := net.ParseIP(network.IPAddress).To4()
if len(IPObject) > 0 {
d.Set(Attr_IPOctet, strconv.Itoa(int(IPObject[3])))
}
if len(network.NetworkSecurityGroupIDs) > 0 {
d.Set(Attr_NetworkSecurityGroupIDs, network.NetworkSecurityGroupIDs)
}
if len(network.NetworkSecurityGroupsHref) > 0 {
d.Set(Attr_NetworkSecurityGroupsHref, network.NetworkSecurityGroupsHref)
}
return nil
}
}
Expand Down
30 changes: 24 additions & 6 deletions ibm/service/power/data_source_ibm_pi_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,33 @@ func DataSourceIBMPIInstances() *schema.Resource {
Description: "The MAC address of the instance.",
Type: schema.TypeString,
},
Attr_Macaddress: {
Attr_NetworkID: {
Computed: true,
Deprecated: "Deprecated, use mac_address instead",
Description: "The MAC address of the instance.",
Description: "The network ID of the instance.",
Type: schema.TypeString,
},
Attr_NetworkID: {
Attr_NetworkInterfaceID: {
Computed: true,
Description: "The network ID of the instance.",
Description: "ID of the network interface.",
Type: schema.TypeString,
},
Attr_NetworkName: {
Computed: true,
Description: "The network name of the instance.",
Type: schema.TypeString,
},
Attr_NetworkSecurityGroupIDs: {
Computed: true,
Description: "IDs of the network necurity groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeSet,
},
Attr_NetworkSecurityGroupsHref: {
Computed: true,
Description: "Links to the network security groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
Attr_Type: {
Computed: true,
Description: "The type of the network.",
Expand Down Expand Up @@ -331,11 +342,18 @@ func flattenPvmInstanceNetworks(list []*models.PVMInstanceNetwork) (networks []m
p := make(map[string]interface{})
p[Attr_ExternalIP] = pvmip.ExternalIP
p[Attr_IP] = pvmip.IPAddress
p[Attr_Macaddress] = pvmip.MacAddress
p[Attr_MacAddress] = pvmip.MacAddress
p[Attr_NetworkID] = pvmip.NetworkID
p[Attr_NetworkInterfaceID] = pvmip.NetworkInterfaceID
p[Attr_NetworkName] = pvmip.NetworkName
p[Attr_Type] = pvmip.Type
if len(pvmip.NetworkSecurityGroupIDs) > 0 {
p[Attr_NetworkSecurityGroupIDs] = pvmip.NetworkSecurityGroupIDs
}
if len(pvmip.NetworkSecurityGroupsHref) > 0 {
p[Attr_NetworkSecurityGroupsHref] = pvmip.NetworkSecurityGroupsHref
}

networks[i] = p
}
return networks
Expand Down
3 changes: 2 additions & 1 deletion ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,14 @@ const (
Attr_NetworkInterfaceID = "network_interface_id"
Attr_NetworkName = "network_name"
Attr_NetworkPeers = "network_peers"
Attr_NetworkPorts = "network_ports"
Attr_NetworkPortID = "network_port_id"
Attr_NetworkPorts = "network_ports"
Attr_Networks = "networks"
Attr_NetworkSecurityGroupID = "network_security_group_id"
Attr_NetworkSecurityGroupIDs = "network_security_group_ids"
Attr_NetworkSecurityGroupMemberID = "network_security_group_member_id"
Attr_NetworkSecurityGroups = "network_security_groups"
Attr_NetworkSecurityGroupsHref = "network_security_groups_href"
Attr_NumberOfVolumes = "number_of_volumes"
Attr_OnboardingID = "onboarding_id"
Attr_Onboardings = "onboardings"
Expand Down
56 changes: 41 additions & 15 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,47 @@ func ResourceIBMPIInstance() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Attr_IPAddress: {
Type: schema.TypeString,
Optional: true,
Computed: true,
Optional: true,
Type: schema.TypeString,
},
Attr_MacAddress: {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
},
Attr_NetworkID: {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
},
Attr_NetworkInterfaceID: {
Computed: true,
Description: "ID of the network interface.",
Type: schema.TypeString,
},
Attr_NetworkName: {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
},
Attr_NetworkSecurityGroupIDs: {
Computed: true,
Description: "Network security groups that the network interface is a member of. There is a limit of 1 network security group in the array. If not specified, default network security group is used.",
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Type: schema.TypeSet,
},
Attr_NetworkSecurityGroupsHref: {
Computed: true,
Description: "Links to the network security groups that the network interface is a member of.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
Attr_Type: {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
},
Attr_ExternalIP: {
Type: schema.TypeString,
Computed: true,
Type: schema.TypeString,
},
},
},
Expand Down Expand Up @@ -624,12 +642,19 @@ func resourceIBMPIInstanceRead(ctx context.Context, d *schema.ResourceData, meta
for _, n := range powervmdata.Networks {
if n != nil {
v := map[string]interface{}{
Attr_IPAddress: n.IPAddress,
Attr_MacAddress: n.MacAddress,
Attr_NetworkID: n.NetworkID,
Attr_NetworkName: n.NetworkName,
Attr_Type: n.Type,
Attr_ExternalIP: n.ExternalIP,
Attr_ExternalIP: n.ExternalIP,
Attr_IPAddress: n.IPAddress,
Attr_MacAddress: n.MacAddress,
Attr_NetworkID: n.NetworkID,
Attr_NetworkInterfaceID: n.NetworkInterfaceID,
Attr_NetworkName: n.NetworkName,
Attr_Type: n.Type,
}
if len(n.NetworkSecurityGroupIDs) > 0 {
v[Attr_NetworkSecurityGroupIDs] = n.NetworkSecurityGroupIDs
}
if len(n.NetworkSecurityGroupsHref) > 0 {
v[Attr_NetworkSecurityGroupsHref] = n.NetworkSecurityGroupsHref
}
networksMap = append(networksMap, v)
}
Expand Down Expand Up @@ -1514,8 +1539,9 @@ func expandPVMNetworks(networks []interface{}) []*models.PVMInstanceAddNetwork {
for _, v := range networks {
network := v.(map[string]interface{})
pvmInstanceNetwork := &models.PVMInstanceAddNetwork{
IPAddress: network[Attr_IPAddress].(string),
NetworkID: flex.PtrToString(network[Attr_NetworkID].(string)),
IPAddress: network[Attr_IPAddress].(string),
NetworkID: flex.PtrToString(network[Attr_NetworkID].(string)),
NetworkSecurityGroupIDs: flex.ExpandStringList((network[Attr_NetworkSecurityGroupIDs].(*schema.Set)).List()),
}
pvmNetworks = append(pvmNetworks, pvmInstanceNetwork)
}
Expand Down
54 changes: 49 additions & 5 deletions ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ func TestAccIBMPIInstanceStorageConnection(t *testing.T) {
func testAccCheckIBMPIInstanceStorageConnectionConfig(name, instanceHealthStatus string) string {
return fmt.Sprintf(`
resource "ibm_pi_volume" "power_volume" {
pi_cloud_instance_id = "%[1]s"
pi_volume_size = 1
pi_volume_name = "%[2]s"
pi_cloud_instance_id = "%[1]s"
pi_volume_size = 1
pi_volume_name = "%[2]s"
pi_volume_type = "tier3"
}
resource "ibm_pi_instance" "power_instance" {
Expand All @@ -130,6 +130,50 @@ func testAccCheckIBMPIInstanceStorageConnectionConfig(name, instanceHealthStatus
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, acc.Pi_storage_connection, instanceHealthStatus)
}
func testAccCheckIBMPIInstanceNetworkSecurityGroupConfig(name, instanceHealthStatus string) string {
return fmt.Sprintf(`
resource "ibm_pi_volume" "power_volume" {
pi_cloud_instance_id = "%[1]s"
pi_volume_size = 1
pi_volume_name = "%[2]s"
pi_volume_type = "tier3"
}
resource "ibm_pi_instance" "power_instance" {
pi_cloud_instance_id = "%[1]s"
pi_memory = "2"
pi_processors = "0.25"
pi_instance_name = "%[2]s"
pi_proc_type = "shared"
pi_image_id = "%[3]s"
pi_sys_type = "s922"
pi_network {
network_id = "%[4]s"
network_security_group_ids = ["%[6]s"]
}
pi_health_status = "%[5]s"
pi_volume_ids = [ibm_pi_volume.power_volume.volume_id]
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image, acc.Pi_network_name, instanceHealthStatus, acc.Pi_network_security_group_id)
}
func TestAccIBMPIInstanceNetworkSecurityGroup(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
name := fmt.Sprintf("tf-pi-instance-%d", acctest.RandIntRange(10, 100))
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMPIInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMPIInstanceNetworkSecurityGroupConfig(name, power.OK),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMPIInstanceExists(instanceRes),
resource.TestCheckResourceAttr(instanceRes, "pi_instance_name", name),
resource.TestCheckResourceAttr(instanceRes, "pi_network.0.network_security_group_ids.0", acc.Pi_network_security_group_id),
),
},
},
})
}

func TestAccIBMPIInstanceDeploymentTarget(t *testing.T) {
instanceRes := "ibm_pi_instance.power_instance"
Expand Down Expand Up @@ -450,7 +494,7 @@ func testAccIBMPIInstanceVTLConfig(name string) string {
pi_key_name = "%[2]s"
pi_ssh_key = "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEArb2aK0mekAdbYdY9rwcmeNSxqVCwez3WZTYEq+1Nwju0x5/vQFPSD2Kp9LpKBbxx3OVLN4VffgGUJznz9DAr7veLkWaf3iwEil6U4rdrhBo32TuDtoBwiczkZ9gn1uJzfIaCJAJdnO80Kv9k0smbQFq5CSb9H+F5VGyFue/iVd5/b30MLYFAz6Jg1GGWgw8yzA4Gq+nO7HtyuA2FnvXdNA3yK/NmrTiPCdJAtEPZkGu9LcelkQ8y90ArlKfjtfzGzYDE4WhOufFxyWxciUePh425J2eZvElnXSdGha+FCfYjQcvqpCVoBAG70U4fJBGjB+HL/GpCXLyiYXPrSnzC9w=="
}
resource "ibm_pi_network" "vtl_network" {
pi_cloud_instance_id = "%[1]s"
pi_network_name = "%[2]s"
Expand All @@ -472,7 +516,7 @@ func testAccIBMPIInstanceVTLConfig(name string) string {
network_id = ibm_pi_network.vtl_network.network_id
}
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_image)
}

Expand Down
4 changes: 3 additions & 1 deletion website/docs/d/pi_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ In addition to all argument reference list, you can access the following attribu
Nested scheme for `networks`:
- `external_ip` - (String) The external IP address of the instance.
- `ip` - (String) The IP address of the instance.
- `macaddress` - (String) The MAC address of the instance. Deprecated please use `mac_address` instead.
- `mac_address` - (String) The MAC address of the instance.
- `network_id` - (String) The network ID of the instance.
- `network_interface_id` - (String) ID of the network interface.
- `network_name` - (String) The network name of the instance.
- `network_security_group_ids` - (List) IDs of the network necurity groups that the network interface is a member of.
- `network_security_groups_href` - (List) Links to the network security groups that the network interface is a member of.
- `type` - (String) The type of the network.

- `pin_policy` - (String) The pinning policy of the instance.
Expand Down
Loading

0 comments on commit 1452f36

Please sign in to comment.