Skip to content

Commit

Permalink
Additional encryption acceptance test steps.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Mar 5, 2018
1 parent 5c58790 commit 0eb8914
Showing 1 changed file with 73 additions and 6 deletions.
79 changes: 73 additions & 6 deletions aws/resource_aws_dynamodb_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,31 @@ func TestAccAWSDynamoDbTable_basic(t *testing.T) {

rName := acctest.RandomWithPrefix("TerraformTestTable-")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDynamoDbConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "name", rName),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "read_capacity", "1"),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "write_capacity", "1"),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "hash_key", "TestTableHashKey"),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "attribute.2990477658.name", "TestTableHashKey"),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "attribute.2990477658.type", "S"),
),
},
},
})
}
func TestAccAWSDynamoDbTable_extended(t *testing.T) {
var conf dynamodb.DescribeTableOutput

rName := acctest.RandomWithPrefix("TerraformTestTable-")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down Expand Up @@ -626,7 +651,7 @@ func testAccCheckDynamoDbTableTimeToLiveWasUpdated(n string) resource.TestCheckF
}

func TestAccAWSDynamoDbTable_encryption(t *testing.T) {
var conf dynamodb.DescribeTableOutput
var confEncEnabled, confEncDisabled, confBasic dynamodb.DescribeTableOutput

rName := acctest.RandomWithPrefix("TerraformTestTable-")

Expand All @@ -636,13 +661,39 @@ func TestAccAWSDynamoDbTable_encryption(t *testing.T) {
CheckDestroy: testAccCheckAWSDynamoDbTableDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSDynamoDbConfigInitialStateWithEncryption(rName),
Config: testAccAWSDynamoDbConfigInitialStateWithEncryption(rName, true),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &conf),
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &confEncEnabled),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "server_side_encryption.#", "1"),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "server_side_encryption.0.enabled", "true"),
),
},
{
Config: testAccAWSDynamoDbConfigInitialStateWithEncryption(rName, false),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &confEncDisabled),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "server_side_encryption.#", "0"),
func(s *terraform.State) error {
if confEncDisabled.Table.CreationDateTime.Equal(*confEncEnabled.Table.CreationDateTime) {
return fmt.Errorf("[ERROR] DynamoDB table not recreated when changing SSE")
}
return nil
},
),
},
{
Config: testAccAWSDynamoDbConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckInitialAWSDynamoDbTableExists("aws_dynamodb_table.basic-dynamodb-table", &confBasic),
resource.TestCheckResourceAttr("aws_dynamodb_table.basic-dynamodb-table", "server_side_encryption.#", "0"),
func(s *terraform.State) error {
if !confBasic.Table.CreationDateTime.Equal(*confEncDisabled.Table.CreationDateTime) {
return fmt.Errorf("[ERROR] DynamoDB table was recreated unexpectedly")
}
return nil
},
),
},
},
})
}
Expand Down Expand Up @@ -906,6 +957,22 @@ func dynamoDbAttributesToMap(attributes *[]*dynamodb.AttributeDefinition) map[st
return attrmap
}

func testAccAWSDynamoDbConfig_basic(rName string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "%s"
read_capacity = 1
write_capacity = 1
hash_key = "TestTableHashKey"
attribute {
name = "TestTableHashKey"
type = "S"
}
}
`, rName)
}

func testAccAWSDynamoDbConfigInitialState(rName string) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "basic-dynamodb-table" {
Expand Down Expand Up @@ -953,7 +1020,7 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" {
`, rName)
}

func testAccAWSDynamoDbConfigInitialStateWithEncryption(rName string) string {
func testAccAWSDynamoDbConfigInitialStateWithEncryption(rName string, enabled bool) string {
return fmt.Sprintf(`
resource "aws_dynamodb_table" "basic-dynamodb-table" {
name = "%s"
Expand All @@ -967,10 +1034,10 @@ resource "aws_dynamodb_table" "basic-dynamodb-table" {
}
server_side_encryption {
enabled = true
enabled = %t
}
}
`, rName)
`, rName, enabled)
}

func testAccAWSDynamoDbConfigAddSecondaryGSI(rName string) string {
Expand Down

0 comments on commit 0eb8914

Please sign in to comment.