Skip to content

Commit

Permalink
Updated indexing_configuration thing_indexing_configuration with filter
Browse files Browse the repository at this point in the history
AWS updated the [Create|Get|Update]IndexingConfiguration requests with a new optional parameter: filter
This filter attribute IS required now, when named_shadow_indexing_mode is set to ON.
https://docs.aws.amazon.com/iot/latest/apireference/API_ThingIndexingConfiguration.html

If filter is missing in the described case above, then the following error message is returned:
Error: error updating IoT Indexing Configuration: InvalidRequestException: NamedShadowNames Filter must not be empty for enabling NamedShadowIndexingMode
  • Loading branch information
Zoltan Tudlik committed Sep 19, 2022
1 parent da38070 commit b26420f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/service/iot/indexing_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package iot
import (
"context"
"log"
"regexp"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iot"
Expand Down Expand Up @@ -105,6 +106,30 @@ func ResourceIndexingConfiguration() *schema.Resource {
Default: iot.DeviceDefenderIndexingModeOff,
ValidateFunc: validation.StringInSlice(iot.DeviceDefenderIndexingMode_Values(), false),
},
"filter": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"named_shadow_names": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
MinItems: 1,
MaxItems: 10, // TODO What should this be? 10 or 64? https://docs.aws.amazon.com/iot/latest/apireference/API_IndexingFilter.html
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.All(
validation.StringLenBetween(1, 64),
validation.StringMatch(regexp.MustCompile(`^[a-zA-Z0-9:_-]+`), "must contain only alphanumeric characters, underscores, colons, and hyphens"),
),
},
},
},
},
},
"managed_field": {
Type: schema.TypeSet,
Optional: true,
Expand Down
6 changes: 6 additions & 0 deletions internal/service/iot/indexing_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func testAccIndexingConfiguration_allAttributes(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "thing_indexing_configuration.0.named_shadow_indexing_mode", "ON"),
resource.TestCheckResourceAttr(resourceName, "thing_indexing_configuration.0.thing_connectivity_indexing_mode", "STATUS"),
resource.TestCheckResourceAttr(resourceName, "thing_indexing_configuration.0.thing_indexing_mode", "REGISTRY_AND_SHADOW"),
resource.TestCheckResourceAttr(resourceName, "thing_indexing_configuration.0.filter.named_shadow_names.#", "1"),
resource.TestCheckResourceAttr(resourceName, "thing_indexing_configuration.0.filter.named_shadow_names.0", "thing1shadow"),
),
},
{
Expand Down Expand Up @@ -126,6 +128,10 @@ resource "aws_iot_indexing_configuration" "test" {
device_defender_indexing_mode = "VIOLATIONS"
named_shadow_indexing_mode = "ON"
filter {
named_shadow_names = [ "thing1shadow" ]
}
custom_field {
name = "attributes.version"
type = "Number"
Expand Down

0 comments on commit b26420f

Please sign in to comment.