Skip to content

Commit

Permalink
r/aws_cloudsearch_domain: fix index_field crash on read (#35900)
Browse files Browse the repository at this point in the history
* 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
```

* chore: changelog
  • Loading branch information
jar-b authored Feb 21, 2024
1 parent 7b21bea commit 3d74da9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/35900.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_cloudsearch_domain: Prevent panic when reading nil `index_field` options response values
```
33 changes: 33 additions & 0 deletions internal/service/cloudsearch/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3d74da9

Please sign in to comment.