Skip to content

Commit ad67559

Browse files
authored
Merge pull request #1430 from Tinyblargon/lxc-release
LXC release
2 parents 4876183 + c945ca8 commit ad67559

File tree

10 files changed

+286
-45
lines changed

10 files changed

+286
-45
lines changed

docs/resources/lxc_guest.md

Lines changed: 221 additions & 0 deletions
Large diffs are not rendered by default.

proxmox/Internal/resource/guest/lxc/networks/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const (
2727
schemaMTU = "mtu"
2828
schemaName = "name"
2929
schemaNativeVlan = native.Root
30-
schemaRate = "rate"
30+
schemaRateLimit = "rate_limit"
3131

3232
schmemaIPv4 = "ipv4"
3333
schmemaIPv6 = "ipv6"

proxmox/Internal/resource/guest/lxc/networks/schema_network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ func SchemaNetwork() *schema.Schema {
3838
schemaMTU: subSchemaMTU(true, schemaMTU),
3939
schemaName: subSchemaName(true, schemaName),
4040
schemaNativeVlan: subSchemaNativeVlan(true, schemaNativeVlan),
41-
schemaRate: subSchemaRate(true, schemaRate),
41+
schemaRateLimit: subSchemaRate(true, schemaRateLimit),
4242
schemaSLAAC: subSchemaSLAAC(schema.Schema{})}}}
4343
}

proxmox/Internal/resource/guest/lxc/networks/schema_networks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func networksSubSchema(slot string) *schema.Schema {
4343
schemaMTU: subSchemaMTU(false, pathSimple+schemaMTU),
4444
schemaName: subSchemaName(false, pathSimple+schemaName),
4545
schemaNativeVlan: subSchemaNativeVlan(false, pathSimple+schemaNativeVlan),
46-
schemaRate: subSchemaRate(false, pathSimple+schemaRate),
46+
schemaRateLimit: subSchemaRate(false, pathSimple+schemaRateLimit),
4747
schmemaIPv4: {
4848
Type: schema.TypeList,
4949
Optional: true,

proxmox/Internal/resource/guest/lxc/networks/sdk_network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func sdkNetwork(schema []any) (pveSDK.LxcNetworks, diag.Diagnostics) {
3232
Mtu: util.Pointer(pveSDK.MTU(schemaMap[schemaMTU].(int))),
3333
Name: util.Pointer(pveSDK.LxcNetworkName(schemaMap[schemaName].(string))),
3434
NativeVlan: util.Pointer(pveSDK.Vlan(schemaMap[schemaNativeVlan].(int))),
35-
RateLimitKBps: util.Pointer(pveSDK.GuestNetworkRate(schemaMap[schemaRate].(int)))}
35+
RateLimitKBps: util.Pointer(pveSDK.GuestNetworkRate(schemaMap[schemaRateLimit].(int)))}
3636
}
3737
for i := range pveSDK.LxcNetworkID(networksAmount) { // ensure all networks are present
3838
if _, ok := config[i]; !ok {

proxmox/Internal/resource/guest/lxc/networks/sdk_networks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func sdkNetworks(schema map[string]any) pveSDK.LxcNetworks {
3232
Mtu: util.Pointer(pveSDK.MTU(schemaMap[schemaMTU].(int))),
3333
Name: util.Pointer(pveSDK.LxcNetworkName(schemaMap[schemaName].(string))),
3434
NativeVlan: util.Pointer(pveSDK.Vlan(schemaMap[schemaNativeVlan].(int))),
35-
RateLimitKBps: util.Pointer(pveSDK.GuestNetworkRate(schemaMap[schemaRate].(int)))}
35+
RateLimitKBps: util.Pointer(pveSDK.GuestNetworkRate(schemaMap[schemaRateLimit].(int)))}
3636
}
3737
return config
3838
}

proxmox/Internal/resource/guest/lxc/networks/terraform_network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func terraformNetwork(config pveSDK.LxcNetworks, tfConfig []any) []map[string]an
3333
params[schemaNativeVlan] = int(*v.NativeVlan)
3434
}
3535
if v.RateLimitKBps != nil {
36-
params[schemaRate] = int(*v.RateLimitKBps)
36+
params[schemaRateLimit] = int(*v.RateLimitKBps)
3737
} else {
38-
params[schemaRate] = 0
38+
params[schemaRateLimit] = 0
3939
}
4040
if v.IPv4 != nil {
4141
params[schemaIPv4DHCP] = v.IPv4.DHCP

proxmox/Internal/resource/guest/lxc/networks/terraform_networks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func terraformNetworks(config pveSDK.LxcNetworks) []any {
5151
schemaSLAAC: ipv6.SLAAC}}
5252
}
5353
if v.RateLimitKBps != nil {
54-
settings[schemaRate] = int(*v.RateLimitKBps)
54+
settings[schemaRateLimit] = int(*v.RateLimitKBps)
5555
}
5656
mapParams[prefixSchemaID+strconv.Itoa(int(k))] = []any{settings}
5757
}

