github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/resource_aws_security_group_rule_migrate_test.go (about) 1 package aws 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 func TestAWSSecurityGroupRuleMigrateState(t *testing.T) { 10 cases := map[string]struct { 11 StateVersion int 12 ID string 13 Attributes map[string]string 14 Expected string 15 Meta interface{} 16 }{ 17 "v0_1": { 18 StateVersion: 0, 19 ID: "sg-4235098228", 20 Attributes: map[string]string{ 21 "self": "false", 22 "to_port": "0", 23 "security_group_id": "sg-13877277", 24 "cidr_blocks.#": "0", 25 "type": "ingress", 26 "protocol": "-1", 27 "from_port": "0", 28 "source_security_group_id": "sg-11877275", 29 }, 30 Expected: "sgrule-2889201120", 31 }, 32 "v0_2": { 33 StateVersion: 0, 34 ID: "sg-1021609891", 35 Attributes: map[string]string{ 36 "security_group_id": "sg-0981746d", 37 "from_port": "0", 38 "to_port": "0", 39 "type": "ingress", 40 "self": "false", 41 "protocol": "-1", 42 "cidr_blocks.0": "172.16.1.0/24", 43 "cidr_blocks.1": "172.16.2.0/24", 44 "cidr_blocks.2": "172.16.3.0/24", 45 "cidr_blocks.3": "172.16.4.0/24", 46 "cidr_blocks.#": "4"}, 47 Expected: "sgrule-1826358977", 48 }, 49 } 50 51 for tn, tc := range cases { 52 is := &terraform.InstanceState{ 53 ID: tc.ID, 54 Attributes: tc.Attributes, 55 } 56 is, err := resourceAwsSecurityGroupRuleMigrateState( 57 tc.StateVersion, is, tc.Meta) 58 59 if err != nil { 60 t.Fatalf("bad: %s, err: %#v", tn, err) 61 } 62 63 if is.ID != tc.Expected { 64 t.Fatalf("bad sg rule id: %s\n\n expected: %s", is.ID, tc.Expected) 65 } 66 } 67 }