mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-22 19:38:35 +00:00
fix(vm): update validation and docs for machine
attribute (#681)
* fix(vm): update validation and docs for `machine` attribute. Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * chore: remove certificate resource from acceptance tests Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
a8e8ad73ed
commit
3fd6b6b2ce
@ -78,6 +78,7 @@ environment. The following assumptions are made about the test environment:
|
||||
|
||||
- It has one node named `pve`
|
||||
- The node has local storages named `local` and `local-lvm`
|
||||
- The "Snippets" content type is enabled in `local` storage
|
||||
|
||||
Create `examples/terraform.tfvars` with the following variables:
|
||||
|
||||
|
@ -370,8 +370,8 @@ output "ubuntu_vm_public_key" {
|
||||
- `sv` - Swedish.
|
||||
- `tr` - Turkish.
|
||||
- `kvm_arguments` - (Optional) Arbitrary arguments passed to kvm.
|
||||
- `machine` - (Optional) The VM machine type (defaults to `i440fx`).
|
||||
- `i440fx` - Standard PC (i440FX + PIIX, 1996).
|
||||
- `machine` - (Optional) The VM machine type (defaults to `pc`).
|
||||
- `pc` - Standard PC (i440FX + PIIX, 1996).
|
||||
- `q35` - Standard PC (Q35 + ICH9, 2009).
|
||||
- `memory` - (Optional) The memory configuration.
|
||||
- `dedicated` - (Optional) The dedicated memory in megabytes (defaults
|
||||
|
@ -1,64 +0,0 @@
|
||||
resource "proxmox_virtual_environment_certificate" "example" {
|
||||
certificate = tls_self_signed_cert.proxmox_virtual_environment_certificate.cert_pem
|
||||
node_name = data.proxmox_virtual_environment_nodes.example.names[0]
|
||||
private_key = tls_private_key.proxmox_virtual_environment_certificate.private_key_pem
|
||||
}
|
||||
|
||||
resource "tls_private_key" "proxmox_virtual_environment_certificate" {
|
||||
algorithm = "RSA"
|
||||
rsa_bits = 2048
|
||||
}
|
||||
|
||||
resource "tls_self_signed_cert" "proxmox_virtual_environment_certificate" {
|
||||
key_algorithm = tls_private_key.proxmox_virtual_environment_certificate.algorithm
|
||||
private_key_pem = tls_private_key.proxmox_virtual_environment_certificate.private_key_pem
|
||||
|
||||
subject {
|
||||
common_name = "example.com"
|
||||
organization = "Terraform Provider for Proxmox"
|
||||
}
|
||||
|
||||
validity_period_hours = 8760
|
||||
|
||||
allowed_uses = [
|
||||
"key_encipherment",
|
||||
"digital_signature",
|
||||
"server_auth",
|
||||
]
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_expiration_date" {
|
||||
value = proxmox_virtual_environment_certificate.example.expiration_date
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_file_name" {
|
||||
value = proxmox_virtual_environment_certificate.example.file_name
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_issuer" {
|
||||
value = proxmox_virtual_environment_certificate.example.issuer
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_public_key_size" {
|
||||
value = proxmox_virtual_environment_certificate.example.public_key_size
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_public_key_type" {
|
||||
value = proxmox_virtual_environment_certificate.example.public_key_type
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_ssl_fingerprint" {
|
||||
value = proxmox_virtual_environment_certificate.example.ssl_fingerprint
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_start_date" {
|
||||
value = proxmox_virtual_environment_certificate.example.start_date
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_subject" {
|
||||
value = proxmox_virtual_environment_certificate.example.subject
|
||||
}
|
||||
|
||||
output "resource_proxmox_virtual_environment_certificate_example_subject_alternative_names" {
|
||||
value = proxmox_virtual_environment_certificate.example.subject_alternative_names
|
||||
}
|
@ -185,6 +185,14 @@ func KeyboardLayout() schema.SchemaValidateDiagFunc {
|
||||
}, false))
|
||||
}
|
||||
|
||||
// MachineType is a schema validation function for machine types.
|
||||
func MachineType() schema.SchemaValidateDiagFunc {
|
||||
//nolint:lll
|
||||
r := regexp.MustCompile(`^$|^(pc|pc(-i440fx)?-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|q35|pc-q35-\d+(\.\d+)+(\+pve\d+)?(\.pxe)?|virt(?:-\d+(\.\d+)+)?(\+pve\d+)?)$`)
|
||||
|
||||
return validation.ToDiagFunc(validation.StringMatch(r, "must be a valid machine type"))
|
||||
}
|
||||
|
||||
// Timeout is a schema validation function for timeouts.
|
||||
func Timeout() schema.SchemaValidateDiagFunc {
|
||||
return validation.ToDiagFunc(func(i interface{}, k string) ([]string, []error) {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_getCPUTypeValidator(t *testing.T) {
|
||||
func TestCPUType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
@ -43,3 +43,37 @@ func Test_getCPUTypeValidator(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMachineType(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
valid bool
|
||||
}{
|
||||
{"empty is valid", "", true},
|
||||
{"invalid", "invalid", false},
|
||||
{"valid q35", "q35", true},
|
||||
{"valid pc-q35", "pc-q35-2.3", true},
|
||||
{"valid i440fx", "pc-i440fx-3.1+pve0", true},
|
||||
{"valid virt", "virt", true},
|
||||
{"invalid i440fx", "i440fx", false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f := MachineType()
|
||||
res := f(tt.value, nil)
|
||||
|
||||
if tt.valid {
|
||||
require.Empty(t, res, "validate: '%s'", tt.value)
|
||||
} else {
|
||||
require.NotEmpty(t, res, "validate: '%s'", tt.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1102,10 +1102,11 @@ func VM() *schema.Resource {
|
||||
ValidateDiagFunc: validator.KeyboardLayout(),
|
||||
},
|
||||
mkResourceVirtualEnvironmentVMMachine: {
|
||||
Type: schema.TypeString,
|
||||
Description: "The VM machine type, either default i440fx or q35",
|
||||
Optional: true,
|
||||
Default: dvResourceVirtualEnvironmentVMMachineType,
|
||||
Type: schema.TypeString,
|
||||
Description: "The VM machine type, either default `pc` or `q35`",
|
||||
Optional: true,
|
||||
Default: dvResourceVirtualEnvironmentVMMachineType,
|
||||
ValidateDiagFunc: validator.MachineType(),
|
||||
},
|
||||
mkResourceVirtualEnvironmentVMMACAddresses: {
|
||||
Type: schema.TypeList,
|
||||
|
Loading…
Reference in New Issue
Block a user