Skip to content

Commit

Permalink
refactor of instance network attachment reference to use vni (#5563)
Browse files Browse the repository at this point in the history
  • Loading branch information
uibm authored Aug 21, 2024
1 parent eb56218 commit d509939
Show file tree
Hide file tree
Showing 16 changed files with 469 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require (
github.com/IBM/schematics-go-sdk v0.2.3
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.5
github.com/IBM/vpc-beta-go-sdk v0.6.0
github.com/IBM/vpc-go-sdk v0.56.0
github.com/IBM/vpc-go-sdk v0.57.0
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w
github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA=
github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc=
github.com/IBM/vpc-beta-go-sdk v0.6.0/go.mod h1:fzHDAQIqH/5yJmYsKodKHLcqxMDT+yfH6vZjdiw8CQA=
github.com/IBM/vpc-go-sdk v0.56.0 h1:GVlehMD2rYxETF2S/OSIgPHW7xZlfNsz1C59YLTVPis=
github.com/IBM/vpc-go-sdk v0.56.0/go.mod h1:BpIOxz9FRDsAY7NQFUYdxiPWjqvcRbBrw8fiAvzNqDE=
github.com/IBM/vpc-go-sdk v0.57.0 h1:E8CPDpUE4z0cvvmFZzqUthMtGJx71Fne6vdvkjZdXfg=
github.com/IBM/vpc-go-sdk v0.57.0/go.mod h1:swmxiYLT+OfBsBYqJWGeRd6NPmBk4u/het2PZdtzIaw=
github.com/Jeffail/gabs v1.1.1 h1:V0uzR08Hj22EX8+8QMhyI9sX2hwRu+/RJhJUmnwda/E=
github.com/Jeffail/gabs v1.1.1/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
Expand Down
83 changes: 83 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,40 @@ func DataSourceIBMIsBareMetalServer() *schema.Resource {
},
},
},
"virtual_network_interface": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The virtual network interface for this bare metal server network attachment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual network interface.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual network interface.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual network interface.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -592,6 +626,40 @@ func DataSourceIBMIsBareMetalServer() *schema.Resource {
},
},
},
"virtual_network_interface": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The virtual network interface for this bare metal server network attachment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual network interface.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual network interface.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual network interface.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1119,6 +1187,21 @@ func dataSourceIBMIsBareMetalServerBareMetalServerNetworkAttachmentReferenceToMa
return modelMap, err
}
modelMap["subnet"] = []map[string]interface{}{subnetMap}
virtualNetworkInterfaceMap, err := dataSourceIBMIsBareMetalServerVirtualNetworkInterfaceReferenceAttachmentContextToMap(model.VirtualNetworkInterface)
if err != nil {
return modelMap, err
}
modelMap["virtual_network_interface"] = []map[string]interface{}{virtualNetworkInterfaceMap}
return modelMap, nil
}

func dataSourceIBMIsBareMetalServerVirtualNetworkInterfaceReferenceAttachmentContextToMap(model *vpcv1.VirtualNetworkInterfaceReferenceAttachmentContext) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["crn"] = model.CRN
modelMap["href"] = model.Href
modelMap["id"] = model.ID
modelMap["name"] = model.Name
modelMap["resource_type"] = model.ResourceType
return modelMap, nil
}

Expand Down
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "primary_network_attachment.0.primary_ip.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "primary_network_attachment.0.resource_type"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "primary_network_attachment.0.subnet.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "primary_network_attachment.0.virtual_network_interface.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.href"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.id"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.name"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.primary_ip.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.resource_type"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.subnet.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_bare_metal_server.test1", "network_attachments.0.virtual_network_interface.#"),
),
},
},
Expand Down
68 changes: 68 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,40 @@ func DataSourceIBMIsBareMetalServers() *schema.Resource {
},
},
},
"virtual_network_interface": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The virtual network interface for this bare metal server network attachment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual network interface.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual network interface.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual network interface.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -564,6 +598,40 @@ func DataSourceIBMIsBareMetalServers() *schema.Resource {
},
},
},
"virtual_network_interface": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The virtual network interface for this bare metal server network attachment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual network interface.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual network interface.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual network interface.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_bare_metal_servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCKVmnMOlHKcZK8tpt3MP1lqOLAcqcJzhsvJcjscgVE
resource.TestCheckResourceAttrSet(resName, "servers.0.primary_network_attachment.0.primary_ip.#"),
resource.TestCheckResourceAttrSet(resName, "servers.0.primary_network_attachment.0.resource_type"),
resource.TestCheckResourceAttrSet(resName, "servers.0.primary_network_attachment.0.subnet.#"),
resource.TestCheckResourceAttrSet(resName, "servers.0.primary_network_attachment.0.virtual_network_interface.#"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.#"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.href"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.id"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.name"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.primary_ip.#"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.resource_type"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.subnet.#"),
resource.TestCheckResourceAttrSet(resName, "servers.0.network_attachments.0.virtual_network_interface.#"),
),
},
},
Expand Down
83 changes: 83 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,40 @@ func DataSourceIBMISInstance() *schema.Resource {
},
},
},
"virtual_network_interface": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The virtual network interface for this instance network attachment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual network interface.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual network interface.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual network interface.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -760,6 +794,40 @@ func DataSourceIBMISInstance() *schema.Resource {
},
},
},
"virtual_network_interface": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The virtual network interface for this instance network attachment.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this virtual network interface.",
},
"href": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The URL for this virtual network interface.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this virtual network interface.",
},
"name": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The name for this virtual network interface. The name is unique across all virtual network interfaces in the VPC.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1747,6 +1815,21 @@ func dataSourceIBMIsInstanceInstanceNetworkAttachmentReferenceToMap(model *vpcv1
return modelMap, err
}
modelMap["subnet"] = []map[string]interface{}{subnetMap}
virtualNetworkInterfaceMap, err := dataSourceIBMIsInstanceVirtualNetworkInterfaceReferenceAttachmentContextToMap(model.VirtualNetworkInterface)
if err != nil {
return modelMap, err
}
modelMap["virtual_network_interface"] = []map[string]interface{}{virtualNetworkInterfaceMap}
return modelMap, nil
}

