From 2f766c1e8a5030f2af88b1b959f22f9daeddd80e Mon Sep 17 00:00:00 2001
From: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
Date: Thu, 13 Jun 2024 21:43:49 -0400
Subject: [PATCH] initial schema
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
---
docs/resources/virtual_environment_vm2.md | 22 ++++++-
fwprovider/vm/cdrom/resource_schema.go | 2 +-
fwprovider/vm/cloudinit/resource_schema.go | 72 ++++++++++++++++++++++
fwprovider/vm/resource_schema.go | 2 +
fwprovider/vm/vga/resource_schema.go | 10 +--
5 files changed, 102 insertions(+), 6 deletions(-)
create mode 100644 fwprovider/vm/cloudinit/resource_schema.go
diff --git a/docs/resources/virtual_environment_vm2.md b/docs/resources/virtual_environment_vm2.md
index a2656af9..bfee6624 100644
--- a/docs/resources/virtual_environment_vm2.md
+++ b/docs/resources/virtual_environment_vm2.md
@@ -30,11 +30,12 @@ The attributes are also marked as optional to allow the practitioner to set (or
### Optional
-- `cdrom` (Attributes Map) The CD-ROM configuration. The key is the interface of the CD-ROM, could be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. Note that `q35` machine type only supports `ide0` and `ide2` of IDE interfaces. (see [below for nested schema](#nestedatt--cdrom))
+- `cdrom` (Attributes Map) The CD-ROM configuration. The key is the interface of the CD-ROM, must be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. Note that `q35` machine type only supports `ide0` and `ide2` of IDE interfaces. (see [below for nested schema](#nestedatt--cdrom))
- `clone` (Attributes) The cloning configuration. (see [below for nested schema](#nestedatt--clone))
- `cpu` (Attributes) The CPU configuration. (see [below for nested schema](#nestedatt--cpu))
- `description` (String) The description of the VM.
- `id` (Number) The unique identifier of the VM in the Proxmox cluster.
+- `initialization` (Attributes) The cloud-init configuration. (see [below for nested schema](#nestedatt--initialization))
- `name` (String) The name of the VM. Doesn't have to be unique.
- `stop_on_destroy` (Boolean) Set to true to stop (rather than shutdown) the VM on destroy (defaults to `false`).
- `tags` (Set of String) The tags assigned to the VM.
@@ -79,6 +80,25 @@ Optional:
- `units` (Number) CPU weight for a VM. Argument is used in the kernel fair scheduler. The larger the number is, the more CPU time this VM gets. Number is relative to weights of all the other running VMs.
+
+### Nested Schema for `initialization`
+
+Optional:
+
+- `datastore_id` (String) The identifier for the datastore to create the cloud-init disk in (defaults to `local-lvm`)
+- `dns` (Attributes) The DNS configuration. (see [below for nested schema](#nestedatt--initialization--dns))
+- `interface` (String) The hardware interface to connect the cloud-init image to. Must be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. Will be detected if the setting is missing but a cloud-init image is present, otherwise defaults to `ide2`. Note that `q35` machine type only supports `ide0` and `ide2` of IDE interfaces.
+
+
+### Nested Schema for `initialization.dns`
+
+Optional:
+
+- `domain` (String) The domain name to use for the VM.
+- `servers` (List of String) The list of DNS servers to use.
+
+
+
### Nested Schema for `timeouts`
diff --git a/fwprovider/vm/cdrom/resource_schema.go b/fwprovider/vm/cdrom/resource_schema.go
index d3945961..25f5a387 100644
--- a/fwprovider/vm/cdrom/resource_schema.go
+++ b/fwprovider/vm/cdrom/resource_schema.go
@@ -23,7 +23,7 @@ func ResourceSchema() schema.Attribute {
return schema.MapNestedAttribute{
Description: "The CD-ROM configuration",
MarkdownDescription: "The CD-ROM configuration. The key is the interface of the CD-ROM, " +
- "could be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. " +
+ "must be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. " +
"Note that `q35` machine type only supports `ide0` and `ide2` of IDE interfaces.",
Optional: true,
Computed: true,
diff --git a/fwprovider/vm/cloudinit/resource_schema.go b/fwprovider/vm/cloudinit/resource_schema.go
new file mode 100644
index 00000000..05ce5dd8
--- /dev/null
+++ b/fwprovider/vm/cloudinit/resource_schema.go
@@ -0,0 +1,72 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+package cloudinit
+
+import (
+ "regexp"
+
+ "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
+ "github.com/hashicorp/terraform-plugin-framework/schema/validator"
+
+ customtypes "github.com/bpg/terraform-provider-proxmox/fwprovider/types"
+)
+
+// ResourceSchema defines the schema for the CPU resource.
+func ResourceSchema() schema.Attribute {
+ return schema.SingleNestedAttribute{
+ Description: "The cloud-init configuration.",
+ Optional: true,
+ Computed: true,
+ Attributes: map[string]schema.Attribute{
+ "datastore_id": schema.StringAttribute{
+ Description: "The identifier for the datastore to create the cloud-init disk in (defaults to `local-lvm`)",
+ Optional: true,
+ Computed: true,
+ Default: stringdefault.StaticString("local-lvm"),
+ Validators: []validator.String{
+ stringvalidator.LengthAtLeast(1),
+ },
+ },
+ "interface": schema.StringAttribute{
+ Description: "The hardware interface to connect the cloud-init image to.",
+ MarkdownDescription: "The hardware interface to connect the cloud-init image to. " +
+ "Must be one of `ideN`, `sataN`, `scsiN`, where N is the index of the interface. " +
+ "Will be detected if the setting is missing but a cloud-init image is present, " +
+ "otherwise defaults to `ide2`. Note that `q35` machine type only supports " +
+ "`ide0` and `ide2` of IDE interfaces.",
+ Optional: true,
+ Computed: true,
+ Validators: []validator.String{
+ stringvalidator.RegexMatches(
+ regexp.MustCompile(`^(ide[0-3]|sata[0-5]|scsi([0-9]|1[0-3]))$`),
+ "one of `ide[0-3]`, `sata[0-5]`, `scsi[0-13]`",
+ ),
+ },
+ },
+ "dns": schema.SingleNestedAttribute{
+ Description: "The DNS configuration.",
+ Optional: true,
+ Computed: true,
+ Attributes: map[string]schema.Attribute{
+ "domain": schema.StringAttribute{
+ Description: "The domain name to use for the VM.",
+ Optional: true,
+ Computed: true,
+ },
+ "servers": schema.ListAttribute{
+ Description: "The list of DNS servers to use.",
+ ElementType: customtypes.IPAddrType{},
+ Optional: true,
+ Computed: true,
+ },
+ },
+ },
+ },
+ }
+}
diff --git a/fwprovider/vm/resource_schema.go b/fwprovider/vm/resource_schema.go
index 37483656..4108dcf8 100644
--- a/fwprovider/vm/resource_schema.go
+++ b/fwprovider/vm/resource_schema.go
@@ -24,6 +24,7 @@ import (
"github.com/bpg/terraform-provider-proxmox/fwprovider/types/stringset"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/cdrom"
+ "github.com/bpg/terraform-provider-proxmox/fwprovider/vm/cloudinit"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/cpu"
"github.com/bpg/terraform-provider-proxmox/fwprovider/vm/vga"
)
@@ -74,6 +75,7 @@ func (r *Resource) Schema(
},
Description: "The unique identifier of the VM in the Proxmox cluster.",
},
+ "initialization": cloudinit.ResourceSchema(),
"name": schema.StringAttribute{
Description: "The name of the VM.",
MarkdownDescription: "The name of the VM. Doesn't have to be unique.",
diff --git a/fwprovider/vm/vga/resource_schema.go b/fwprovider/vm/vga/resource_schema.go
index fc553133..73174c0e 100644
--- a/fwprovider/vm/vga/resource_schema.go
+++ b/fwprovider/vm/vga/resource_schema.go
@@ -1,3 +1,9 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
package vga
import (
@@ -7,15 +13,11 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
- "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)
// ResourceSchema defines the schema for the CPU resource.
func ResourceSchema() schema.Attribute {
return schema.SingleNestedAttribute{
- CustomType: basetypes.ObjectType{
- AttrTypes: attributeTypes(),
- },
Description: "The VGA configuration.",
MarkdownDescription: "Configure the VGA Hardware. If you want to use high resolution modes (>= 1280x1024x16) " +
"you may need to increase the vga memory option. Since QEMU 2.9 the default VGA display type is `std` " +