From ca38834b03ccef71496e35a5a7c79a8786a7f662 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Mon, 3 Jun 2019 14:47:57 -0700 Subject: [PATCH 1/3] aws_elasticache_replication_group: Implement no-op MigrateState from v0 to v1 --- ...ource_aws_elasticache_replication_group.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/aws/resource_aws_elasticache_replication_group.go b/aws/resource_aws_elasticache_replication_group.go index 5a127aafd6c..e9d4196828e 100644 --- a/aws/resource_aws_elasticache_replication_group.go +++ b/aws/resource_aws_elasticache_replication_group.go @@ -9,9 +9,11 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/elasticache" + "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" + "github.com/hashicorp/terraform/terraform" ) func resourceAwsElasticacheReplicationGroup() *schema.Resource { @@ -223,6 +225,7 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { }, }, SchemaVersion: 1, + MigrateState: resourceAwsElasticacheReplicationGroupMigrateState, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(60 * time.Minute), @@ -232,6 +235,22 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { } } +func resourceAwsElasticacheReplicationGroupMigrateState(v int, inst *terraform.InstanceState, meta interface {}) (*terraform.InstanceState, error) { + switch v { + case 0: + log.Printf("[WARN] Elasticache Replication Group (%s) v%d; migrating to v1 (noop)", inst, v) + + fallthrough + + case 1: + // Current version + return inst, nil + + default: + return inst, fmt.Errorf("Unexpected schema version: %d", v) + } +} + func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticacheconn From ac201022938ffdb95eca18ce1b2bede743cdada3 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Wed, 5 Jun 2019 17:28:37 -0700 Subject: [PATCH 2/3] gofmt --- aws/resource_aws_elasticache_replication_group.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/aws/resource_aws_elasticache_replication_group.go b/aws/resource_aws_elasticache_replication_group.go index e9d4196828e..d4f263cff76 100644 --- a/aws/resource_aws_elasticache_replication_group.go +++ b/aws/resource_aws_elasticache_replication_group.go @@ -225,7 +225,7 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { }, }, SchemaVersion: 1, - MigrateState: resourceAwsElasticacheReplicationGroupMigrateState, + MigrateState: resourceAwsElasticacheReplicationGroupMigrateState, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(60 * time.Minute), @@ -235,19 +235,19 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { } } -func resourceAwsElasticacheReplicationGroupMigrateState(v int, inst *terraform.InstanceState, meta interface {}) (*terraform.InstanceState, error) { +func resourceAwsElasticacheReplicationGroupMigrateState(v int, inst *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { switch v { case 0: - log.Printf("[WARN] Elasticache Replication Group (%s) v%d; migrating to v1 (noop)", inst, v) + log.Printf("[WARN] Elasticache Replication Group (%s) v%d; migrating to v1 (noop)", inst, v) - fallthrough + fallthrough case 1: - // Current version - return inst, nil + // Current version + return inst, nil default: - return inst, fmt.Errorf("Unexpected schema version: %d", v) + return inst, fmt.Errorf("Unexpected schema version: %d", v) } } From dbc10a0bfb9b6b6cd8a5ef497f6a2557c9057dd6 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Mon, 10 Jun 2019 19:40:46 -0700 Subject: [PATCH 3/3] Swap MigrateState to one requested by reviewer. --- ...ource_aws_elasticache_replication_group.go | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_elasticache_replication_group.go b/aws/resource_aws_elasticache_replication_group.go index d4f263cff76..16a23c4b962 100644 --- a/aws/resource_aws_elasticache_replication_group.go +++ b/aws/resource_aws_elasticache_replication_group.go @@ -225,7 +225,13 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { }, }, SchemaVersion: 1, - MigrateState: resourceAwsElasticacheReplicationGroupMigrateState, + + // SchemaVersion: 1 did not include any state changes via MigrateState. + // Perform a no-operation state upgrade for Terraform 0.12 compatibility. + // Future state migrations should be performed with StateUpgraders. + MigrateState: func(v int, inst *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { + return inst, nil + }, Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(60 * time.Minute), @@ -235,22 +241,6 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource { } } -func resourceAwsElasticacheReplicationGroupMigrateState(v int, inst *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) { - switch v { - case 0: - log.Printf("[WARN] Elasticache Replication Group (%s) v%d; migrating to v1 (noop)", inst, v) - - fallthrough - - case 1: - // Current version - return inst, nil - - default: - return inst, fmt.Errorf("Unexpected schema version: %d", v) - } -} - func resourceAwsElasticacheReplicationGroupCreate(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).elasticacheconn