Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Network Interface and NSG Href To Instance Network #179

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.23.4
require (
github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
github.com/IBM-Cloud/power-go-client v1.9.0
github.com/IBM-Cloud/power-go-client v1.10.0-beta7
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
github.com/IBM/appconfiguration-go-admin-sdk v0.4.4
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20241117121028-a3be206688b3/go.mod h1:/7h
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
github.com/IBM-Cloud/power-go-client v1.9.0-beta7 h1:ePYmNBoRsPBojv1mLRPLMgzRruExuop0twNx0UIwg+I=
github.com/IBM-Cloud/power-go-client v1.9.0-beta7/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
github.com/IBM-Cloud/power-go-client v1.9.0 h1:nnErpb/7TJQe8P7OfIlJPhSJVq5oyuCJlMje9Ry6XEY=
github.com/IBM-Cloud/power-go-client v1.9.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/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 @@ -135,22 +135,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)
michaelkad marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -111,22 +111,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 @@ -325,11 +336,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
4 changes: 3 additions & 1 deletion ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,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
58 changes: 42 additions & 16 deletions ibm/service/power/resource_ibm_pi_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,29 +176,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 @@ -621,12 +639,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 @@ -1511,8 +1536,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 Expand Up @@ -1727,7 +1753,7 @@ func createPVMInstance(d *schema.ResourceData, client *instance.IBMPIInstanceCli
SysType: systype,
ImageID: flex.PtrToString(imageid),
ProcType: flex.PtrToString(processortype),
Replicants: replicants,
Replicants: &replicants,
UserData: encodeBase64(userData),
ReplicantNamingScheme: flex.PtrToString(replicationNamingScheme),
ReplicantAffinityPolicy: flex.PtrToString(replicationpolicy),
Expand Down
50 changes: 47 additions & 3 deletions ibm/service/power/resource_ibm_pi_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ func testAccCheckIBMPIInstanceUserTagsConfig(name, instanceHealthStatus string,
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 @@ -323,6 +323,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 = "1"
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 testAccCheckIBMPIInstanceDestroy(s *terraform.State) error {
sess, err := acc.TestAccProvider.Meta().(conns.ClientSession).IBMPISession()
if err != nil {
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 @@ -78,10 +78,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
Loading