Merge pull request #9009 from hashicorp/tests-aws-import-eip

provider/aws: Add some tests for the Import for aws_eip
This commit is contained in:
Paul Stack 2016-10-07 16:25:41 +01:00 committed by GitHub
commit 181fd25ee4
2 changed files with 63 additions and 3 deletions

View File

@ -29,6 +29,7 @@ func resourceAwsEip() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Computed: true,
},
"instance": &schema.Schema{
@ -168,7 +169,7 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
// On import (domain never set, which it must've been if we created),
// set the 'vpc' attribute depending on if we're in a VPC.
if _, ok := d.GetOk("domain"); !ok {
if address.Domain != nil {
d.Set("vpc", *address.Domain == "vpc")
}

View File

@ -2,6 +2,7 @@ package aws
import (
"fmt"
"os"
"strings"
"testing"
@ -12,6 +13,50 @@ import (
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSEIP_importEc2Classic(t *testing.T) {
oldvar := os.Getenv("AWS_DEFAULT_REGION")
os.Setenv("AWS_DEFAULT_REGION", "us-east-1")
defer os.Setenv("AWS_DEFAULT_REGION", oldvar)
resourceName := "aws_eip.bar"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEIPDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEIPInstanceEc2Classic,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccAWSEIP_importVpc(t *testing.T) {
resourceName := "aws_eip.bar"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEIPDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEIPNetworkInterfaceConfig,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccAWSEIP_basic(t *testing.T) {
var conf ec2.Address
@ -152,7 +197,7 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error {
describe, err := conn.DescribeAddresses(req)
if err != nil {
// Verify the error is what we want
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidAllocationID.NotFound" {
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidAllocationID.NotFound" || ae.Code() == "InvalidAddress.NotFound" {
continue
}
return err
@ -168,7 +213,7 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error {
describe, err := conn.DescribeAddresses(req)
if err != nil {
// Verify the error is what we want
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidAllocationID.NotFound" {
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidAllocationID.NotFound" || ae.Code() == "InvalidAddress.NotFound" {
continue
}
return err
@ -256,6 +301,20 @@ resource "aws_eip" "bar" {
}
`
const testAccAWSEIPInstanceEc2Classic = `
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "foo" {
ami = "ami-5469ae3c"
instance_type = "m1.small"
}
resource "aws_eip" "bar" {
instance = "${aws_instance.foo.id}"
}
`
const testAccAWSEIPInstanceConfig = `
resource "aws_instance" "foo" {
# us-west-2