From dbf2bd31d440df31cd61052b81a2d7dad2546c75 Mon Sep 17 00:00:00 2001 From: 178inaba Date: Tue, 6 Nov 2018 02:24:30 +0900 Subject: [PATCH] Add validate DynamoDB indexes --- aws/validators.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/aws/validators.go b/aws/validators.go index 4cec1021ee3..707d42b29e4 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -1843,6 +1843,8 @@ func validateDynamoDbTableAttributes(d *schema.ResourceDiff) error { if _, ok := indexedAttributes[attrName]; !ok { missingAttrDefs = append(missingAttrDefs, attrName) + } else { + delete(indexedAttributes, attrName) } } @@ -1850,6 +1852,15 @@ func validateDynamoDbTableAttributes(d *schema.ResourceDiff) error { return fmt.Errorf("All attributes must be indexed. Unused attributes: %q", missingAttrDefs) } + if len(indexedAttributes) > 0 { + missingIndexes := []string{} + for index := range indexedAttributes { + missingIndexes = append(missingIndexes, index) + } + + return fmt.Errorf("All indexes must be attribute. Unused indexes: %q", missingIndexes) + } + return nil }