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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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.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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
15 changes: 10 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,27 @@ 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_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
24 changes: 22 additions & 2 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,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,
},
Expand All @@ -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.",
Expand All @@ -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
}
}
Expand Down
20 changes: 14 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,27 @@ 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_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 @@ -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
Expand Down
1 change: 1 addition & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 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,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.
Expand Down
20 changes: 14 additions & 6 deletions website/docs/d/pi_instance_ip.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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.
3 changes: 2 additions & 1 deletion website/docs/d/pi_instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading