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

#669 ip_endpoint_list type #693

Open
wants to merge 2 commits into
base: feat/1.9.6
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
15 changes: 11 additions & 4 deletions nutanix/resource_nutanix_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,10 @@ func resourceNutanixVirtualMachine() *schema.Resource {
Computed: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"ASSIGNED"}, false),
},
},
},
Expand Down Expand Up @@ -1664,9 +1665,15 @@ func expandIPAddressList(ipl []interface{}) []*v3.IPAddress {
if ipset, ipsetok := v["ip"]; ipsetok {
v3ip.IP = utils.StringPtr(ipset.(string))
}
if iptype, iptypeok := v["type"]; iptypeok {
// Check if 'type' is provided
if iptype, iptypeok := v["type"]; !iptypeok || iptype == "" {
// ip type not provided, set a default value to ASSIGNED
log.Printf("[DEBUG] IP type not provided, setting default value to ASSIGNED")
v3ip.Type = utils.StringPtr("ASSIGNED")
} else {
v3ip.Type = utils.StringPtr(iptype.(string))
}

ip[k] = v3ip
}
return ip
Expand Down
182 changes: 182 additions & 0 deletions nutanix/resource_nutanix_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func TestAccNutanixVirtualMachine_WithSubnet(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", "1"),
resource.TestCheckResourceAttr(resourceName, "categories.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "nic_list_status.0.ip_endpoint_list.0.ip"),
resource.TestCheckResourceAttr(resourceName, "nic_list_status.0.ip_endpoint_list.0.type", "ASSIGNED"),
),
},
{
Expand Down Expand Up @@ -618,6 +619,36 @@ func TestAccNutanixVirtualMachine_SecureBoot(t *testing.T) {
})
}

func TestAccNutanixVirtualMachine_WithNicListIpType(t *testing.T) {
r := acctest.RandIntRange(101, 110)
resourceName := "nutanix_virtual_machine.vm3"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNutanixVirtualMachineDestroy,
Steps: []resource.TestStep{
{
Config: testaccnutanixvmconfigwithniclistIPType(r),
Check: resource.ComposeTestCheckFunc(
testAccCheckNutanixVirtualMachineExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "hardware_clock_timezone", "UTC"),
resource.TestCheckResourceAttr(resourceName, "power_state", "ON"),
resource.TestCheckResourceAttr(resourceName, "memory_size_mib", "186"),
resource.TestCheckResourceAttr(resourceName, "num_sockets", "1"),
resource.TestCheckResourceAttr(resourceName, "num_vcpus_per_socket", "1"),
resource.TestCheckResourceAttr(resourceName, "categories.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "nic_list_status.0.ip_endpoint_list.0.ip"),
resource.TestCheckResourceAttr(resourceName, "nic_list_status.0.ip_endpoint_list.0.type", "ASSIGNED"),
),
},
{
Config: testaccnutanixvmconfigwithniclistIPTypeWrongType(r),
ExpectError: regexp.MustCompile(`Error: expected nic_list.0.ip_endpoint_list.0.type to be one of ` + `[ASSIGNED], got WRONG`),
},
},
})
}

func TestAccNutanixVirtualMachine_SecureBootWithNoMachineType(t *testing.T) {
r := acctest.RandInt()
name := fmt.Sprintf("test-vm-%d", r)
Expand Down Expand Up @@ -1602,3 +1633,154 @@ func testAccNutanixVMConfigWithSecureBootWithNoMachineType(name, desc, mem strin

`, name, desc, mem)
}

func testaccnutanixvmconfigwithniclistIPType(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}

locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

resource "nutanix_subnet" "sub" {
cluster_uuid = "${local.cluster1}"

# General Information for subnet
name = "terraform-vm-with-subnet-%[1]d"
description = "Description of my unit test VLAN"
vlan_id = %[1]d
subnet_type = "VLAN"

# Provision a Managed L3 Network
# This bit is only needed if you intend to turn on AHV's IPAM
subnet_ip = "10.250.140.0"
default_gateway_ip = "10.250.140.1"
prefix_length = 24
dhcp_options = {
boot_file_name = "bootfile"
domain_name = "nutanix"
tftp_server_name = "10.250.140.200"
}
dhcp_domain_name_server_list = ["8.8.8.8", "4.2.2.2"]
dhcp_domain_search_list = ["terraform.nutanix.com", "terraform.unit.test.com"]
ip_config_pool_list_ranges = ["10.250.140.20 10.250.140.100"]
}

resource "nutanix_image" "cirros-034-disk" {
name = "test-image-dou-%[1]d"
source_uri = "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
description = "heres a tiny linux image, not an iso, but a real disk!"
}

resource "nutanix_virtual_machine" "vm3" {
name = "test-dou-vm-%[1]d"

categories {
name = "Environment"
value = "Staging"
}

cluster_uuid = "${local.cluster1}"
num_vcpus_per_socket = 1
num_sockets = 1
memory_size_mib = 186

disk_list {
data_source_reference = {
kind = "image"
uuid = "${nutanix_image.cirros-034-disk.id}"
}
}

nic_list {
subnet_uuid = "${nutanix_subnet.sub.id}"
ip_endpoint_list {
ip = "10.250.140.76"
type = "ASSIGNED"
}
}
}

output "ip_address" {
value = "${lookup(nutanix_virtual_machine.vm3.nic_list_status.0.ip_endpoint_list[0], "ip")}"
}
`, r)
}
func testaccnutanixvmconfigwithniclistIPTypeWrongType(r int) string {
return fmt.Sprintf(`
data "nutanix_clusters" "clusters" {}

locals {
cluster1 = [
for cluster in data.nutanix_clusters.clusters.entities :
cluster.metadata.uuid if cluster.service_list[0] != "PRISM_CENTRAL"
][0]
}

resource "nutanix_subnet" "sub" {
cluster_uuid = "${local.cluster1}"

# General Information for subnet
name = "terraform-vm-with-subnet-%[1]d"
description = "Description of my unit test VLAN"
vlan_id = %[1]d
subnet_type = "VLAN"

# Provision a Managed L3 Network
# This bit is only needed if you intend to turn on AHV's IPAM
subnet_ip = "10.250.140.0"
default_gateway_ip = "10.250.140.1"
prefix_length = 24
dhcp_options = {
boot_file_name = "bootfile"
domain_name = "nutanix"
tftp_server_name = "10.250.140.200"
}
dhcp_domain_name_server_list = ["8.8.8.8", "4.2.2.2"]
dhcp_domain_search_list = ["terraform.nutanix.com", "terraform.unit.test.com"]
ip_config_pool_list_ranges = ["10.250.140.20 10.250.140.100"]
}

resource "nutanix_image" "cirros-034-disk" {
name = "test-image-dou-%[1]d"
source_uri = "http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img"
description = "heres a tiny linux image, not an iso, but a real disk!"
}

resource "nutanix_virtual_machine" "vm3" {
name = "test-dou-vm-%[1]d"

categories {
name = "Environment"
value = "Staging"
}

cluster_uuid = "${local.cluster1}"
num_vcpus_per_socket = 1
num_sockets = 1
memory_size_mib = 186

disk_list {
data_source_reference = {
kind = "image"
uuid = "${nutanix_image.cirros-034-disk.id}"
}
}

nic_list {
subnet_uuid = "${nutanix_subnet.sub.id}"
ip_endpoint_list {
ip = "10.250.140.76"
type = "WRONG"
}
}
}

output "ip_address" {
value = "${lookup(nutanix_virtual_machine.vm3.nic_list_status.0.ip_endpoint_list[0], "ip")}"
}
`, r)
}
Loading