diff --git a/fwprovider/test/resource_container_test.go b/fwprovider/test/resource_container_test.go index e4f4c060..478bbbd7 100644 --- a/fwprovider/test/resource_container_test.go +++ b/fwprovider/test/resource_container_test.go @@ -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 }, ), diff --git a/proxmoxtf/resource/container/container.go b/proxmoxtf/resource/container/container.go index ae90b31a..78534981 100644 --- a/proxmoxtf/resource/container/container.go +++ b/proxmoxtf/resource/container/container.go @@ -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)...) }