Skip to content

Commit 6006087

Browse files
committed
Add back a couple import tests, and a VPC-only precheck
1 parent b73594a commit 6006087

File tree

2 files changed

+114
-17
lines changed

2 files changed

+114
-17
lines changed

aws/provider_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ func testAccEC2ClassicPreCheck(t *testing.T) {
218218
}
219219
}
220220

221+
func testAccEC2VPCOnlyPreCheck(t *testing.T) {
222+
client := testAccProvider.Meta().(*AWSClient)
223+
platforms := client.supportedplatforms
224+
region := client.region
225+
if hasEc2Classic(platforms) {
226+
t.Skipf("This test can only in regions without EC2 Classic, platforms available in %s: %q",
227+
region, platforms)
228+
}
229+
}
230+
221231
func testAccHasServicePreCheck(service string, t *testing.T) {
222232
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), testAccGetRegion()); ok {
223233
if _, ok := partition.Services()[service]; !ok {

aws/resource_aws_eip_association_test.go

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

15+
func TestAccAWSEIPAssociation_instance(t *testing.T) {
16+
resourceName := "aws_eip_association.test"
17+
var a ec2.Address
18+
19+
resource.ParallelTest(t, resource.TestCase{
20+
PreCheck: func() { testAccPreCheck(t) },
21+
Providers: testAccProviders,
22+
CheckDestroy: testAccCheckAWSEIPAssociationDestroy,
23+
Steps: []resource.TestStep{
24+
{
25+
Config: testAccAWSEIPAssociationConfig_instance,
26+
Check: resource.ComposeTestCheckFunc(
27+
testAccCheckAWSEIPExists(
28+
"aws_eip.test", &a),
29+
testAccCheckAWSEIPAssociationExists(
30+
resourceName, &a),
31+
testAccCheckAWSEIPAssociationExists(
32+
resourceName, &a),
33+
),
34+
},
35+
{
36+
ResourceName: resourceName,
37+
ImportState: true,
38+
ImportStateVerify: true,
39+
},
40+
},
41+
})
42+
}
43+
44+
func TestAccAWSEIPAssociation_networkInterface(t *testing.T) {
45+
resourceName := "aws_eip_association.test"
46+
var a ec2.Address
47+
48+
resource.ParallelTest(t, resource.TestCase{
49+
PreCheck: func() { testAccPreCheck(t) },
50+
Providers: testAccProviders,
51+
CheckDestroy: testAccCheckAWSEIPAssociationDestroy,
52+
Steps: []resource.TestStep{
53+
{
54+
Config: testAccAWSEIPAssociationConfig_networkInterface,
55+
Check: resource.ComposeTestCheckFunc(
56+
testAccCheckAWSEIPExists(
57+
"aws_eip.test", &a),
58+
testAccCheckAWSEIPAssociationExists(
59+
resourceName, &a),
60+
),
61+
},
62+
{
63+
ResourceName: resourceName,
64+
ImportState: true,
65+
ImportStateVerify: true,
66+
},
67+
},
68+
})
69+
}
70+
1571
func TestAccAWSEIPAssociation_basic(t *testing.T) {
1672
var a ec2.Address
1773
resourceName := "aws_eip_association.by_allocation_id"
1874

1975
resource.ParallelTest(t, resource.TestCase{
20-
PreCheck: func() { testAccPreCheck(t) },
76+
PreCheck: func() { testAccPreCheck(t); testAccEC2VPCOnlyPreCheck(t) },
2177
Providers: testAccProviders,
2278
CheckDestroy: testAccCheckAWSEIPAssociationDestroy,
2379
Steps: []resource.TestStep{
@@ -64,10 +120,10 @@ func TestAccAWSEIPAssociation_ec2Classic(t *testing.T) {
64120
Config: testAccAWSEIPAssociationConfig_ec2Classic,
65121
Check: resource.ComposeTestCheckFunc(
66122
testAccCheckAWSEIPExists("aws_eip.test", &a),
67-
testAccCheckAWSEIPAssociationExists("aws_eip_association.test", &a),
68-
resource.TestCheckResourceAttrSet("aws_eip_association.test", "public_ip"),
69-
resource.TestCheckResourceAttr("aws_eip_association.test", "allocation_id", ""),
70-
testAccCheckAWSEIPAssociationHasIpBasedId("aws_eip_association.test", &a),
123+
testAccCheckAWSEIPAssociationExists(resourceName, &a),
124+
resource.TestCheckResourceAttrSet(resourceName, "public_ip"),
125+
resource.TestCheckResourceAttr(resourceName, "allocation_id", ""),
126+
testAccCheckAWSEIPAssociationHasIpBasedId(resourceName, &a),
71127
),
72128
},
73129
{
@@ -93,9 +149,9 @@ func TestAccAWSEIPAssociation_spotInstance(t *testing.T) {
93149
Config: testAccAWSEIPAssociationConfig_spotInstance(rInt),
94150
Check: resource.ComposeTestCheckFunc(
95151
testAccCheckAWSEIPExists("aws_eip.test", &a),
96-
testAccCheckAWSEIPAssociationExists("aws_eip_association.test", &a),
97-
resource.TestCheckResourceAttrSet("aws_eip_association.test", "allocation_id"),
98-
resource.TestCheckResourceAttrSet("aws_eip_association.test", "instance_id"),
152+
testAccCheckAWSEIPAssociationExists(resourceName, &a),
153+
resource.TestCheckResourceAttrSet(resourceName, "allocation_id"),
154+
resource.TestCheckResourceAttrSet(resourceName, "instance_id"),
99155
),
100156
},
101157
{
@@ -226,16 +282,31 @@ func testAccCheckAWSEIPAssociationDestroy(s *terraform.State) error {
226282
}
227283

228284
const testAccAWSEIPAssociationConfig = `
285+
data "aws_availability_zones" "available" {
286+
state = "available"
287+
}
288+
229289
resource "aws_vpc" "test" {
230290
cidr_block = "192.168.0.0/24"
231291
tags = {
232292
Name = "terraform-testacc-eip-association"
233293
}
234294
}
295+
296+
data "aws_ami" "amzn-ami-minimal-pv" {
297+
most_recent = true
298+
owners = ["amazon"]
299+
300+
filter {
301+
name = "name"
302+
values = ["amzn-ami-minimal-pv-*"]
303+
}
304+
}
305+
235306
resource "aws_subnet" "test" {
236307
vpc_id = "${aws_vpc.test.id}"
237308
cidr_block = "192.168.0.0/25"
238-
availability_zone = "us-west-2a"
309+
availability_zone = "${data.aws_availability_zones.available.names[0]}"
239310
tags = {
240311
Name = "tf-acc-eip-association"
241312
}
@@ -245,9 +316,9 @@ resource "aws_internet_gateway" "test" {
245316
}
246317
resource "aws_instance" "test" {
247318
count = 2
248-
ami = "ami-21f78e11"
249-
availability_zone = "us-west-2a"
250-
instance_type = "t1.micro"
319+
ami = "${data.aws_ami.amzn-ami-minimal-pv.id}"
320+
availability_zone = "${data.aws_availability_zones.available.names[0]}"
321+
instance_type = "m1.small"
251322
subnet_id = "${aws_subnet.test.id}"
252323
private_ip = "192.168.0.${count.index+10}"
253324
}
@@ -281,6 +352,20 @@ resource "aws_network_interface" "test" {
281352
`
282353

283354
const testAccAWSEIPAssociationConfigDisappears = `
355+
data "aws_availability_zones" "available" {
356+
state = "available"
357+
}
358+
359+
data "aws_ami" "amzn-ami-minimal-pv" {
360+
most_recent = true
361+
owners = ["amazon"]
362+
363+
filter {
364+
name = "name"
365+
values = ["amzn-ami-minimal-pv-*"]
366+
}
367+
}
368+
284369
resource "aws_vpc" "main" {
285370
cidr_block = "192.168.0.0/24"
286371
tags = {
@@ -290,7 +375,7 @@ resource "aws_vpc" "main" {
290375
resource "aws_subnet" "sub" {
291376
vpc_id = "${aws_vpc.main.id}"
292377
cidr_block = "192.168.0.0/25"
293-
availability_zone = "us-west-2a"
378+
availability_zone = "${data.aws_availability_zones.available.names[0]}"
294379
tags = {
295380
Name = "tf-acc-eip-association-disappears"
296381
}
@@ -299,9 +384,9 @@ resource "aws_internet_gateway" "igw" {
299384
vpc_id = "${aws_vpc.main.id}"
300385
}
301386
resource "aws_instance" "foo" {
302-
ami = "ami-21f78e11"
303-
availability_zone = "us-west-2a"
304-
instance_type = "t1.micro"
387+
ami = "${data.aws_ami.amzn-ami-minimal-pv.id}"
388+
availability_zone = "${data.aws_availability_zones.available.names[0]}"
389+
instance_type = "m1.small"
305390
subnet_id = "${aws_subnet.sub.id}"
306391
}
307392
resource "aws_eip" "bar" {
@@ -319,7 +404,9 @@ provider "aws" {
319404
320405
resource "aws_eip" "test" {}
321406
322-
data "aws_availability_zones" "available" {}
407+
data "aws_availability_zones" "available" {
408+
state = "available"
409+
}
323410
324411
data "aws_ami" "ubuntu" {
325412
most_recent = true

0 commit comments

Comments
 (0)