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

fix(lxc): support device_passthrough config on non-clone container (#1722)

* fix(lxc): support `device_passthrough` config on non-clone container

Signed-off-by: Gifary Dhimas Fadhillah <4391866+gifff@users.noreply.github.com>

* fix(lxc): device_passthrough state of cloned container

Signed-off-by: Gifary Dhimas Fadhillah <4391866+gifff@users.noreply.github.com>

* test(lxc): assert container device passthrough

Signed-off-by: Gifary Dhimas Fadhillah <4391866+gifff@users.noreply.github.com>

---------

Signed-off-by: Gifary Dhimas Fadhillah <4391866+gifff@users.noreply.github.com>
Co-authored-by: Gifary Dhimas Fadhillah <4391866+gifff@users.noreply.github.com>
This commit is contained in:
Gifary Dhimas Fadhillah 2025-01-26 05:37:34 +07:00 committed by GitHub
parent e031a38d50
commit e92b0064bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 4 deletions

View File

@ -61,7 +61,7 @@ func TestAccResourceContainer(t *testing.T) {
name string
step []resource.TestStep
}{
{"crete and start container", []resource.TestStep{{
{"create and start container", []resource.TestStep{{
Config: te.RenderConfig(`
resource "proxmox_virtual_environment_container" "test_container" {
node_name = "{{.NodeName}}"
@ -101,13 +101,19 @@ func TestAccResourceContainer(t *testing.T) {
}`, WithRootUser()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(accTestContainerName, "description", "my\ndescription\nvalue\n"),
resource.TestCheckResourceAttr(accTestContainerName, "device_passthrough.#", "1"),
func(*terraform.State) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := te.NodeClient().Container(accTestContainerID).WaitForContainerStatus(ctx, "running")
ct := te.NodeClient().Container(accTestContainerID)
err := ct.WaitForContainerStatus(ctx, "running")
require.NoError(te.t, err, "container did not start")
ctInfo, err := ct.GetContainer(ctx)
require.NoError(te.t, err, "failed to get container")
require.NotNil(te.t, ctInfo.DevicePassthrough0)
return nil
},
),
@ -239,9 +245,14 @@ func TestAccResourceContainer(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err := te.NodeClient().Container(accTestContainerIDClone).WaitForContainerStatus(ctx, "running")
ct := te.NodeClient().Container(accTestContainerIDClone)
err := ct.WaitForContainerStatus(ctx, "running")
require.NoError(te.t, err, "container did not start")
ctInfo, err := ct.GetContainer(ctx)
require.NoError(te.t, err, "failed to get container")
require.NotNil(te.t, ctInfo.DevicePassthrough0)
return nil
},
),

View File

@ -1751,6 +1751,34 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
networkInterfaceArray[ni] = networkInterfaceObject
}
devicePassthrough := d.Get(mkDevicePassthrough).([]interface{})
devicePassthroughArray := make(
containers.CustomDevicePassthroughArray,
len(devicePassthrough),
)
for di, dv := range devicePassthrough {
devicePassthroughMap := dv.(map[string]interface{})
devicePassthroughObject := containers.CustomDevicePassthrough{}
denyWrite := types.CustomBool(
devicePassthroughMap[mkDevicePassthroughDenyWrite].(bool),
)
gid := devicePassthroughMap[mkDevicePassthroughGID].(int)
mode := devicePassthroughMap[mkDevicePassthroughMode].(string)
path := devicePassthroughMap[mkDevicePassthroughPath].(string)
uid := devicePassthroughMap[mkDevicePassthroughUID].(int)
devicePassthroughObject.DenyWrite = &denyWrite
devicePassthroughObject.GID = &gid
devicePassthroughObject.Mode = &mode
devicePassthroughObject.Path = path
devicePassthroughObject.UID = &uid
devicePassthroughArray[di] = devicePassthroughObject
}
operatingSystem := d.Get(mkOperatingSystem).([]interface{})
if len(operatingSystem) == 0 || operatingSystem[0] == nil {
@ -1798,6 +1826,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
CPUUnits: &cpuUnits,
DatastoreID: &diskDatastoreID,
DedicatedMemory: &memoryDedicated,
DevicePassthrough: devicePassthroughArray,
Features: features,
MountPoints: mountPointArray,
NetworkInterfaces: networkInterfaceArray,
@ -2361,8 +2390,10 @@ func containerRead(ctx context.Context, d *schema.ResourceData, m interface{}) d
devicePassthroughList = append(devicePassthroughList, devicePassthrough)
}
currentDevicePassthrough := d.Get(mkDevicePassthrough).([]interface{})
if len(clone) > 0 {
if len(devicePassthroughList) > 0 {
if len(currentDevicePassthrough) > 0 {
err := d.Set(mkDevicePassthrough, devicePassthroughList)
diags = append(diags, diag.FromErr(err)...)
}