From 9544f83150550cabf920b7bebbc2490c1f41d810 Mon Sep 17 00:00:00 2001 From: Sherzod Karimov Date: Mon, 11 Nov 2024 16:32:20 -0500 Subject: [PATCH] handle when state does not exist --- datadog/resource_datadog_synthetics_test_.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/datadog/resource_datadog_synthetics_test_.go b/datadog/resource_datadog_synthetics_test_.go index 2656f45b6..a90fb02be 100644 --- a/datadog/resource_datadog_synthetics_test_.go +++ b/datadog/resource_datadog_synthetics_test_.go @@ -2877,9 +2877,12 @@ func buildDatadogBodyFiles(attr []interface{}) []datadogV1.SyntheticsTestRequest func buildTerraformBodyFiles(actualBodyFiles *[]datadogV1.SyntheticsTestRequestBodyFile, oldLocalBodyFiles []map[string]interface{}) (localBodyFiles []map[string]interface{}) { localBodyFiles = make([]map[string]interface{}, len(*actualBodyFiles)) for i, file := range *actualBodyFiles { - // The file content is kept from the existing localFile from the state, - // as the response from the backend contains the bucket key rather than the content. - localFile := oldLocalBodyFiles[i] + localFile := make(map[string]interface{}) + if i < len(oldLocalBodyFiles) && oldLocalBodyFiles[i] != nil { + // The file content is kept from the existing localFile from the state, + // as the response from the backend contains the bucket key rather than the content. + localFile = oldLocalBodyFiles[i] + } localFile["name"] = file.GetName() localFile["original_file_name"] = file.GetOriginalFileName() localFile["type"] = file.GetType()