Skip to content

Commit

Permalink
resource/aws_kinesis_stream: Add state migration for new enforce_cons…
Browse files Browse the repository at this point in the history
…umer_deletion attribute
  • Loading branch information
bflad committed May 23, 2019
1 parent 40bc77d commit 42069b4
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aws/resource_aws_kinesis_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ func resourceAwsKinesisStream() *schema.Resource {
State: resourceAwsKinesisStreamImport,
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceAwsKinesisStreamResourceV0().CoreConfigSchema().ImpliedType(),
Upgrade: resourceAwsKinesisStreamStateUpgradeV0,
Version: 0,
},
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Update: schema.DefaultTimeout(120 * time.Minute),
Expand Down
59 changes: 59 additions & 0 deletions aws/resource_aws_kinesis_stream_migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package aws

import (
"github.com/hashicorp/terraform/helper/schema"
)

func resourceAwsKinesisStreamResourceV0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"shard_count": {
Type: schema.TypeInt,
Required: true,
},

"retention_period": {
Type: schema.TypeInt,
Optional: true,
Default: 24,
},

"shard_level_metrics": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},

"encryption_type": {
Type: schema.TypeString,
Optional: true,
Default: "NONE",
},

"kms_key_id": {
Type: schema.TypeString,
Optional: true,
},

"arn": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"tags": tagsSchema(),
},
}
}

func resourceAwsKinesisStreamStateUpgradeV0(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
rawState["enforce_consumer_deletion"] = false

return rawState, nil
}
46 changes: 46 additions & 0 deletions aws/resource_aws_kinesis_stream_migrate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package aws

import (
"reflect"
"testing"
)

func testResourceAwsKinesisStreamStateDataV0() map[string]interface{} {
return map[string]interface{}{
"arn": "arn:aws:test:us-east-1:123456789012:test",
"encryption_type": "NONE",
"kms_key_id": "",
"name": "test",
"retention_period": 24,
"shard_count": 1,
"shard_level_metrics": []interface{}{},
"tags": map[string]interface{}{"key1": "value1"},
}
}

func testResourceAwsKinesisStreamStateDataV1() map[string]interface{} {
v0 := testResourceAwsKinesisStreamStateDataV0()
return map[string]interface{}{
"arn": v0["arn"],
"encryption_type": v0["encryption_type"],
"enforce_consumer_deletion": false,
"kms_key_id": v0["kms_key_id"],
"name": v0["name"],
"retention_period": v0["retention_period"],
"shard_count": v0["shard_count"],
"shard_level_metrics": v0["shard_level_metrics"],
"tags": v0["tags"],
}
}

func TestResourceAwsKinesisStreamStateUpgradeV0(t *testing.T) {
expected := testResourceAwsKinesisStreamStateDataV1()
actual, err := resourceAwsKinesisStreamStateUpgradeV0(testResourceAwsKinesisStreamStateDataV0(), nil)
if err != nil {
t.Fatalf("error migrating state: %s", err)
}

if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", expected, actual)
}
}

0 comments on commit 42069b4

Please sign in to comment.