Merge pull request #701 from ceh/issue-687
builtin/providers/aws: acceptance tests for assigning private IPs on AWS instance
This commit is contained in:
commit
11dc775c25
|
@ -2,8 +2,8 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
@ -190,6 +190,64 @@ func TestAccInstance_tags(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccInstance_privateIP(t *testing.T) {
|
||||
var v ec2.Instance
|
||||
|
||||
testCheckPrivateIP := func() resource.TestCheckFunc {
|
||||
return func(*terraform.State) error {
|
||||
if v.PrivateIpAddress != "10.1.1.42" {
|
||||
return fmt.Errorf("bad private IP: %s", v.PrivateIpAddress)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigPrivateIP,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceExists("aws_instance.foo", &v),
|
||||
testCheckPrivateIP(),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccInstance_associatePublicIPAndPrivateIP(t *testing.T) {
|
||||
var v ec2.Instance
|
||||
|
||||
testCheckPrivateIP := func() resource.TestCheckFunc {
|
||||
return func(*terraform.State) error {
|
||||
if v.PrivateIpAddress != "10.1.1.42" {
|
||||
return fmt.Errorf("bad private IP: %s", v.PrivateIpAddress)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigAssociatePublicIPAndPrivateIP,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceExists("aws_instance.foo", &v),
|
||||
testCheckPrivateIP(),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccCheckInstanceDestroy(s *terraform.State) error {
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
|
||||
|
@ -379,3 +437,40 @@ resource "aws_instance" "foo" {
|
|||
}
|
||||
}
|
||||
`
|
||||
|
||||
const testAccInstanceConfigPrivateIP = `
|
||||
resource "aws_vpc" "foo" {
|
||||
cidr_block = "10.1.0.0/16"
|
||||
}
|
||||
|
||||
resource "aws_subnet" "foo" {
|
||||
cidr_block = "10.1.1.0/24"
|
||||
vpc_id = "${aws_vpc.foo.id}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
ami = "ami-c5eabbf5"
|
||||
instance_type = "t2.micro"
|
||||
subnet_id = "${aws_subnet.foo.id}"
|
||||
private_ip = "10.1.1.42"
|
||||
}
|
||||
`
|
||||
|
||||
const testAccInstanceConfigAssociatePublicIPAndPrivateIP = `
|
||||
resource "aws_vpc" "foo" {
|
||||
cidr_block = "10.1.0.0/16"
|
||||
}
|
||||
|
||||
resource "aws_subnet" "foo" {
|
||||
cidr_block = "10.1.1.0/24"
|
||||
vpc_id = "${aws_vpc.foo.id}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "foo" {
|
||||
ami = "ami-c5eabbf5"
|
||||
instance_type = "t2.micro"
|
||||
subnet_id = "${aws_subnet.foo.id}"
|
||||
associate_public_ip_address = true
|
||||
private_ip = "10.1.1.42"
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue