Skip to content

Commit b73594a

Browse files
committed
Import test refactor for EIP resources
1 parent 8aa2cac commit b73594a

File tree

2 files changed

+189
-173
lines changed

2 files changed

+189
-173
lines changed

aws/resource_aws_eip_association_test.go

Lines changed: 41 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,9 @@ import (
1212
"github.com/hashicorp/terraform/terraform"
1313
)
1414

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-
5515
func TestAccAWSEIPAssociation_basic(t *testing.T) {
5616
var a ec2.Address
17+
resourceName := "aws_eip_association.by_allocation_id"
5718

5819
resource.ParallelTest(t, resource.TestCase{
5920
PreCheck: func() { testAccPreCheck(t) },
@@ -64,25 +25,31 @@ func TestAccAWSEIPAssociation_basic(t *testing.T) {
6425
Config: testAccAWSEIPAssociationConfig,
6526
Check: resource.ComposeTestCheckFunc(
6627
testAccCheckAWSEIPExists(
67-
"aws_eip.bar.0", &a),
28+
"aws_eip.test.0", &a),
6829
testAccCheckAWSEIPAssociationExists(
6930
"aws_eip_association.by_allocation_id", &a),
7031
testAccCheckAWSEIPExists(
71-
"aws_eip.bar.1", &a),
32+
"aws_eip.test.1", &a),
7233
testAccCheckAWSEIPAssociationExists(
7334
"aws_eip_association.by_public_ip", &a),
7435
testAccCheckAWSEIPExists(
75-
"aws_eip.bar.2", &a),
36+
"aws_eip.test.2", &a),
7637
testAccCheckAWSEIPAssociationExists(
7738
"aws_eip_association.to_eni", &a),
7839
),
7940
},
41+
{
42+
ResourceName: resourceName,
43+
ImportState: true,
44+
ImportStateVerify: true,
45+
},
8046
},
8147
})
8248
}
8349

8450
func TestAccAWSEIPAssociation_ec2Classic(t *testing.T) {
8551
var a ec2.Address
52+
resourceName := "aws_eip_association.test"
8653

8754
oldvar := os.Getenv("AWS_DEFAULT_REGION")
8855
os.Setenv("AWS_DEFAULT_REGION", "us-east-1")
@@ -103,13 +70,19 @@ func TestAccAWSEIPAssociation_ec2Classic(t *testing.T) {
10370
testAccCheckAWSEIPAssociationHasIpBasedId("aws_eip_association.test", &a),
10471
),
10572
},
73+
{
74+
ResourceName: resourceName,
75+
ImportState: true,
76+
ImportStateVerify: true,
77+
},
10678
},
10779
})
10880
}
10981

11082
func TestAccAWSEIPAssociation_spotInstance(t *testing.T) {
11183
var a ec2.Address
11284
rInt := acctest.RandInt()
85+
resourceName := "aws_eip_association.test"
11386

11487
resource.ParallelTest(t, resource.TestCase{
11588
PreCheck: func() { testAccPreCheck(t) },
@@ -125,6 +98,11 @@ func TestAccAWSEIPAssociation_spotInstance(t *testing.T) {
12598
resource.TestCheckResourceAttrSet("aws_eip_association.test", "instance_id"),
12699
),
127100
},
101+
{
102+
ResourceName: resourceName,
103+
ImportState: true,
104+
ImportStateVerify: true,
105+
},
128106
},
129107
})
130108
}
@@ -248,55 +226,55 @@ func testAccCheckAWSEIPAssociationDestroy(s *terraform.State) error {
248226
}
249227

250228
const testAccAWSEIPAssociationConfig = `
251-
resource "aws_vpc" "main" {
229+
resource "aws_vpc" "test" {
252230
cidr_block = "192.168.0.0/24"
253231
tags = {
254232
Name = "terraform-testacc-eip-association"
255233
}
256234
}
257-
resource "aws_subnet" "sub" {
258-
vpc_id = "${aws_vpc.main.id}"
235+
resource "aws_subnet" "test" {
236+
vpc_id = "${aws_vpc.test.id}"
259237
cidr_block = "192.168.0.0/25"
260238
availability_zone = "us-west-2a"
261239
tags = {
262240
Name = "tf-acc-eip-association"
263241
}
264242
}
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}"
267245
}
268-
resource "aws_instance" "foo" {
246+
resource "aws_instance" "test" {
269247
count = 2
270248
ami = "ami-21f78e11"
271249
availability_zone = "us-west-2a"
272250
instance_type = "t1.micro"
273-
subnet_id = "${aws_subnet.sub.id}"
251+
subnet_id = "${aws_subnet.test.id}"
274252
private_ip = "192.168.0.${count.index+10}"
275253
}
276-
resource "aws_eip" "bar" {
254+
resource "aws_eip" "test" {
277255
count = 3
278256
vpc = true
279257
}
280258
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"]
284262
}
285263
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"]
289267
}
290268
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}"
293271
}
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}"
296274
private_ips = ["192.168.0.50"]
297-
depends_on = ["aws_instance.foo"]
275+
depends_on = ["aws_instance.test"]
298276
attachment {
299-
instance = "${aws_instance.foo.0.id}"
277+
instance = "${aws_instance.test.0.id}"
300278
device_index = 1
301279
}
302280
}

0 commit comments

Comments
 (0)