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

feat: vm agent interface prefixes #70

Closed
wants to merge 4 commits into from
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## v0.5.0 (UNRELEASED)

ENHANCEMENTS:

* resource/virtual_environment_vm: Add `agent.prefixes` argument

OTHER:

* provider/example: Remove support for Terraform v0.11 and older
Expand Down
1 change: 1 addition & 0 deletions docs/resources/virtual_environment_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ output "ubuntu_vm_public_key" {
* `acpi` - (Optional) Whether to enable ACPI (defaults to `true`).
* `agent` - (Optional) The QEMU agent configuration.
* `enabled` - (Optional) Whether to enable the QEMU agent (defaults to `false`).
* `prefixes` - (Optional) The prefixes for the network interfaces which need to have an IP assigned before continuing (defaults to `["eno","enp","ens","eth","tun"]`).
* `timeout` - (Optional) The maximum amount of time to wait for data from the QEMU agent to become available (defaults to `15m`).
* `trim` - (Optional) Whether to enable the FSTRIM feature in the QEMU agent (defaults to `false`).
* `type` - (Optional) The QEMU agent interface type (defaults to `virtio`).
Expand Down
16 changes: 8 additions & 8 deletions proxmox/virtual_environment_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func (c *VirtualEnvironmentClient) UpdateVMAsync(nodeName string, vmID int, d *V
}

// WaitForNetworkInterfacesFromVMAgent waits for a virtual machine's QEMU agent to publish the network interfaces.
func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(nodeName string, vmID int, timeout int, delay int, waitForIP bool) (*VirtualEnvironmentVMGetQEMUNetworkInterfacesResponseData, error) {
func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(nodeName string, vmID int, timeout int, delay int, waitForIP bool, interfacePrefixes []string) (*VirtualEnvironmentVMGetQEMUNetworkInterfacesResponseData, error) {
timeDelay := int64(delay)
timeMax := float64(timeout)
timeStart := time.Now()
Expand All @@ -384,13 +384,13 @@ func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(nodeName

if waitForIP {
for _, nic := range *data.Result {
if nic.Name == "lo" {
continue
}

if nic.IPAddresses == nil || (nic.IPAddresses != nil && len(*nic.IPAddresses) == 0) {
missingIP = true
break
for _, prefix := range interfacePrefixes {
if strings.HasPrefix(nic.Name, prefix) {
if nic.IPAddresses == nil || (nic.IPAddresses != nil && len(*nic.IPAddresses) == 0) {
missingIP = true
break
}
}
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions proxmoxtf/resource_virtual_environment_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const (
mkResourceVirtualEnvironmentVMACPI = "acpi"
mkResourceVirtualEnvironmentVMAgent = "agent"
mkResourceVirtualEnvironmentVMAgentEnabled = "enabled"
mkResourceVirtualEnvironmentVMAgentPrefixes = "prefixes"
mkResourceVirtualEnvironmentVMAgentTimeout = "timeout"
mkResourceVirtualEnvironmentVMAgentTrim = "trim"
mkResourceVirtualEnvironmentVMAgentType = "type"
Expand Down Expand Up @@ -235,6 +236,21 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
Optional: true,
Default: dvResourceVirtualEnvironmentVMAgentEnabled,
},
mkResourceVirtualEnvironmentVMAgentPrefixes: {
Type: schema.TypeList,
Description: "The prefixes for the network interfaces which need to have an IP assigned before continuing",
Optional: true,
DefaultFunc: func() (interface{}, error) {
return []interface{}{
"eno",
"enp",
"ens",
"eth",
"tun",
}, nil
},
Elem: &schema.Schema{Type: schema.TypeString},
},
mkResourceVirtualEnvironmentVMAgentTimeout: {
Type: schema.TypeString,
Description: "The maximum amount of time to wait for data from the QEMU agent to become available",
Expand Down Expand Up @@ -1798,7 +1814,7 @@ func resourceVirtualEnvironmentVMCreateCustomDisks(d *schema.ResourceData, m int
fileFormat, _ := block[mkResourceVirtualEnvironmentVMDiskFileFormat].(string)
size, _ := block[mkResourceVirtualEnvironmentVMDiskSize].(int)
speed := block[mkResourceVirtualEnvironmentVMDiskSpeed].([]interface{})
diskInterface,_ := block[mkResourcevirtualEnvironmentVMDiskInterface].(string)
diskInterface, _ := block[mkResourcevirtualEnvironmentVMDiskInterface].(string)

if len(speed) == 0 {
diskSpeedDefault, err := diskSpeedResource.DefaultValue()
Expand Down Expand Up @@ -3032,14 +3048,21 @@ func resourceVirtualEnvironmentVMReadNetworkValues(d *schema.ResourceData, m int
return err
}

agentPrefixes := agentBlock[mkResourceVirtualEnvironmentVMAgentPrefixes].([]interface{})
agentTimeout, err := time.ParseDuration(agentBlock[mkResourceVirtualEnvironmentVMAgentTimeout].(string))

if err != nil {
return err
}

interfacePrefixes := make([]string, len(agentPrefixes))

for i, v := range agentPrefixes {
interfacePrefixes[i] = v.(string)
}

macAddresses := []interface{}{}
networkInterfaces, err := veClient.WaitForNetworkInterfacesFromVMAgent(nodeName, vmID, int(agentTimeout.Seconds()), 5, true)
networkInterfaces, err := veClient.WaitForNetworkInterfacesFromVMAgent(nodeName, vmID, int(agentTimeout.Seconds()), 5, true, interfacePrefixes)

if err == nil && networkInterfaces.Result != nil {
ipv4Addresses = make([]interface{}, len(*networkInterfaces.Result))
Expand Down
9 changes: 6 additions & 3 deletions proxmoxtf/resource_virtual_environment_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,18 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {

testOptionalArguments(t, agentSchema, []string{
mkResourceVirtualEnvironmentVMAgentEnabled,
mkResourceVirtualEnvironmentVMAgentPrefixes,
mkResourceVirtualEnvironmentVMAgentTimeout,
mkResourceVirtualEnvironmentVMAgentTrim,
mkResourceVirtualEnvironmentVMAgentType,
})

testValueTypes(t, agentSchema, map[string]schema.ValueType{
mkResourceVirtualEnvironmentVMAgentEnabled: schema.TypeBool,
mkResourceVirtualEnvironmentVMAgentTrim: schema.TypeBool,
mkResourceVirtualEnvironmentVMAgentType: schema.TypeString,
mkResourceVirtualEnvironmentVMAgentEnabled: schema.TypeBool,
mkResourceVirtualEnvironmentVMAgentPrefixes: schema.TypeList,
mkResourceVirtualEnvironmentVMAgentTimeout: schema.TypeString,
mkResourceVirtualEnvironmentVMAgentTrim: schema.TypeBool,
mkResourceVirtualEnvironmentVMAgentType: schema.TypeString,
})

audioDeviceSchema := testNestedSchemaExistence(t, s, mkResourceVirtualEnvironmentVMAudioDevice)
Expand Down
2 changes: 1 addition & 1 deletion proxmoxtf/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ const (
TerraformProviderName = "terraform-provider-proxmox"

// TerraformProviderVersion specifies the version number.
TerraformProviderVersion = "0.4.1"
TerraformProviderVersion = "0.5.0"
)