0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-06-30 02:31:10 +00:00

Merge branch 'main' into 1913_Import_Disks

This commit is contained in:
Marco Attia 2025-06-24 18:48:05 +00:00 committed by GitHub
commit e8dddac1f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 133 additions and 15 deletions

View File

@ -1378,6 +1378,24 @@
"contributions": [
"code"
]
},
{
"login": "cowgod",
"name": "Dan McCormack",
"avatar_url": "https://avatars.githubusercontent.com/u/523086?v=4",
"profile": "https://github.com/cowgod",
"contributions": [
"doc"
]
},
{
"login": "valkiriaaquatica",
"name": "VALKIRIA ACUATICA ",
"avatar_url": "https://avatars.githubusercontent.com/u/56233573?v=4",
"profile": "https://github.com/valkiriaaquatica",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,

View File

@ -194,6 +194,10 @@
<td align="center" valign="top" width="14.28%"><a href="https://github.com/antoniacobaeus"><img src="https://avatars.githubusercontent.com/u/46004494?v=4?s=100" width="100px;" alt="Anton Iacobaeus"/><br /><sub><b>Anton Iacobaeus</b></sub></a><br /><a href="https://github.com/bpg/terraform-provider-proxmox/commits?author=antoniacobaeus" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Bartosz-lab"><img src="https://avatars.githubusercontent.com/u/73119351?v=4?s=100" width="100px;" alt="Bartosz Cieślik"/><br /><sub><b>Bartosz Cieślik</b></sub></a><br /><a href="https://github.com/bpg/terraform-provider-proxmox/commits?author=Bartosz-lab" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/cowgod"><img src="https://avatars.githubusercontent.com/u/523086?v=4?s=100" width="100px;" alt="Dan McCormack"/><br /><sub><b>Dan McCormack</b></sub></a><br /><a href="https://github.com/bpg/terraform-provider-proxmox/commits?author=cowgod" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/valkiriaaquatica"><img src="https://avatars.githubusercontent.com/u/56233573?v=4?s=100" width="100px;" alt="VALKIRIA ACUATICA "/><br /><sub><b>VALKIRIA ACUATICA </b></sub></a><br /><a href="https://github.com/bpg/terraform-provider-proxmox/commits?author=valkiriaaquatica" title="Code">💻</a></td>
</tr>
</tbody>
<tfoot>
<tr>

View File

@ -668,6 +668,26 @@ All changes made to `amd_sev` will trigger reboots. Removing or adding the `amd_
`allow_smt` is by default set to `true` even if `snp` is not the selected type. Proxmox will ignore this value when `snp` is not in use. Likewise `no_key_sharing` is `false` by default but ignored by Proxmox when `snp` is in use.
## High Availability
When managing a virtual machine in a multi-node cluster, the VM's HA settings can
be managed using the `proxmox_virtual_environment_haresource` resource.
```hcl
resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
name = "terraform-provider-proxmox-ubuntu-vm"
vm_id = 4321
# ...
}
resource "proxmox_virtual_environment_haresource" "ubuntu_vm" {
resource_id = "vm:${proxmox_virtual_environment_vm.ubuntu_vm.vm_id}"
group = "node1"
state = "started"
comment = "Managed by Terraform"
}
```
## Important Notes
### `local-lvm` Datastore

View File

@ -289,12 +289,23 @@ func (r *linuxBridgeResource) Create(ctx context.Context, req resource.CreateReq
plan.ID = types.StringValue(plan.NodeName.ValueString() + ":" + plan.Name.ValueString())
r.read(ctx, &plan, &resp.Diagnostics)
found := r.read(ctx, &plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.Diagnostics.AddError(
"Linux Bridge interface not found after creation",
fmt.Sprintf(
"Interface %q on node %q could not be read after creation",
plan.Name.ValueString(), plan.NodeName.ValueString()),
)
return
}
resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
@ -308,7 +319,7 @@ func (r *linuxBridgeResource) Create(ctx context.Context, req resource.CreateReq
}
}
func (r *linuxBridgeResource) read(ctx context.Context, model *linuxBridgeResourceModel, diags *diag.Diagnostics) {
func (r *linuxBridgeResource) read(ctx context.Context, model *linuxBridgeResourceModel, diags *diag.Diagnostics) bool {
ifaces, err := r.client.Node(model.NodeName.ValueString()).ListNetworkInterfaces(ctx)
if err != nil {
diags.AddError(
@ -316,7 +327,7 @@ func (r *linuxBridgeResource) read(ctx context.Context, model *linuxBridgeResour
"Could not list network interfaces, unexpected error: "+err.Error(),
)
return
return false
}
for _, iface := range ifaces {
@ -331,11 +342,13 @@ func (r *linuxBridgeResource) read(ctx context.Context, model *linuxBridgeResour
"Could not import network interface from API response, unexpected error: "+err.Error(),
)
return
return false
}
break
return true
}
return false
}
// Read reads a Linux Bridge interface.
@ -349,12 +362,17 @@ func (r *linuxBridgeResource) Read(ctx context.Context, req resource.ReadRequest
return
}
r.read(ctx, &state, &resp.Diagnostics)
found := r.read(ctx, &state, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.State.RemoveResource(ctx)
return
}
diags = resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}
@ -409,12 +427,23 @@ func (r *linuxBridgeResource) Update(ctx context.Context, req resource.UpdateReq
return
}
r.read(ctx, &plan, &resp.Diagnostics)
found := r.read(ctx, &plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.Diagnostics.AddError(
"Linux Bridge interface not found after update",
fmt.Sprintf(
"Interface %q on node %q could not be read after update",
plan.Name.ValueString(), plan.NodeName.ValueString()),
)
return
}
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
err = r.client.Node(state.NodeName.ValueString()).ReloadNetworkConfiguration(ctx)
@ -491,12 +520,21 @@ func (r *linuxBridgeResource) ImportState(
NodeName: types.StringValue(nodeName),
Name: types.StringValue(iface),
}
r.read(ctx, &state, &resp.Diagnostics)
found := r.read(ctx, &state, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.Diagnostics.AddError(
"Linux Bridge interface not found",
fmt.Sprintf("Interface %q on node %q could not be imported", iface, nodeName),
)
return
}
diags := resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}

View File

@ -261,12 +261,23 @@ func (r *linuxVLANResource) Create(ctx context.Context, req resource.CreateReque
plan.ID = types.StringValue(plan.NodeName.ValueString() + ":" + plan.Name.ValueString())
r.read(ctx, &plan, &resp.Diagnostics)
found := r.read(ctx, &plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.Diagnostics.AddError(
"Linux VLAN interface not found after creation",
fmt.Sprintf(
"Interface %q on node %q could not be read after creation",
plan.Name.ValueString(), plan.NodeName.ValueString()),
)
return
}
resp.State.Set(ctx, plan)
resp.Diagnostics.Append(diags...)
@ -280,7 +291,7 @@ func (r *linuxVLANResource) Create(ctx context.Context, req resource.CreateReque
}
}
func (r *linuxVLANResource) read(ctx context.Context, model *linuxVLANResourceModel, diags *diag.Diagnostics) {
func (r *linuxVLANResource) read(ctx context.Context, model *linuxVLANResourceModel, diags *diag.Diagnostics) bool {
ifaces, err := r.client.Node(model.NodeName.ValueString()).ListNetworkInterfaces(ctx)
if err != nil {
diags.AddError(
@ -288,7 +299,7 @@ func (r *linuxVLANResource) read(ctx context.Context, model *linuxVLANResourceMo
"Could not list network interfaces, unexpected error: "+err.Error(),
)
return
return false
}
for _, iface := range ifaces {
@ -298,8 +309,10 @@ func (r *linuxVLANResource) read(ctx context.Context, model *linuxVLANResourceMo
model.importFromNetworkInterfaceList(iface)
break
return true
}
return false
}
// Read reads a Linux VLAN interface.
@ -313,12 +326,17 @@ func (r *linuxVLANResource) Read(ctx context.Context, req resource.ReadRequest,
return
}
r.read(ctx, &state, &resp.Diagnostics)
found := r.read(ctx, &state, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.State.RemoveResource(ctx)
return
}
diags = resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}
@ -357,12 +375,23 @@ func (r *linuxVLANResource) Update(ctx context.Context, req resource.UpdateReque
return
}
r.read(ctx, &plan, &resp.Diagnostics)
found := r.read(ctx, &plan, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.Diagnostics.AddError(
"Linux VLAN interface not found after update",
fmt.Sprintf(
"Interface %q on node %q could not be read after update",
plan.Name.ValueString(), plan.NodeName.ValueString()),
)
return
}
resp.Diagnostics.Append(resp.State.Set(ctx, plan)...)
err = r.client.Node(state.NodeName.ValueString()).ReloadNetworkConfiguration(ctx)
@ -439,12 +468,21 @@ func (r *linuxVLANResource) ImportState(
NodeName: types.StringValue(nodeName),
Name: types.StringValue(iface),
}
r.read(ctx, &state, &resp.Diagnostics)
found := r.read(ctx, &state, &resp.Diagnostics)
if resp.Diagnostics.HasError() {
return
}
if !found {
resp.Diagnostics.AddError(
"Linux VLAN interface not found",
fmt.Sprintf("Interface %q on node %q could not be imported", iface, nodeName),
)
return
}
diags := resp.State.Set(ctx, state)
resp.Diagnostics.Append(diags...)
}