From f8d20403bd1b59b3683352f9b525e45501e5ab30 Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Wed, 21 Apr 2021 20:53:03 +0900 Subject: [PATCH] fix: assign map to rawState when it is nil to prevent panic (#180) * fix: assign map to rawState when it is nil to prevent panic * refactor: return nil --- internal/provider/resource_docker_container_migrators.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/provider/resource_docker_container_migrators.go b/internal/provider/resource_docker_container_migrators.go index ab193bb1..db447f85 100644 --- a/internal/provider/resource_docker_container_migrators.go +++ b/internal/provider/resource_docker_container_migrators.go @@ -908,6 +908,9 @@ func updateV0ToV1PortsOrder(is *terraform.InstanceState, meta interface{}) error } func replaceLabelsMapFieldWithSetField(rawState map[string]interface{}) map[string]interface{} { + if rawState == nil { + return nil + } labelMapIFace := rawState["labels"] if labelMapIFace != nil { labelMap := labelMapIFace.(map[string]interface{}) @@ -920,6 +923,11 @@ func replaceLabelsMapFieldWithSetField(rawState map[string]interface{}) map[stri } func migrateContainerLabels(rawState map[string]interface{}) map[string]interface{} { + if rawState == nil { + // https://github.com/kreuzwerker/terraform-provider-docker/issues/176 + // to prevent error `assignment to entry in nil map` + rawState = map[string]interface{}{} + } replaceLabelsMapFieldWithSetField(rawState) m, ok := rawState["mounts"]