@@ -12,48 +12,9 @@ import (
12
12
"github.com/hashicorp/terraform/terraform"
13
13
)
14
14
15
- func TestAccAWSEIPAssociation_importInstance (t * testing.T ) {
16
- resourceName := "aws_eip_association.test"
17
-
18
- resource .ParallelTest (t , resource.TestCase {
19
- PreCheck : func () { testAccPreCheck (t ) },
20
- Providers : testAccProviders ,
21
- CheckDestroy : testAccCheckAWSEIPAssociationDestroy ,
22
- Steps : []resource.TestStep {
23
- {
24
- Config : testAccAWSEIPAssociationConfig_instance ,
25
- },
26
- {
27
- ResourceName : resourceName ,
28
- ImportState : true ,
29
- ImportStateVerify : true ,
30
- },
31
- },
32
- })
33
- }
34
-
35
- func TestAccAWSEIPAssociation_importNetworkInterface (t * testing.T ) {
36
- resourceName := "aws_eip_association.test"
37
-
38
- resource .ParallelTest (t , resource.TestCase {
39
- PreCheck : func () { testAccPreCheck (t ) },
40
- Providers : testAccProviders ,
41
- CheckDestroy : testAccCheckAWSEIPAssociationDestroy ,
42
- Steps : []resource.TestStep {
43
- {
44
- Config : testAccAWSEIPAssociationConfig_networkInterface ,
45
- },
46
- {
47
- ResourceName : resourceName ,
48
- ImportState : true ,
49
- ImportStateVerify : true ,
50
- },
51
- },
52
- })
53
- }
54
-
55
15
func TestAccAWSEIPAssociation_basic (t * testing.T ) {
56
16
var a ec2.Address
17
+ resourceName := "aws_eip_association.by_allocation_id"
57
18
58
19
resource .ParallelTest (t , resource.TestCase {
59
20
PreCheck : func () { testAccPreCheck (t ) },
@@ -64,25 +25,31 @@ func TestAccAWSEIPAssociation_basic(t *testing.T) {
64
25
Config : testAccAWSEIPAssociationConfig ,
65
26
Check : resource .ComposeTestCheckFunc (
66
27
testAccCheckAWSEIPExists (
67
- "aws_eip.bar .0" , & a ),
28
+ "aws_eip.test .0" , & a ),
68
29
testAccCheckAWSEIPAssociationExists (
69
30
"aws_eip_association.by_allocation_id" , & a ),
70
31
testAccCheckAWSEIPExists (
71
- "aws_eip.bar .1" , & a ),
32
+ "aws_eip.test .1" , & a ),
72
33
testAccCheckAWSEIPAssociationExists (
73
34
"aws_eip_association.by_public_ip" , & a ),
74
35
testAccCheckAWSEIPExists (
75
- "aws_eip.bar .2" , & a ),
36
+ "aws_eip.test .2" , & a ),
76
37
testAccCheckAWSEIPAssociationExists (
77
38
"aws_eip_association.to_eni" , & a ),
78
39
),
79
40
},
41
+ {
42
+ ResourceName : resourceName ,
43
+ ImportState : true ,
44
+ ImportStateVerify : true ,
45
+ },
80
46
},
81
47
})
82
48
}
83
49
84
50
func TestAccAWSEIPAssociation_ec2Classic (t * testing.T ) {
85
51
var a ec2.Address
52
+ resourceName := "aws_eip_association.test"
86
53
87
54
oldvar := os .Getenv ("AWS_DEFAULT_REGION" )
88
55
os .Setenv ("AWS_DEFAULT_REGION" , "us-east-1" )
@@ -103,13 +70,19 @@ func TestAccAWSEIPAssociation_ec2Classic(t *testing.T) {
103
70
testAccCheckAWSEIPAssociationHasIpBasedId ("aws_eip_association.test" , & a ),
104
71
),
105
72
},
73
+ {
74
+ ResourceName : resourceName ,
75
+ ImportState : true ,
76
+ ImportStateVerify : true ,
77
+ },
106
78
},
107
79
})
108
80
}
109
81
110
82
func TestAccAWSEIPAssociation_spotInstance (t * testing.T ) {
111
83
var a ec2.Address
112
84
rInt := acctest .RandInt ()
85
+ resourceName := "aws_eip_association.test"
113
86
114
87
resource .ParallelTest (t , resource.TestCase {
115
88
PreCheck : func () { testAccPreCheck (t ) },
@@ -125,6 +98,11 @@ func TestAccAWSEIPAssociation_spotInstance(t *testing.T) {
125
98
resource .TestCheckResourceAttrSet ("aws_eip_association.test" , "instance_id" ),
126
99
),
127
100
},
101
+ {
102
+ ResourceName : resourceName ,
103
+ ImportState : true ,
104
+ ImportStateVerify : true ,
105
+ },
128
106
},
129
107
})
130
108
}
@@ -248,55 +226,55 @@ func testAccCheckAWSEIPAssociationDestroy(s *terraform.State) error {
248
226
}
249
227
250
228
const testAccAWSEIPAssociationConfig = `
251
- resource "aws_vpc" "main " {
229
+ resource "aws_vpc" "test " {
252
230
cidr_block = "192.168.0.0/24"
253
231
tags = {
254
232
Name = "terraform-testacc-eip-association"
255
233
}
256
234
}
257
- resource "aws_subnet" "sub " {
258
- vpc_id = "${aws_vpc.main .id}"
235
+ resource "aws_subnet" "test " {
236
+ vpc_id = "${aws_vpc.test .id}"
259
237
cidr_block = "192.168.0.0/25"
260
238
availability_zone = "us-west-2a"
261
239
tags = {
262
240
Name = "tf-acc-eip-association"
263
241
}
264
242
}
265
- resource "aws_internet_gateway" "igw " {
266
- vpc_id = "${aws_vpc.main .id}"
243
+ resource "aws_internet_gateway" "test " {
244
+ vpc_id = "${aws_vpc.test .id}"
267
245
}
268
- resource "aws_instance" "foo " {
246
+ resource "aws_instance" "test " {
269
247
count = 2
270
248
ami = "ami-21f78e11"
271
249
availability_zone = "us-west-2a"
272
250
instance_type = "t1.micro"
273
- subnet_id = "${aws_subnet.sub .id}"
251
+ subnet_id = "${aws_subnet.test .id}"
274
252
private_ip = "192.168.0.${count.index+10}"
275
253
}
276
- resource "aws_eip" "bar " {
254
+ resource "aws_eip" "test " {
277
255
count = 3
278
256
vpc = true
279
257
}
280
258
resource "aws_eip_association" "by_allocation_id" {
281
- allocation_id = "${aws_eip.bar .0.id}"
282
- instance_id = "${aws_instance.foo .0.id}"
283
- depends_on = ["aws_instance.foo "]
259
+ allocation_id = "${aws_eip.test .0.id}"
260
+ instance_id = "${aws_instance.test .0.id}"
261
+ depends_on = ["aws_instance.test "]
284
262
}
285
263
resource "aws_eip_association" "by_public_ip" {
286
- public_ip = "${aws_eip.bar .1.public_ip}"
287
- instance_id = "${aws_instance.foo .1.id}"
288
- depends_on = ["aws_instance.foo "]
264
+ public_ip = "${aws_eip.test .1.public_ip}"
265
+ instance_id = "${aws_instance.test .1.id}"
266
+ depends_on = ["aws_instance.test "]
289
267
}
290
268
resource "aws_eip_association" "to_eni" {
291
- allocation_id = "${aws_eip.bar .2.id}"
292
- network_interface_id = "${aws_network_interface.baz .id}"
269
+ allocation_id = "${aws_eip.test .2.id}"
270
+ network_interface_id = "${aws_network_interface.test .id}"
293
271
}
294
- resource "aws_network_interface" "baz " {
295
- subnet_id = "${aws_subnet.sub .id}"
272
+ resource "aws_network_interface" "test " {
273
+ subnet_id = "${aws_subnet.test .id}"
296
274
private_ips = ["192.168.0.50"]
297
- depends_on = ["aws_instance.foo "]
275
+ depends_on = ["aws_instance.test "]
298
276
attachment {
299
- instance = "${aws_instance.foo .0.id}"
277
+ instance = "${aws_instance.test .0.id}"
300
278
device_index = 1
301
279
}
302
280
}
0 commit comments