providers/aws: test internet gateway changing the VPC addr

This commit is contained in:
Mitchell Hashimoto 2014-07-10 14:51:23 -07:00
parent 9ab4a5bf88
commit 86c4678bee
1 changed files with 42 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package aws
import (
"fmt"
"log"
"testing"
"github.com/hashicorp/terraform/helper/resource"
@ -10,7 +11,24 @@ import (
)
func TestAccAWSInternetGateway(t *testing.T) {
var v ec2.InternetGateway
var v, v2 ec2.InternetGateway
testNotEqual := func(*terraform.State) error {
if len(v.Attachments) == 0 {
return fmt.Errorf("IG A is not attached")
}
if len(v2.Attachments) == 0 {
return fmt.Errorf("IG B is not attached")
}
id1 := v.Attachments[0].VpcId
id2 := v2.Attachments[0].VpcId
if id1 == id2 {
return fmt.Errorf("Both attachment IDs are the same")
}
return nil
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -24,6 +42,15 @@ func TestAccAWSInternetGateway(t *testing.T) {
"aws_internet_gateway.foo", &v),
),
},
resource.TestStep{
Config: testAccInternetGatewayConfigChangeVPC,
Check: resource.ComposeTestCheckFunc(
testAccCheckInternetGatewayExists(
"aws_internet_gateway.foo", &v2),
testNotEqual,
),
},
},
})
}
@ -96,3 +123,17 @@ resource "aws_internet_gateway" "foo" {
vpc_id = "${aws_vpc.foo.id}"
}
`
const testAccInternetGatewayConfigChangeVPC = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_vpc" "bar" {
cidr_block = "10.2.0.0/16"
}
resource "aws_internet_gateway" "foo" {
vpc_id = "${aws_vpc.bar.id}"
}
`