terraform/builtin/providers/aws/resource_aws_security_group...

68 lines
1.7 KiB
Go
Raw Normal View History

2015-06-16 22:54:27 +02:00
package aws
import (
"testing"
"github.com/hashicorp/terraform/terraform"
)
func TestAWSSecurityGroupRuleMigrateState(t *testing.T) {
cases := map[string]struct {
StateVersion int
2015-06-16 23:21:46 +02:00
ID string
2015-06-16 22:54:27 +02:00
Attributes map[string]string
Expected string
Meta interface{}
}{
"v0_1": {
StateVersion: 0,
2015-06-16 23:21:46 +02:00
ID: "sg-4235098228",
2015-06-16 22:54:27 +02:00
Attributes: map[string]string{
2015-06-16 23:15:07 +02:00
"self": "false",
"to_port": "0",
"security_group_id": "sg-13877277",
"cidr_blocks.#": "0",
"type": "ingress",
"protocol": "-1",
"from_port": "0",
"source_security_group_id": "sg-11877275",
2015-06-16 22:54:27 +02:00
},
2015-10-12 23:26:49 +02:00
Expected: "sgrule-2889201120",
2015-06-16 22:54:27 +02:00
},
2015-06-16 23:21:46 +02:00
"v0_2": {
StateVersion: 0,
ID: "sg-1021609891",
Attributes: map[string]string{
"security_group_id": "sg-0981746d",
"from_port": "0",
"to_port": "0",
"type": "ingress",
"self": "false",
"protocol": "-1",
"cidr_blocks.0": "172.16.1.0/24",
"cidr_blocks.1": "172.16.2.0/24",
"cidr_blocks.2": "172.16.3.0/24",
"cidr_blocks.3": "172.16.4.0/24",
"cidr_blocks.#": "4"},
2015-10-12 23:26:49 +02:00
Expected: "sgrule-1826358977",
2015-06-16 23:21:46 +02:00
},
2015-06-16 22:54:27 +02:00
}
for tn, tc := range cases {
is := &terraform.InstanceState{
2015-06-16 23:21:46 +02:00
ID: tc.ID,
2015-06-16 22:54:27 +02:00
Attributes: tc.Attributes,
}
is, err := resourceAwsSecurityGroupRuleMigrateState(
tc.StateVersion, is, tc.Meta)
if err != nil {
t.Fatalf("bad: %s, err: %#v", tn, err)
}
if is.ID != tc.Expected {
t.Fatalf("bad sg rule id: %s\n\n expected: %s", is.ID, tc.Expected)
}
}
}