func dataSourceIBMIsInstanceVirtualNetworkInterfaceReferenceAttachmentContextToMap(model *vpcv1.VirtualNetworkInterfaceReferenceAttachmentContext) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["crn"] = model.CRN
modelMap["href"] = model.Href
modelMap["id"] = model.ID
modelMap["name"] = model.Name
modelMap["resource_type"] = model.ResourceType
return modelMap, nil
}
func dataSourceIBMIsInstanceInstanceNetworkAttachmentReferenceDeletedToMap(model *vpcv1.InstanceNetworkAttachmentReferenceDeleted) (map[string]interface{}, error) {
Expand Down
25 changes: 24 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,22 @@ func TestAccIBMISInstanceDataSource_vni(t *testing.T) {
resName, "primary_network_attachment.0.id"),
resource.TestCheckResourceAttr(
resName, "primary_network_attachment.0.name", "test-vni"),
resource.TestCheckResourceAttr(
resName, "primary_network_attachment.0.virtual_network_interface.#", "1"),
resource.TestCheckResourceAttrSet(
resName, "primary_network_attachment.0.primary_ip.#"),
resource.TestCheckResourceAttrSet(
resName, "primary_network_attachment.0.subnet.#"),
resource.TestCheckResourceAttrSet(
resName, "network_attachments.#"),
resource.TestCheckResourceAttrSet(
resName, "network_attachments.0.id"),
resource.TestCheckResourceAttr(
resName, "network_attachments.0.virtual_network_interface.#", "1"),
resource.TestCheckResourceAttrSet(
resName, "network_attachments.0.primary_ip.#"),
resource.TestCheckResourceAttrSet(
resName, "network_attachments.0.subnet.#"),
),
},
},
Expand Down Expand Up @@ -302,6 +314,11 @@ resource "ibm_is_virtual_network_interface" "testacc_vni"{
allow_ip_spoofing = true
subnet = ibm_is_subnet.testacc_subnet.id
}
resource "ibm_is_virtual_network_interface" "testacc_vni2"{
name = "%s-2"
allow_ip_spoofing = true
subnet = ibm_is_subnet.testacc_subnet.id
}
resource "ibm_is_instance" "testacc_instance" {
name = "%s"
Expand All @@ -313,6 +330,12 @@ resource "ibm_is_instance" "testacc_instance" {
id = ibm_is_virtual_network_interface.testacc_vni.id
}
}
network_attachments {
name = "test-vni-sec"
virtual_network_interface {
id = ibm_is_virtual_network_interface.testacc_vni2.id
}
}
vpc = ibm_is_vpc.testacc_vpc.id
zone = "%s"
keys = [ibm_is_ssh_key.testacc_sshkey.id]
Expand All @@ -321,7 +344,7 @@ data "ibm_is_instance" "ds_instance" {
name = ibm_is_instance.testacc_instance.name
private_key = file("./test-fixtures/.ssh/id_rsa")
passphrase = ""
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, vniname, instanceName, acc.IsWinImage, acc.InstanceProfileName, acc.ISZoneName)
}`, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, vniname, vniname, instanceName, acc.IsWinImage, acc.InstanceProfileName, acc.ISZoneName)
}
func testAccCheckIBMISInstanceDataSourcePKCS8SSHConfig(vpcname, subnetname, sshname, instanceName string) string {
return fmt.Sprintf(`
Expand Down
Loading

0 comments on commit d509939

Please sign in to comment.