From 685e2953717f71516ed7a6ae11e10cc6721d1aee Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Tue, 20 Feb 2024 16:29:23 -0500 Subject: [PATCH 1/2] r/aws_cloudsearch_domain: fix index_field crash on read A missing nil check in the flattener for the `index_field` argument could, under certain conditions, cause the read operation to panic. ``` make testacc PKG=cloudsearch TESTS=TestAccCloudSearchDomain_ ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./internal/service/cloudsearch/... -v -count 1 -parallel 20 -run='TestAccCloudSearchDomain_' -timeout 360m --- PASS: TestAccCloudSearchDomain_basic (708.55s) --- PASS: TestAccCloudSearchDomain_disappears (746.41s) --- PASS: TestAccCloudSearchDomain_sourceFields (1712.89s) --- PASS: TestAccCloudSearchDomain_indexFields (1859.65s) --- PASS: TestAccCloudSearchDomain_update (2328.91s) PASS ok github.com/hashicorp/terraform-provider-aws/internal/service/cloudsearch 2336.129s ``` --- internal/service/cloudsearch/domain.go | 33 ++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/internal/service/cloudsearch/domain.go b/internal/service/cloudsearch/domain.go index bf8a2b4a28a..32f97dd4570 100644 --- a/internal/service/cloudsearch/domain.go +++ b/internal/service/cloudsearch/domain.go @@ -1049,6 +1049,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter switch fieldType { case types.IndexFieldTypeDate: options := field.DateOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = aws.ToString(v) @@ -1080,6 +1083,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeDateArray: options := field.DateArrayOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = aws.ToString(v) @@ -1108,6 +1114,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeDouble: options := field.DoubleOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = flex.Float64ToStringValue(v) @@ -1139,6 +1148,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeDoubleArray: options := field.DoubleArrayOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = flex.Float64ToStringValue(v) @@ -1167,6 +1179,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeInt: options := field.IntOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = flex.Int64ToStringValue(v) @@ -1198,6 +1213,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeIntArray: options := field.IntArrayOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = flex.Int64ToStringValue(v) @@ -1226,6 +1244,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeLatlon: options := field.LatLonOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = aws.ToString(v) @@ -1257,6 +1278,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeLiteral: options := field.LiteralOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = aws.ToString(v) @@ -1288,6 +1312,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeLiteralArray: options := field.LiteralArrayOptions + if options == nil { + break + } if v := options.DefaultValue; v != nil { tfMap["default_value"] = aws.ToString(v) @@ -1316,6 +1343,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeText: options := field.TextOptions + if options == nil { + break + } if v := options.AnalysisScheme; v != nil { tfMap["analysis_scheme"] = aws.ToString(v) @@ -1347,6 +1377,9 @@ func flattenIndexFieldStatus(apiObject types.IndexFieldStatus) (map[string]inter case types.IndexFieldTypeTextArray: options := field.TextArrayOptions + if options == nil { + break + } if v := options.AnalysisScheme; v != nil { tfMap["analysis_scheme"] = aws.ToString(v) From d8929d72661004a5b53bc0ce0b4717a7c02a388a Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Tue, 20 Feb 2024 16:56:50 -0500 Subject: [PATCH 2/2] chore: changelog --- .changelog/35900.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35900.txt diff --git a/.changelog/35900.txt b/.changelog/35900.txt new file mode 100644 index 00000000000..aea58669932 --- /dev/null +++ b/.changelog/35900.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_cloudsearch_domain: Prevent panic when reading nil `index_field` options response values +```