diff --git a/README.md b/README.md index 054615ca..6026c974 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/docs/resources/virtual_environment_vm.md b/docs/resources/virtual_environment_vm.md index 9fd785f9..14af52c4 100644 --- a/docs/resources/virtual_environment_vm.md +++ b/docs/resources/virtual_environment_vm.md @@ -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 diff --git a/example/resource_virtual_environment_certificate.tf b/example/resource_virtual_environment_certificate.tf deleted file mode 100644 index b03d8c68..00000000 --- a/example/resource_virtual_environment_certificate.tf +++ /dev/null @@ -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 -} diff --git a/proxmoxtf/resource/validator/vm.go b/proxmoxtf/resource/validator/vm.go index 725cb915..4cac5d09 100644 --- a/proxmoxtf/resource/validator/vm.go +++ b/proxmoxtf/resource/validator/vm.go @@ -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) { diff --git a/proxmoxtf/resource/validator/vm_test.go b/proxmoxtf/resource/validator/vm_test.go index 0e709289..0e72c15a 100644 --- a/proxmoxtf/resource/validator/vm_test.go +++ b/proxmoxtf/resource/validator/vm_test.go @@ -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) + } + }) + } +} diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go index 910fc276..e8e843d3 100644 --- a/proxmoxtf/resource/vm.go +++ b/proxmoxtf/resource/vm.go @@ -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,