proxmox/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func Provider() *schema.Provider {
201201
"proxmox_vm_qemu": resourceVmQemu(),
202202
"proxmox_lxc": resourceLxc(),
203203
"proxmox_lxc_disk": resourceLxcDisk(),
204+
"proxmox_lxc_guest": resourceLxcGuest(),
204205
"proxmox_pool": resourcePool(),
205206
"proxmox_cloud_init_disk": resourceCloudInitDisk(),
206207
"proxmox_storage_iso": resourceStorageIso(),

proxmox/resource_lxc_new.go renamed to proxmox/resource_lxc_guest.go

Lines changed: 56 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/dns"
1010
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/lxc/architecture"
1111
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/lxc/cpu"
12-
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/lxc/features"
1312
tags "github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/lxc/lxc_tags"
1413
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/lxc/memory"
1514
"github.com/Telmate/terraform-provider-proxmox/v2/proxmox/Internal/resource/guest/lxc/mounts"
@@ -34,24 +33,24 @@ import (
3433

3534
var lxcNewResourceDef *schema.Resource
3635

37-
func ResourceLxcNew() *schema.Resource {
36+
func resourceLxcGuest() *schema.Resource {
3837
lxcNewResourceDef = &schema.Resource{
39-
CreateContext: resourceLxcNewCreate,
40-
ReadContext: resourceLxcNewReadWithLock,
41-
UpdateContext: resourceLxcNewUpdate,
42-
DeleteContext: resourceLxcNewDelete,
38+
CreateContext: resourceLxcGuestCreate,
39+
ReadContext: resourceLxcGuestReadWithLock,
40+
UpdateContext: resourceLxcGuestUpdate,
41+
DeleteContext: resourceLxcGuestDelete,
4342
Importer: &schema.ResourceImporter{
4443
StateContext: schema.ImportStatePassthroughContext,
4544
},
4645
CustomizeDiff: reboot.CustomizeDiff(),
4746

4847
Schema: map[string]*schema.Schema{
49-
architecture.Root: architecture.Schema(),
50-
clone.Root: clone.Schema(),
51-
cpu.Root: cpu.Schema(),
52-
description.Root: description.Schema(),
53-
dns.Root: dns.Schema(),
54-
features.Root: features.Schema(),
48+
architecture.Root: architecture.Schema(),
49+
clone.Root: clone.Schema(),
50+
cpu.Root: cpu.Schema(),
51+
description.Root: description.Schema(),
52+
dns.Root: dns.Schema(),
53+
// features.Root: features.Schema(),
5554
memory.Root: memory.Schema(),
5655
mounts.RootMount: mounts.SchemaMount(),
5756
mounts.RootMounts: mounts.SchemaMounts(),
@@ -81,15 +80,21 @@ func ResourceLxcNew() *schema.Resource {
8180
return lxcNewResourceDef
8281
}
8382

84-
func resourceLxcNewCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
83+
func resourceLxcGuestCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
8584
pconf := meta.(*providerConfiguration)
8685
lock := pmParallelBegin(pconf)
8786
defer lock.unlock()
8887

88+
diags := lxcGuestWarning()
89+
8990
client := pconf.Client
9091

9192
privileged := privilege.SDK(d)
92-
config, diags := lxcSDK(privileged, d)
93+
config, tmpDiags := lxcSDK(privileged, d)
94+
diags = append(diags, tmpDiags...)
95+
if diags.HasError() {
96+
return diags
97+
}
9398
config.Privileged = &privileged
9499

95100
// Set the node for the LXC container
@@ -150,36 +155,41 @@ func resourceLxcNewCreate(ctx context.Context, d *schema.ResourceData, meta any)
150155
Type: id.GuestLxc}.String())
151156
}
152157

153-
return append(diags, resourceLxcNewRead(ctx, d, meta, vmr, client)...)
158+
return append(diags, resourceLxcGuestRead(ctx, d, meta, vmr, client)...)
154159
}
155160

156-
func resourceLxcNewUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
161+
func resourceLxcGuestUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
157162
pConf := meta.(*providerConfiguration)
158163
lock := pmParallelBegin(pConf)
159164
defer lock.unlock()
160165

161166
client := pConf.Client
162167

168+
diags := lxcGuestWarning()
169+
163170
// Get vm reference
164171
var resourceID id.Guest
165172
err := resourceID.Parse(d.Id())
166173
if err != nil {
167174
d.SetId("")
168-
return diag.Diagnostics{{
175+
return append(diags, diag.Diagnostic{
169176
Summary: "unexpected error when trying to read and parse the resource: " + err.Error(),
170-
Severity: diag.Error}}
177+
Severity: diag.Error})
171178
}
172179
var vmr *pveSDK.VmRef
173180
vmr, err = client.GetVmRefById(ctx, resourceID.ID)
174181
if err != nil {
175-
return diag.Diagnostics{
176-
diag.Diagnostic{
177-
Summary: err.Error(),
178-
Severity: diag.Error}}
182+
return append(diags, diag.Diagnostic{
183+
Summary: err.Error(),
184+
Severity: diag.Error})
179185
}
180186

181187
// create a new config from the resource data
182-
config, diags := lxcSDK(privilege.SDK(d), d)
188+
config, tmpDiags := lxcSDK(privilege.SDK(d), d)
189+
diags = append(diags, tmpDiags...)
190+
if diags.HasError() {
191+
return diags
192+
}
183193

184194
// update the targetNode for the LXC container
185195
var targetNode pveSDK.NodeName
@@ -201,27 +211,29 @@ func resourceLxcNewUpdate(ctx context.Context, d *schema.ResourceData, meta any)
201211
Severity: diag.Error})
202212
}
203213

