From d9f299c00e678fc943277c8f70d540f05b849bdb Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Fri, 8 Sep 2023 14:18:55 +0800 Subject: [PATCH 1/2] fix dereference may cause panic in apim --- .../apimanagement/api_management_backend_resource.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/services/apimanagement/api_management_backend_resource.go b/internal/services/apimanagement/api_management_backend_resource.go index a990324ed88b..68da32ffc9aa 100644 --- a/internal/services/apimanagement/api_management_backend_resource.go +++ b/internal/services/apimanagement/api_management_backend_resource.go @@ -540,17 +540,17 @@ func flattenApiManagementBackendCredentials(input *backend.BackendCredentialsCon if input.Certificate != nil { result["certificate"] = *input.Certificate } - result["header"] = flattenApiManagementBackendCredentialsObject(*input.Header) - result["query"] = flattenApiManagementBackendCredentialsObject(*input.Query) + result["header"] = flattenApiManagementBackendCredentialsObject(input.Header) + result["query"] = flattenApiManagementBackendCredentialsObject(input.Query) return append(results, result) } -func flattenApiManagementBackendCredentialsObject(input map[string][]string) map[string]interface{} { +func flattenApiManagementBackendCredentialsObject(input *map[string][]string) map[string]interface{} { results := make(map[string]interface{}) - if input == nil { + if input == nil || *input == nil { return results } - for k, v := range input { + for k, v := range *input { results[k] = strings.Join(v, ",") } return results From b5a8569b2dc0e91ecbccae3d2de6965884a34542 Mon Sep 17 00:00:00 2001 From: xuwu1 Date: Sat, 9 Sep 2023 08:55:47 +0800 Subject: [PATCH 2/2] no need check map nil --- .../services/apimanagement/api_management_backend_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/apimanagement/api_management_backend_resource.go b/internal/services/apimanagement/api_management_backend_resource.go index 68da32ffc9aa..2e1ae7abcd6c 100644 --- a/internal/services/apimanagement/api_management_backend_resource.go +++ b/internal/services/apimanagement/api_management_backend_resource.go @@ -547,7 +547,7 @@ func flattenApiManagementBackendCredentials(input *backend.BackendCredentialsCon func flattenApiManagementBackendCredentialsObject(input *map[string][]string) map[string]interface{} { results := make(map[string]interface{}) - if input == nil || *input == nil { + if input == nil { return results } for k, v := range *input {