Skip to content

Commit a79bcaa

Browse files
authored
handle when state does not exist (#2659)
1 parent 46c6b1d commit a79bcaa

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

datadog/resource_datadog_synthetics_test_.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,9 +2877,12 @@ func buildDatadogBodyFiles(attr []interface{}) []datadogV1.SyntheticsTestRequest
28772877
func buildTerraformBodyFiles(actualBodyFiles *[]datadogV1.SyntheticsTestRequestBodyFile, oldLocalBodyFiles []map[string]interface{}) (localBodyFiles []map[string]interface{}) {
28782878
localBodyFiles = make([]map[string]interface{}, len(*actualBodyFiles))
28792879
for i, file := range *actualBodyFiles {
2880-
// The file content is kept from the existing localFile from the state,
2881-
// as the response from the backend contains the bucket key rather than the content.
2882-
localFile := oldLocalBodyFiles[i]
2880+
localFile := make(map[string]interface{})
2881+
if i < len(oldLocalBodyFiles) && oldLocalBodyFiles[i] != nil {
2882+
// The file content is kept from the existing localFile from the state,
2883+
// as the response from the backend contains the bucket key rather than the content.
2884+
localFile = oldLocalBodyFiles[i]
2885+
}
28832886
localFile["name"] = file.GetName()
28842887
localFile["original_file_name"] = file.GetOriginalFileName()
28852888
localFile["type"] = file.GetType()

0 commit comments

Comments
 (0)