204-
return append(diags, resourceLxcNewRead(ctx, d, meta, vmr, client)...)
214+
return append(diags, resourceLxcGuestRead(ctx, d, meta, vmr, client)...)
205215
}
206216

207-
func resourceLxcNewReadWithLock(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
217+
func resourceLxcGuestReadWithLock(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
208218
pConf := meta.(*providerConfiguration)
209219
lock := pmParallelBegin(pConf)
210220
defer lock.unlock()
211221

222+
diags := lxcGuestWarning()
223+
212224
var resourceID id.Guest
213225
err := resourceID.Parse(d.Id())
214226
if err != nil {
215227
d.SetId("")
216-
return diag.Diagnostics{{
228+
return append(diags, diag.Diagnostic{
217229
Summary: "unexpected error when trying to read and parse the resource: " + err.Error(),
218-
Severity: diag.Error}}
230+
Severity: diag.Error})
219231
}
220232

221-
return resourceLxcNewRead(ctx, d, meta, pveSDK.NewVmRef(resourceID.ID), pConf.Client)
233+
return append(diags, resourceLxcGuestRead(ctx, d, meta, pveSDK.NewVmRef(resourceID.ID), pConf.Client)...)
222234
}
223235

224-
func resourceLxcNewRead(ctx context.Context, d *schema.ResourceData, meta any, vmr *pveSDK.VmRef, client *pveSDK.Client) diag.Diagnostics {
236+
func resourceLxcGuestRead(ctx context.Context, d *schema.ResourceData, meta any, vmr *pveSDK.VmRef, client *pveSDK.Client) diag.Diagnostics {
225237
guestStatus, err := vmr.GetRawGuestStatus(ctx, client)
226238
if err != nil {
227239
return diag.Diagnostics{{
@@ -245,7 +257,7 @@ func resourceLxcNewRead(ctx context.Context, d *schema.ResourceData, meta any, v
245257
cpu.Terraform(config.CPU, d)
246258
description.Terraform(config.Description, false, d)
247259
dns.Terraform(config.DNS, d)
248-
features.Terraform(config.Features, d)
260+
// features.Terraform(config.Features, d)
249261
memory.Terraform(config.Memory, d)
250262
mounts.Terraform(config.Mounts, d)
251263
name.Terraform_Unsafe(config.Name, d)
@@ -261,7 +273,7 @@ func resourceLxcNewRead(ctx context.Context, d *schema.ResourceData, meta any, v
261273
return nil
262274
}
263275

264-
func resourceLxcNewDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
276+
func resourceLxcGuestDelete(ctx context.Context, d *schema.ResourceData, meta any) diag.Diagnostics {
265277
return guestDelete(ctx, d, meta, "LXC")
266278
}
267279

@@ -275,12 +287,12 @@ func lxcSDK(privilidged bool, d *schema.ResourceData) (pveSDK.ConfigLXC, diag.Di
275287
CPU: cpu.SDK(d),
276288
DNS: dns.SDK(d),
277289
Description: description.SDK(false, d),
278-
Features: features.SDK(privilidged, d),
279-
Memory: memory.SDK(d),
280-
Name: guestName,
281-
State: powerstate.SDK(d),
282-
Swap: swap.SDK(d),
283-
Tags: tags.SDK(d),
290+
// Features: features.SDK(privilidged, d),
291+
Memory: memory.SDK(d),
292+
Name: guestName,
293+
State: powerstate.SDK(d),
294+
Swap: swap.SDK(d),
295+
Tags: tags.SDK(d),
284296
}
285297
var diags, tmpDiags diag.Diagnostics
286298
config.Networks, diags = networks.SDK(d)
@@ -291,3 +303,10 @@ func lxcSDK(privilidged bool, d *schema.ResourceData) (pveSDK.ConfigLXC, diag.Di
291303
diags = append(diags, tmpDiags...)
292304
return config, diags
293305
}
306+
307+
func lxcGuestWarning() diag.Diagnostics {
308+
return diag.Diagnostics{{
309+
Detail: "The LXC Guest resource is experimental. The schema and functionality may change in future releases without a major version bump.",
310+
Summary: "LXC Guest resource is experimental",
311+
Severity: diag.Warning}}
312+
}

0 commit comments

Comments
 (0)