Skip to content

Commit

Permalink
Update 'CustomizeDiff' to prevent incorrect 'ForceNew's.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Mar 2, 2018
1 parent b4ddab7 commit 0693e2d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions aws/resource_aws_dynamodb_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/hashicorp/terraform/helper/customdiff"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand All @@ -30,9 +31,20 @@ func resourceAwsDynamoDbTable() *schema.Resource {
Update: schema.DefaultTimeout(10 * time.Minute),
},

CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error {
return validateDynamoDbStreamSpec(diff)
},
CustomizeDiff: customdiff.Sequence(
func(diff *schema.ResourceDiff, v interface{}) error {
return validateDynamoDbStreamSpec(diff)
},
func(diff *schema.ResourceDiff, v interface{}) error {
if diff.HasChange("server_side_encryption") {
o, n := diff.GetChange("server_side_encryption")
if isDynamoDbTableSSEDisabled(o) && isDynamoDbTableSSEDisabled(n) {
return diff.Clear("server_side_encryption")
}
}
return nil
},
),

SchemaVersion: 1,
MigrateState: resourceAwsDynamoDbTableMigrateState,
Expand Down Expand Up @@ -695,3 +707,12 @@ func waitForDynamoDbTtlUpdateToBeCompleted(tableName string, toEnable bool, conn
_, err := stateConf.WaitForState()
return err
}

func isDynamoDbTableSSEDisabled(v interface{}) bool {
options := v.([]interface{})
if len(options) == 0 {
return true
}
e := options[0].(map[string]interface{})["enabled"]
return !e.(bool)
}

0 comments on commit 0693e2d

Please sign in to comment.