From 5c58790ca989c7f6e431b009b21e5fc38b54a003 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 2 Mar 2018 11:58:36 -0500 Subject: [PATCH] Update 'CustomizeDiff' to prevent incorrect 'ForceNew's. --- aws/resource_aws_dynamodb_table.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/aws/resource_aws_dynamodb_table.go b/aws/resource_aws_dynamodb_table.go index 3dd50aaaa75..45fa66ef01c 100644 --- a/aws/resource_aws_dynamodb_table.go +++ b/aws/resource_aws_dynamodb_table.go @@ -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" @@ -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.Id() != "" && 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, @@ -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) +}