terraform-provider-docker/docker/label_migration.go

43 lines
1.3 KiB
Go
Raw Normal View History

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{}{}
}
return rawState
}
func migrateContainerLabels(rawState map[string]interface{}) map[string]interface{} {
2019-11-16 09:11:17 -05:00
replaceLabelsMapFieldWithSetField(rawState)
2019-11-15 21:33:05 -05:00
mounts := rawState["mounts"].([]interface{})
newMounts := make([]interface{}, len(mounts))
2019-11-15 21:33:05 -05:00
for i, mountI := range mounts {
mount := mountI.(map[string]interface{})
2019-11-15 21:33:05 -05:00
volumeOptionsList := mount["volume_options"].([]interface{})
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
}
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)
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)
return rawState
}