-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resource/aws_kinesis_stream: Add state migration for new enforce_cons…
…umer_deletion attribute
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |