Adding a validation function for the DynamoDb Table StreamViewType
This commit is contained in:
parent
d46348c233
commit
8b79881dea
|
@ -172,6 +172,7 @@ func resourceAwsDynamoDbTable() *schema.Resource {
|
|||
value := v.(string)
|
||||
return strings.ToUpper(value)
|
||||
},
|
||||
ValidateFunc: validateStreamViewType,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -800,3 +801,18 @@ func waitForTableToBeActive(tableName string, meta interface{}) error {
|
|||
return nil
|
||||
|
||||
}
|
||||
|
||||
func validateStreamViewType(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
viewTypes := map[string]bool {
|
||||
"KEYS_ONLY": true,
|
||||
"NEW_IMAGE": true,
|
||||
"OLD_IMAGE": true,
|
||||
"NEW_AND_OLD_IMAGES": true,
|
||||
}
|
||||
|
||||
if !viewTypes[value] {
|
||||
errors = append(errors, fmt.Errorf("%q be a valid DynamoDB StreamViewType", k))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -53,6 +53,46 @@ func TestAccAWSDynamoDbTable_streamSpecification(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestResourceAWSDynamoDbTableStreamViewType_validation(t *testing.T) {
|
||||
cases := []struct {
|
||||
Value string
|
||||
ErrCount int
|
||||
}{
|
||||
{
|
||||
Value: "KEYS-ONLY",
|
||||
ErrCount: 1,
|
||||
},
|
||||
{
|
||||
Value: "RANDOM-STRING",
|
||||
ErrCount: 1,
|
||||
},
|
||||
{
|
||||
Value: "KEYS_ONLY",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "NEW_AND_OLD_IMAGES",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "NEW_IMAGE",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "OLD_IMAGE",
|
||||
ErrCount: 0,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
_, errors := validateStreamViewType(tc.Value, "aws_dynamodb_table_stream_view_type")
|
||||
|
||||
if len(errors) != tc.ErrCount {
|
||||
t.Fatalf("Expected the DynamoDB stream_view_type to trigger a validation error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testAccCheckAWSDynamoDbTableDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).dynamodbconn
|
||||
|
||||
|
|
Loading…
Reference in New Issue