mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-03 20:12:59 +00:00
Add agent.timeout argument
This commit is contained in:
parent
cfe0831b1c
commit
8c84784d69
@ -5,6 +5,7 @@ ENHANCEMENTS:
|
|||||||
* resource/virtual_environment_container: Add `clone` argument
|
* resource/virtual_environment_container: Add `clone` argument
|
||||||
* resource/virtual_environment_container: Add `disk` argument
|
* resource/virtual_environment_container: Add `disk` argument
|
||||||
* resource/virtual_environment_container: Add `template` argument
|
* resource/virtual_environment_container: Add `template` argument
|
||||||
|
* resource/virtual_environment_vm: Add `agent.timeout` argument
|
||||||
* resource/virtual_environment_vm: Add `audio_device` argument
|
* resource/virtual_environment_vm: Add `audio_device` argument
|
||||||
* resource/virtual_environment_vm: Add `clone` argument
|
* resource/virtual_environment_vm: Add `clone` argument
|
||||||
* resource/virtual_environment_vm: Add `initialization.datastore_id` argument
|
* resource/virtual_environment_vm: Add `initialization.datastore_id` argument
|
||||||
|
@ -96,6 +96,7 @@ output "ubuntu_vm_public_key" {
|
|||||||
* `acpi` - (Optional) Whether to enable ACPI (defaults to `true`).
|
* `acpi` - (Optional) Whether to enable ACPI (defaults to `true`).
|
||||||
* `agent` - (Optional) The QEMU agent configuration.
|
* `agent` - (Optional) The QEMU agent configuration.
|
||||||
* `enabled` - (Optional) Whether to enable the QEMU agent (defaults to `false`).
|
* `enabled` - (Optional) Whether to enable the QEMU agent (defaults to `false`).
|
||||||
|
* `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`).
|
* `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`).
|
* `type` - (Optional) The QEMU agent interface type (defaults to `virtio`).
|
||||||
* `isa` - ISA Serial Port.
|
* `isa` - ISA Serial Port.
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/danitso/terraform-provider-proxmox/proxmox"
|
"github.com/danitso/terraform-provider-proxmox/proxmox"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
@ -18,6 +19,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
dvResourceVirtualEnvironmentVMACPI = true
|
dvResourceVirtualEnvironmentVMACPI = true
|
||||||
dvResourceVirtualEnvironmentVMAgentEnabled = false
|
dvResourceVirtualEnvironmentVMAgentEnabled = false
|
||||||
|
dvResourceVirtualEnvironmentVMAgentTimeout = "15m"
|
||||||
dvResourceVirtualEnvironmentVMAgentTrim = false
|
dvResourceVirtualEnvironmentVMAgentTrim = false
|
||||||
dvResourceVirtualEnvironmentVMAgentType = "virtio"
|
dvResourceVirtualEnvironmentVMAgentType = "virtio"
|
||||||
dvResourceVirtualEnvironmentVMAudioDeviceDevice = "intel-hda"
|
dvResourceVirtualEnvironmentVMAudioDeviceDevice = "intel-hda"
|
||||||
@ -81,6 +83,7 @@ const (
|
|||||||
mkResourceVirtualEnvironmentVMACPI = "acpi"
|
mkResourceVirtualEnvironmentVMACPI = "acpi"
|
||||||
mkResourceVirtualEnvironmentVMAgent = "agent"
|
mkResourceVirtualEnvironmentVMAgent = "agent"
|
||||||
mkResourceVirtualEnvironmentVMAgentEnabled = "enabled"
|
mkResourceVirtualEnvironmentVMAgentEnabled = "enabled"
|
||||||
|
mkResourceVirtualEnvironmentVMAgentTimeout = "timeout"
|
||||||
mkResourceVirtualEnvironmentVMAgentTrim = "trim"
|
mkResourceVirtualEnvironmentVMAgentTrim = "trim"
|
||||||
mkResourceVirtualEnvironmentVMAgentType = "type"
|
mkResourceVirtualEnvironmentVMAgentType = "type"
|
||||||
mkResourceVirtualEnvironmentVMAudioDevice = "audio_device"
|
mkResourceVirtualEnvironmentVMAudioDevice = "audio_device"
|
||||||
@ -181,6 +184,7 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
return []interface{}{
|
return []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
mkResourceVirtualEnvironmentVMAgentEnabled: dvResourceVirtualEnvironmentVMAgentEnabled,
|
mkResourceVirtualEnvironmentVMAgentEnabled: dvResourceVirtualEnvironmentVMAgentEnabled,
|
||||||
|
mkResourceVirtualEnvironmentVMAgentTimeout: dvResourceVirtualEnvironmentVMAgentTimeout,
|
||||||
mkResourceVirtualEnvironmentVMAgentTrim: dvResourceVirtualEnvironmentVMAgentEnabled,
|
mkResourceVirtualEnvironmentVMAgentTrim: dvResourceVirtualEnvironmentVMAgentEnabled,
|
||||||
mkResourceVirtualEnvironmentVMAgentType: dvResourceVirtualEnvironmentVMAgentType,
|
mkResourceVirtualEnvironmentVMAgentType: dvResourceVirtualEnvironmentVMAgentType,
|
||||||
},
|
},
|
||||||
@ -194,6 +198,13 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Default: dvResourceVirtualEnvironmentVMAgentEnabled,
|
Default: dvResourceVirtualEnvironmentVMAgentEnabled,
|
||||||
},
|
},
|
||||||
|
mkResourceVirtualEnvironmentVMAgentTimeout: &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Description: "The maximum amount of time to wait for data from the QEMU agent to become available",
|
||||||
|
Optional: true,
|
||||||
|
Default: dvResourceVirtualEnvironmentVMAgentTimeout,
|
||||||
|
ValidateFunc: getTimeoutValidator(),
|
||||||
|
},
|
||||||
mkResourceVirtualEnvironmentVMAgentTrim: {
|
mkResourceVirtualEnvironmentVMAgentTrim: {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Whether to enable the FSTRIM feature in the QEMU agent",
|
Description: "Whether to enable the FSTRIM feature in the QEMU agent",
|
||||||
@ -2053,6 +2064,19 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{
|
|||||||
agent[mkResourceVirtualEnvironmentVMAgentTrim] = false
|
agent[mkResourceVirtualEnvironmentVMAgentTrim] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(currentAgent) > 0 {
|
||||||
|
currentAgentBlock := currentAgent[0].(map[string]interface{})
|
||||||
|
currentAgentTimeout := currentAgentBlock[mkResourceVirtualEnvironmentVMAgentTimeout].(string)
|
||||||
|
|
||||||
|
if currentAgentTimeout != "" {
|
||||||
|
agent[mkResourceVirtualEnvironmentVMAgentTimeout] = currentAgentTimeout
|
||||||
|
} else {
|
||||||
|
agent[mkResourceVirtualEnvironmentVMAgentTimeout] = dvResourceVirtualEnvironmentVMAgentTimeout
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
agent[mkResourceVirtualEnvironmentVMAgentTimeout] = dvResourceVirtualEnvironmentVMAgentTimeout
|
||||||
|
}
|
||||||
|
|
||||||
if vmConfig.Agent.Type != nil {
|
if vmConfig.Agent.Type != nil {
|
||||||
agent[mkResourceVirtualEnvironmentVMAgentType] = *vmConfig.Agent.Type
|
agent[mkResourceVirtualEnvironmentVMAgentType] = *vmConfig.Agent.Type
|
||||||
} else {
|
} else {
|
||||||
@ -2065,6 +2089,7 @@ func resourceVirtualEnvironmentVMReadCustom(d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
} else if len(currentAgent) > 0 ||
|
} else if len(currentAgent) > 0 ||
|
||||||
agent[mkResourceVirtualEnvironmentVMAgentEnabled] != dvResourceVirtualEnvironmentVMAgentEnabled ||
|
agent[mkResourceVirtualEnvironmentVMAgentEnabled] != dvResourceVirtualEnvironmentVMAgentEnabled ||
|
||||||
|
agent[mkResourceVirtualEnvironmentVMAgentTimeout] != dvResourceVirtualEnvironmentVMAgentTimeout ||
|
||||||
agent[mkResourceVirtualEnvironmentVMAgentTrim] != dvResourceVirtualEnvironmentVMAgentTrim ||
|
agent[mkResourceVirtualEnvironmentVMAgentTrim] != dvResourceVirtualEnvironmentVMAgentTrim ||
|
||||||
agent[mkResourceVirtualEnvironmentVMAgentType] != dvResourceVirtualEnvironmentVMAgentType {
|
agent[mkResourceVirtualEnvironmentVMAgentType] != dvResourceVirtualEnvironmentVMAgentType {
|
||||||
d.Set(mkResourceVirtualEnvironmentVMAgent, []interface{}{agent})
|
d.Set(mkResourceVirtualEnvironmentVMAgent, []interface{}{agent})
|
||||||
@ -2720,9 +2745,21 @@ func resourceVirtualEnvironmentVMReadNetworkValues(d *schema.ResourceData, m int
|
|||||||
|
|
||||||
if started {
|
if started {
|
||||||
if vmConfig.Agent != nil && vmConfig.Agent.Enabled != nil && *vmConfig.Agent.Enabled {
|
if vmConfig.Agent != nil && vmConfig.Agent.Enabled != nil && *vmConfig.Agent.Enabled {
|
||||||
macAddresses := []interface{}{}
|
resource := resourceVirtualEnvironmentVM()
|
||||||
|
agentBlock, err := getSchemaBlock(resource, d, m, []string{mkResourceVirtualEnvironmentVMAgent}, 0, true)
|
||||||
|
|
||||||
networkInterfaces, err := veClient.WaitForNetworkInterfacesFromVMAgent(nodeName, vmID, 900, 5, true)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
agentTimeout, err := time.ParseDuration(agentBlock[mkResourceVirtualEnvironmentVMAgentTimeout].(string))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
macAddresses := []interface{}{}
|
||||||
|
networkInterfaces, err := veClient.WaitForNetworkInterfacesFromVMAgent(nodeName, vmID, int(agentTimeout.Seconds()), 5, true)
|
||||||
|
|
||||||
if err == nil && networkInterfaces.Result != nil {
|
if err == nil && networkInterfaces.Result != nil {
|
||||||
ipv4Addresses = make([]interface{}, len(*networkInterfaces.Result))
|
ipv4Addresses = make([]interface{}, len(*networkInterfaces.Result))
|
||||||
|
@ -89,6 +89,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
|
|
||||||
testOptionalArguments(t, agentSchema, []string{
|
testOptionalArguments(t, agentSchema, []string{
|
||||||
mkResourceVirtualEnvironmentVMAgentEnabled,
|
mkResourceVirtualEnvironmentVMAgentEnabled,
|
||||||
|
mkResourceVirtualEnvironmentVMAgentTimeout,
|
||||||
mkResourceVirtualEnvironmentVMAgentTrim,
|
mkResourceVirtualEnvironmentVMAgentTrim,
|
||||||
mkResourceVirtualEnvironmentVMAgentType,
|
mkResourceVirtualEnvironmentVMAgentType,
|
||||||
})
|
})
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/helper/validation"
|
"github.com/hashicorp/terraform/helper/validation"
|
||||||
@ -273,6 +274,26 @@ func getSchemaBlock(r *schema.Resource, d *schema.ResourceData, m interface{}, k
|
|||||||
return resourceBlock, nil
|
return resourceBlock, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTimeoutValidator() schema.SchemaValidateFunc {
|
||||||
|
return func(i interface{}, k string) (ws []string, es []error) {
|
||||||
|
v, ok := i.(string)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
es = append(es, fmt.Errorf("expected type of %s to be string", k))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := time.ParseDuration(v)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
es = append(es, fmt.Errorf("expected value of %s to be a duration - got: %s", k, v))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getVGAMemoryValidator() schema.SchemaValidateFunc {
|
func getVGAMemoryValidator() schema.SchemaValidateFunc {
|
||||||
return validation.IntBetween(4, 512)
|
return validation.IntBetween(4, 512)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user