update tests, fix instances
This commit is contained in:
parent
15d93749e8
commit
1f9cf2f4c3
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/go-oracle-terraform/compute"
|
||||
|
@ -837,8 +838,20 @@ func readNetworkInterfaces(d *schema.ResourceData, ifaces map[string]compute.Net
|
|||
return d.Set("networking_info", result)
|
||||
}
|
||||
|
||||
for _, iface := range ifaces {
|
||||
for index, iface := range ifaces {
|
||||
res := make(map[string]interface{})
|
||||
// The index returned from the SDK holds the full device_index from the instance.
|
||||
// For users convenience, we simply allow them to specify the integer equivalent of the device_index
|
||||
// so a user could implement several network interfaces via `count`.
|
||||
// Convert the full device_index `ethN` to `N` as an integer.
|
||||
index := strings.TrimPrefix(index, "eth")
|
||||
indexInt, err := strconv.Atoi(index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
res["index"] = indexInt
|
||||
|
||||
// Set the proper attributes for this specific network interface
|
||||
if iface.DNS != nil {
|
||||
res["dns"] = iface.DNS
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// TODO (@jake): Properly create a vNIC Set once instances are finished
|
||||
func TestAccOPCRoute_Basic(t *testing.T) {
|
||||
rInt := acctest.RandInt()
|
||||
resName := "opc_compute_route.test"
|
||||
|
@ -41,13 +40,37 @@ func TestAccOPCRoute_Basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// TODO (@jake): Properly create a vNIC Set once instances are finished
|
||||
func testAccOPCRouteConfig_Basic(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "opc_compute_ip_network" "foo" {
|
||||
name = "testing-route-%d"
|
||||
description = "testing-route"
|
||||
ip_address_prefix = "10.1.14.0/24"
|
||||
}
|
||||
|
||||
resource "opc_compute_instance" "foo" {
|
||||
name = "test-route-%d"
|
||||
label = "testing"
|
||||
shape = "oc3"
|
||||
image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
|
||||
networking_info {
|
||||
index = 0
|
||||
ip_network = "${opc_compute_ip_network.foo.id}"
|
||||
vnic = "test-vnic-set-%d"
|
||||
shared_network = false
|
||||
}
|
||||
}
|
||||
|
||||
data "opc_compute_network_interface" "foo" {
|
||||
instance_name = "${opc_compute_instance.foo.name}"
|
||||
instance_id = "${opc_compute_instance.foo.id}"
|
||||
interface = "eth0"
|
||||
}
|
||||
|
||||
resource "opc_compute_vnic_set" "test" {
|
||||
name = "route-test-%d"
|
||||
description = "route-testing-%d"
|
||||
virtual_nics = ["jake-manual_eth1"]
|
||||
virtual_nics = ["${data.opc_compute_network_interface.foo.vnic}"]
|
||||
}
|
||||
|
||||
resource "opc_compute_route" "test" {
|
||||
|
@ -56,15 +79,40 @@ resource "opc_compute_route" "test" {
|
|||
admin_distance = 1
|
||||
ip_address_prefix = "10.0.12.0/24"
|
||||
next_hop_vnic_set = "${opc_compute_vnic_set.test.name}"
|
||||
}`, rInt, rInt, rInt, rInt)
|
||||
}`, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
|
||||
}
|
||||
|
||||
func testAccOPCRouteConfig_BasicUpdate(rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "opc_compute_ip_network" "foo" {
|
||||
name = "testing-route-%d"
|
||||
description = "testing-route"
|
||||
ip_address_prefix = "10.1.14.0/24"
|
||||
}
|
||||
|
||||
resource "opc_compute_instance" "foo" {
|
||||
name = "test-route-%d"
|
||||
label = "testing"
|
||||
shape = "oc3"
|
||||
image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
|
||||
networking_info {
|
||||
index = 0
|
||||
ip_network = "${opc_compute_ip_network.foo.id}"
|
||||
vnic = "test-vnic-set-%d"
|
||||
shared_network = false
|
||||
}
|
||||
}
|
||||
|
||||
data "opc_compute_network_interface" "foo" {
|
||||
instance_name = "${opc_compute_instance.foo.name}"
|
||||
instance_id = "${opc_compute_instance.foo.id}"
|
||||
interface = "eth0"
|
||||
}
|
||||
|
||||
resource "opc_compute_vnic_set" "test" {
|
||||
name = "route-test-%d"
|
||||
description = "route-testing-%d"
|
||||
virtual_nics = ["jake-manual_eth1"]
|
||||
virtual_nics = ["${data.opc_compute_network_interface.foo.vnic}"]
|
||||
}
|
||||
|
||||
resource "opc_compute_route" "test" {
|
||||
|
@ -73,7 +121,7 @@ resource "opc_compute_route" "test" {
|
|||
admin_distance = 2
|
||||
ip_address_prefix = "10.0.14.0/24"
|
||||
next_hop_vnic_set = "${opc_compute_vnic_set.test.name}"
|
||||
}`, rInt, rInt, rInt, rInt)
|
||||
}`, rInt, rInt, rInt, rInt, rInt, rInt, rInt)
|
||||
}
|
||||
|
||||
func testAccOPCCheckRouteExists(s *terraform.State) error {
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
// TODO (@jake): Add actual vnics after instance resource is finalized
|
||||
func TestAccOPCVNICSet_Basic(t *testing.T) {
|
||||
rInt := acctest.RandInt()
|
||||
rName := fmt.Sprintf("testing-acc-%d", rInt)
|
||||
|
@ -22,7 +21,7 @@ func TestAccOPCVNICSet_Basic(t *testing.T) {
|
|||
CheckDestroy: testAccOPCCheckVNICSetDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccVnicSetBasic(rName, rDesc),
|
||||
Config: testAccVnicSetBasic(rName, rDesc, rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccOPCCheckVNICSetExists,
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -36,7 +35,7 @@ func TestAccOPCVNICSet_Basic(t *testing.T) {
|
|||
),
|
||||
},
|
||||
{
|
||||
Config: testAccVnicSetBasic_Update(rName, rDesc),
|
||||
Config: testAccVnicSetBasic_Update(rName, rDesc, rInt),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccOPCCheckVNICSetExists,
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -91,23 +90,114 @@ func testAccOPCCheckVNICSetDestroy(s *terraform.State) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// TODO (@jake): add actual vnics once instance resource is finalized
|
||||
func testAccVnicSetBasic(rName, rDesc string) string {
|
||||
func testAccVnicSetBasic(rName, rDesc string, rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "opc_compute_ip_network" "foo" {
|
||||
name = "testing-vnic-set-%d"
|
||||
description = "testing-vnic-set"
|
||||
ip_address_prefix = "10.1.14.0/24"
|
||||
}
|
||||
|
||||
resource "opc_compute_ip_network" "bar" {
|
||||
name = "testing-vnic-set2-%d"
|
||||
description = "testing-vnic-set2"
|
||||
ip_address_prefix = "10.1.15.0/24"
|
||||
}
|
||||
|
||||
resource "opc_compute_instance" "foo" {
|
||||
name = "test-vnic-set-%d"
|
||||
label = "testing"
|
||||
shape = "oc3"
|
||||
image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
|
||||
networking_info {
|
||||
index = 0
|
||||
ip_network = "${opc_compute_ip_network.foo.id}"
|
||||
vnic = "test-vnic-set-%d"
|
||||
shared_network = false
|
||||
}
|
||||
networking_info {
|
||||
index = 1
|
||||
ip_network = "${opc_compute_ip_network.bar.id}"
|
||||
vnic = "test-vnic-set2-%d"
|
||||
shared_network = false
|
||||
}
|
||||
}
|
||||
|
||||
data "opc_compute_network_interface" "foo" {
|
||||
instance_name = "${opc_compute_instance.foo.name}"
|
||||
instance_id = "${opc_compute_instance.foo.id}"
|
||||
interface = "eth0"
|
||||
}
|
||||
|
||||
data "opc_compute_network_interface" "bar" {
|
||||
instance_name = "${opc_compute_instance.foo.name}"
|
||||
instance_id = "${opc_compute_instance.foo.id}"
|
||||
interface = "eth1"
|
||||
}
|
||||
|
||||
resource "opc_compute_vnic_set" "test" {
|
||||
name = "%s"
|
||||
description = "%s"
|
||||
tags = ["tag1", "tag2"]
|
||||
virtual_nics = ["jake-manual_eth1", "jake_manual_two_eth1"]
|
||||
}`, rName, rDesc)
|
||||
virtual_nics = [
|
||||
"${data.opc_compute_network_interface.foo.vnic}",
|
||||
"${data.opc_compute_network_interface.bar.vnic}",
|
||||
]
|
||||
}`, rInt, rInt, rInt, rInt, rInt, rName, rDesc)
|
||||
}
|
||||
|
||||
func testAccVnicSetBasic_Update(rName, rDesc string) string {
|
||||
func testAccVnicSetBasic_Update(rName, rDesc string, rInt int) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "opc_compute_ip_network" "foo" {
|
||||
name = "testing-vnic-set-%d"
|
||||
description = "testing-vnic-set"
|
||||
ip_address_prefix = "10.1.14.0/24"
|
||||
}
|
||||
|
||||
resource "opc_compute_ip_network" "bar" {
|
||||
name = "testing-vnic-set2-%d"
|
||||
description = "testing-vnic-set2"
|
||||
ip_address_prefix = "10.1.15.0/24"
|
||||
}
|
||||
|
||||
resource "opc_compute_instance" "foo" {
|
||||
name = "test-vnic-set-%d"
|
||||
label = "testing"
|
||||
shape = "oc3"
|
||||
image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
|
||||
networking_info {
|
||||
index = 0
|
||||
ip_network = "${opc_compute_ip_network.foo.id}"
|
||||
vnic = "test-vnic-set-%d"
|
||||
shared_network = false
|
||||
}
|
||||
networking_info {
|
||||
index = 1
|
||||
ip_network = "${opc_compute_ip_network.bar.id}"
|
||||
vnic = "test-vnic-set2-%d"
|
||||
shared_network = false
|
||||
}
|
||||
}
|
||||
|
||||
data "opc_compute_network_interface" "foo" {
|
||||
instance_name = "${opc_compute_instance.foo.name}"
|
||||
instance_id = "${opc_compute_instance.foo.id}"
|
||||
interface = "eth0"
|
||||
}
|
||||
|
||||
data "opc_compute_network_interface" "bar" {
|
||||
instance_name = "${opc_compute_instance.foo.name}"
|
||||
instance_id = "${opc_compute_instance.foo.id}"
|
||||
interface = "eth1"
|
||||
}
|
||||
|
||||
resource "opc_compute_vnic_set" "test" {
|
||||
name = "%s"
|
||||
description = "%s-updated"
|
||||
virtual_nics = ["jake-manual_eth1", "jake_manual_two_eth1"]
|
||||
tags = ["tag1"]
|
||||
}`, rName, rDesc)
|
||||
virtual_nics = [
|
||||
"${data.opc_compute_network_interface.foo.vnic}",
|
||||
"${data.opc_compute_network_interface.bar.vnic}",
|
||||
]
|
||||
}`, rInt, rInt, rInt, rInt, rInt, rName, rDesc)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue