2019-11-14 17:44:58 -05:00
|
|
|
package docker
|
|
|
|
|
|
|
|
|
|
func replaceLabelsMapFieldWithSetField(rawState map[string]interface{}) map[string]interface{} {
|
2019-11-15 21:33:05 -05:00
|
|
|
labelMapIFace := rawState["labels"]
|
|
|
|
|
if labelMapIFace != nil {
|
|
|
|
|
labelMap := labelMapIFace.(map[string]interface{})
|
|
|
|
|
rawState["labels"] = mapStringInterfaceToLabelList(labelMap)
|
|
|
|
|
} else {
|
|
|
|
|
rawState["labels"] = []interface{}{}
|
|
|
|
|
}
|
2019-11-14 17:44:58 -05:00
|
|
|
|
|
|
|
|
return rawState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func migrateContainerLabels(rawState map[string]interface{}) map[string]interface{} {
|
2019-11-16 09:11:17 -05:00
|
|
|
replaceLabelsMapFieldWithSetField(rawState)
|
2019-11-14 17:44:58 -05:00
|
|
|
|
2020-08-02 12:25:44 -04:00
|
|
|
m, ok := rawState["mounts"]
|
|
|
|
|
if !ok || m == nil {
|
|
|
|
|
// https://github.com/terraform-providers/terraform-provider-docker/issues/264
|
|
|
|
|
rawState["mounts"] = []interface{}{}
|
|
|
|
|
return rawState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mounts := m.([]interface{})
|
2019-11-14 17:44:58 -05:00
|
|
|
newMounts := make([]interface{}, len(mounts))
|
2019-11-15 21:33:05 -05:00
|
|
|
for i, mountI := range mounts {
|
2019-11-14 17:44:58 -05:00
|
|
|
mount := mountI.(map[string]interface{})
|
2019-11-15 21:33:05 -05:00
|
|
|
volumeOptionsList := mount["volume_options"].([]interface{})
|
2019-11-14 17:44:58 -05:00
|
|
|
|
2019-11-15 21:33:05 -05:00
|
|
|
if len(volumeOptionsList) != 0 {
|
2019-11-16 09:11:17 -05:00
|
|
|
replaceLabelsMapFieldWithSetField(volumeOptionsList[0].(map[string]interface{}))
|
2019-11-15 21:33:05 -05:00
|
|
|
}
|
2019-11-14 17:44:58 -05:00
|
|
|
newMounts[i] = mount
|
|
|
|
|
}
|
|
|
|
|
rawState["mounts"] = newMounts
|
|
|
|
|
|
|
|
|
|
return rawState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func migrateServiceLabels(rawState map[string]interface{}) map[string]interface{} {
|
2019-11-16 09:11:17 -05:00
|
|
|
replaceLabelsMapFieldWithSetField(rawState)
|
2019-11-14 17:44:58 -05:00
|
|
|
|
|
|
|
|
taskSpec := rawState["task_spec"].([]interface{})[0].(map[string]interface{})
|
|
|
|
|
containerSpec := taskSpec["container_spec"].([]interface{})[0].(map[string]interface{})
|
2019-11-15 21:33:05 -05:00
|
|
|
migrateContainerLabels(containerSpec)
|
2019-11-14 17:44:58 -05:00
|
|
|
|
|
|
|
|
return rawState
|
|
|
|
|
}
|