providers/aws/aws_instance: test modifying source_dest_check

This commit is contained in:
Mitchell Hashimoto 2014-07-14 17:38:39 -07:00
parent 0a6b7a9301
commit 735c909264
2 changed files with 40 additions and 6 deletions

View File

@ -89,6 +89,7 @@ func resource_aws_instance_update(
if attr, ok := d.Attributes["source_dest_check"]; ok {
modify = true
opts.SourceDestCheck = attr.New != "" && attr.New != "false"
opts.SetSourceDestCheck = true
rs.Attributes["source_dest_check"] = strconv.FormatBool(
opts.SourceDestCheck)
}
@ -98,6 +99,9 @@ func resource_aws_instance_update(
if _, err := ec2conn.ModifyInstance(s.ID, opts); err != nil {
return s, err
}
// TODO(mitchellh): wait for the attributes we modified to
// persist the change...
}
return rs, nil

View File

@ -31,13 +31,15 @@ func TestAccAWSInstance(t *testing.T) {
func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
var v ec2.Instance
testCheck := func(*terraform.State) error {
if !v.SourceDestCheck {
return fmt.Errorf("no source_dest_check")
testCheck := func(enabled bool) resource.TestCheckFunc {
return func(*terraform.State) error {
if v.SourceDestCheck != enabled {
return fmt.Errorf("bad source_dest_check: %#v", v.SourceDestCheck)
}
return nil
}
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
@ -49,7 +51,16 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(
"aws_instance.foo", &v),
testCheck,
testCheck(true),
),
},
resource.TestStep{
Config: testAccInstanceConfigSourceDestDisable,
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(
"aws_instance.foo", &v),
testCheck(false),
),
},
},
@ -161,6 +172,25 @@ resource "aws_instance" "foo" {
}
`
const testAccInstanceConfigSourceDestDisable = `
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" {
# us-west-2
ami = "ami-4fccb37f"
instance_type = "m1.small"
subnet_id = "${aws_subnet.foo.id}"
source_dest_check = false
}
`
const testAccInstanceConfigVPC = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"