Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_elasticache_replication_group: Implement noop MigrateState for v0..v1 #8887

Merged
merged 4 commits into from
Jun 11, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions aws/resource_aws_elasticache_replication_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -223,6 +225,7 @@ func resourceAwsElasticacheReplicationGroup() *schema.Resource {
},
},
SchemaVersion: 1,
MigrateState: resourceAwsElasticacheReplicationGroupMigrateState,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is an exceptional case and we want to perform the simplest possible upgrade for compatibility, can you please inline this with the following comments?

Suggested change
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
},

I verified this successfully with a Terraform AWS Provider 1.13.0 aws_elasticache_replication_group resource on Terraform 0.12.1. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll swap over. I do find the replacement more error prone, but either way is fine by me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @akatrevorjay, the passthrough implementation is not more error prone -- MigrateState and dealing with flatmap state migrations in of the Terraform v0.12's Provider SDK has been superseded with JSON state migrations via StateUpgraders. In this case, we do not need to worry about doing anything other than passing through the existing InstanceState to bypass the Terraform runtime error, which matches the Terraform v0.11 Provider SDK in this situation where MigrateState was not implemented alongside a SchemaVersion update. We'll be removing the upstream runtime error in the next version of Terraform v0.12 (hashicorp/terraform#21625) to match the old Terraform v0.11 behavior.

Copy link
Contributor Author

@akatrevorjay akatrevorjay Jun 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha! I didn't see any mention of StateUpgraders in the docs at the time of writing this, I'm guessing I must have missed it! Thanks so much for the explanation!


Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Expand All @@ -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

Expand Down