From 42069b4585760440e99661bc08f718e254c19b4e Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Thu, 23 May 2019 13:31:48 -0400 Subject: [PATCH] resource/aws_kinesis_stream: Add state migration for new enforce_consumer_deletion attribute --- aws/resource_aws_kinesis_stream.go | 9 +++ aws/resource_aws_kinesis_stream_migrate.go | 59 +++++++++++++++++++ ...esource_aws_kinesis_stream_migrate_test.go | 46 +++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 aws/resource_aws_kinesis_stream_migrate.go create mode 100644 aws/resource_aws_kinesis_stream_migrate_test.go diff --git a/aws/resource_aws_kinesis_stream.go b/aws/resource_aws_kinesis_stream.go index c86e1379357..7b6708ec194 100644 --- a/aws/resource_aws_kinesis_stream.go +++ b/aws/resource_aws_kinesis_stream.go @@ -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), diff --git a/aws/resource_aws_kinesis_stream_migrate.go b/aws/resource_aws_kinesis_stream_migrate.go new file mode 100644 index 00000000000..aa6a3b1468f --- /dev/null +++ b/aws/resource_aws_kinesis_stream_migrate.go @@ -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 +} diff --git a/aws/resource_aws_kinesis_stream_migrate_test.go b/aws/resource_aws_kinesis_stream_migrate_test.go new file mode 100644 index 00000000000..45a620ef317 --- /dev/null +++ b/aws/resource_aws_kinesis_stream_migrate_test.go @@ -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) + } +}