From adcaf160b33dddd14b28c5d41899ea2282cfffc8 Mon Sep 17 00:00:00 2001 From: michaelkad Date: Wed, 13 Nov 2024 11:41:29 -0600 Subject: [PATCH] Add Network Interface and NSG Href To Instance Network --- go.mod | 2 +- go.sum | 2 ++ .../power/data_source_ibm_pi_instance.go | 15 ++++++++---- .../power/data_source_ibm_pi_instance_ip.go | 24 +++++++++++++++++-- .../power/data_source_ibm_pi_instances.go | 20 +++++++++++----- ibm/service/power/ibm_pi_constants.go | 1 + website/docs/d/pi_instance.html.markdown | 3 ++- website/docs/d/pi_instance_ip.html.markdown | 20 +++++++++++----- website/docs/d/pi_instances.html.markdown | 3 ++- 9 files changed, 68 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index e8b9169896..31f56eb0ad 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.5 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.8.3 + github.com/IBM-Cloud/power-go-client v1.9.0-beta7 github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca github.com/IBM/appconfiguration-go-admin-sdk v0.3.0 github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f diff --git a/go.sum b/go.sum index 0ffc92f67e..ca96cb1380 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,8 @@ 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.8.3 h1:QsBuIS6KvKsiEpe0yiHYKhWgXlqkcJ7XqFHtATj8Yh4= github.com/IBM-Cloud/power-go-client v1.8.3/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0= +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/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= diff --git a/ibm/service/power/data_source_ibm_pi_instance.go b/ibm/service/power/data_source_ibm_pi_instance.go index 95d20b330e..ce8cf9953a 100644 --- a/ibm/service/power/data_source_ibm_pi_instance.go +++ b/ibm/service/power/data_source_ibm_pi_instance.go @@ -135,15 +135,14 @@ 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: { @@ -151,6 +150,12 @@ func DataSourceIBMPIInstance() *schema.Resource { Description: "The network name of the instance.", Type: schema.TypeString, }, + 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.", diff --git a/ibm/service/power/data_source_ibm_pi_instance_ip.go b/ibm/service/power/data_source_ibm_pi_instance_ip.go index 624affe36e..f6179a364a 100644 --- a/ibm/service/power/data_source_ibm_pi_instance_ip.go +++ b/ibm/service/power/data_source_ibm_pi_instance_ip.go @@ -5,7 +5,6 @@ package power import ( "context" - "log" "net" "strconv" @@ -56,8 +55,14 @@ func DataSourceIBMPIInstanceIP() *schema.Resource { Description: "The IP octet of the network that is attached to this instance.", Type: schema.TypeString, }, + Attr_MacAddress: { + Computed: true, + Description: "The MAC address of the network that is attached to this instance.", + Type: schema.TypeString, + }, 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, }, @@ -66,6 +71,17 @@ 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_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.", @@ -92,18 +108,22 @@ 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_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.NetworkSecurityGroupsHref) > 0 { + d.Set(Attr_NetworkSecurityGroupsHref, network.NetworkSecurityGroupsHref) + } return nil } } diff --git a/ibm/service/power/data_source_ibm_pi_instances.go b/ibm/service/power/data_source_ibm_pi_instances.go index fcfc9ff25c..26692f3cfc 100644 --- a/ibm/service/power/data_source_ibm_pi_instances.go +++ b/ibm/service/power/data_source_ibm_pi_instances.go @@ -111,15 +111,14 @@ 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: { @@ -127,6 +126,12 @@ func DataSourceIBMPIInstances() *schema.Resource { Description: "The network name of the instance.", Type: schema.TypeString, }, + 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.", @@ -302,11 +307,14 @@ 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.NetworkSecurityGroupsHref) > 0 { + p[Attr_NetworkSecurityGroupsHref] = pvmip.NetworkSecurityGroupsHref + } networks[i] = p } return networks diff --git a/ibm/service/power/ibm_pi_constants.go b/ibm/service/power/ibm_pi_constants.go index 77ae403ce0..967fcaf887 100644 --- a/ibm/service/power/ibm_pi_constants.go +++ b/ibm/service/power/ibm_pi_constants.go @@ -287,6 +287,7 @@ const ( Attr_NetworkSecurityGroupID = "network_security_group_id" Attr_NetworkSecurityGroupMemberID = "network_security_group_member_id" Attr_NetworkSecurityGroups = "network_security_groups" + Attr_NetworkSecurityGroupsHref = "network_security_groups_href" Attr_NumberOfVolumes = "number_of_volumes" Attr_Onboardings = "onboardings" Attr_OperatingSystem = "operating_system" diff --git a/website/docs/d/pi_instance.html.markdown b/website/docs/d/pi_instance.html.markdown index 1b5785f36f..09f28b2a3d 100644 --- a/website/docs/d/pi_instance.html.markdown +++ b/website/docs/d/pi_instance.html.markdown @@ -78,10 +78,11 @@ 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_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. diff --git a/website/docs/d/pi_instance_ip.html.markdown b/website/docs/d/pi_instance_ip.html.markdown index 8f1942cc83..a898b0e2ce 100644 --- a/website/docs/d/pi_instance_ip.html.markdown +++ b/website/docs/d/pi_instance_ip.html.markdown @@ -7,9 +7,11 @@ description: |- --- # ibm_pi_instance_ip + Retrieve information about a Power Systems Virtual Server instance IP address. For more information, about Power Systems Virtual Server instance IP address, see [configuring and adding a private network subnet](https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-configuring-subnet). ## Example usage + ```terraform data "ibm_pi_instance_ip" "ds_instance_ip" { pi_instance_name = "terraform-test-instance" @@ -18,13 +20,15 @@ data "ibm_pi_instance_ip" "ds_instance_ip" { } ``` -**Notes** +### Notes + - Please find [supported Regions](https://cloud.ibm.com/apidocs/power-cloud#endpoint) for endpoints. - If a Power cloud instance is provisioned at `lon04`, The provider level attributes should be as follows: - `region` - `lon` - `zone` - `lon04` Example usage: + ```terraform provider "ibm" { region = "lon" @@ -33,20 +37,24 @@ Example usage: ``` ## Argument reference -Review the argument references that you can specify for your data source. + +Review the argument references that you can specify for your data source. - `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account. - `pi_instance_name` - (Required, String) The unique identifier or name of the instance. -- `pi_network_name` - (Required, String) The subnet that the instance belongs to. - +- `pi_network_name` - (Required, String) The subnet that the instance belongs to. ## Attribute reference -In addition to all argument reference list, you can access the following attribute references after your data source is created. + +In addition to all argument reference list, you can access the following attribute references after your data source is created. - `external_ip` - (String) The external IP of the network that is attached to this instance. - `id` - (String) The unique identifier of the network. - `ip` - (String) The IP address that is attached to this instance from the subnet. - `ipoctet` - (String) The IP octet of the network that is attached to this instance. -- `macaddress` - (String) The MAC address of the network that is attached to this instance. +- `mac_address` - (String) The MAC address of the network that is attached to this instance. +- `macaddress` - (String) The MAC address of the network that is attached to this instance. Deprecated please use `mac_address` instead. - `network_id` - (String) ID of the network. +- `network_interface_id` - (String) ID of the network interface. +- `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 that is attached to this instance. diff --git a/website/docs/d/pi_instances.html.markdown b/website/docs/d/pi_instances.html.markdown index 0897d28cf3..299b9b8a2c 100644 --- a/website/docs/d/pi_instances.html.markdown +++ b/website/docs/d/pi_instances.html.markdown @@ -70,10 +70,11 @@ 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_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.