feat: Implement volume_options subpath (#710)

This commit is contained in:
Martin 2025-04-24 23:13:01 +02:00 committed by GitHub
parent 0663aeb1a4
commit 42249d3144
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 0 deletions

View file

@ -202,6 +202,7 @@ Optional:
- `driver_options` (Map of String) key/value map of driver specific options.
- `labels` (Block Set) User-defined key/value metadata. (see [below for nested schema](#nestedblock--mounts--volume_options--labels))
- `no_copy` (Boolean) Populate volume with data from the target.
- `subpath` (String) Path within the volume to mount. Requires docker server version 1.45 or higher.
<a id="nestedblock--mounts--volume_options--labels"></a>
### Nested Schema for `mounts.volume_options.labels`

View file

@ -382,6 +382,12 @@ func resourceDockerContainer() *schema.Resource {
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"subpath": {
Type: schema.TypeString,
Description: "Path within the volume to mount. Requires docker server version 1.45 or higher.",
Optional: true,
ForceNew: true,
},
},
},
},

View file

@ -209,6 +209,13 @@ func resourceDockerContainerCreate(ctx context.Context, d *schema.ResourceData,
}
mountInstance.VolumeOptions.DriverConfig.Options = mapTypeMapValsToString(value.(map[string]interface{}))
}
if client.ClientVersion() >= "1.45" {
if value, ok := rawVolumeOptions["subpath"]; ok {
mountInstance.VolumeOptions.Subpath = value.(string)
}
} else {
return diag.Errorf("Setting VolumeOptions.Subpath requires docker version 1.45 or higher")
}
}
}
}

View file

@ -291,6 +291,9 @@ func getDockerContainerMounts(container container.InspectResponse) []map[string]
opt["driver_name"] = mount.VolumeOptions.DriverConfig.Name
opt["driver_options"] = mount.VolumeOptions.DriverConfig.Options
}
if mount.VolumeOptions.Subpath != "" {
opt["subpath"] = mount.VolumeOptions.Subpath
}
m["volume_options"] = []map[string]interface{}{
opt,
}