Merge pull request #1021 from hashicorp/b-aws-instance-source-dest-check-on-create

providers/aws: fix source_dest_check on instance creation
This commit is contained in:
Mitchell Hashimoto 2015-02-23 13:45:17 -08:00
commit 84b1db4505
2 changed files with 20 additions and 21 deletions

View File

@ -487,25 +487,18 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error { func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn ec2conn := meta.(*AWSClient).ec2conn
modify := false
opts := new(ec2.ModifyInstance) opts := new(ec2.ModifyInstance)
if d.HasChange("source_dest_check") { opts.SetSourceDestCheck = true
opts.SetSourceDestCheck = true opts.SourceDestCheck = d.Get("source_dest_check").(bool)
opts.SourceDestCheck = d.Get("source_dest_check").(bool)
modify = true log.Printf("[INFO] Modifying instance %s: %#v", d.Id(), opts)
if _, err := ec2conn.ModifyInstance(d.Id(), opts); err != nil {
return err
} }
if modify { // TODO(mitchellh): wait for the attributes we modified to
log.Printf("[INFO] Modifying instance %s: %#v", d.Id(), opts) // persist the change...
if _, err := ec2conn.ModifyInstance(d.Id(), opts); err != nil {
return err
}
// TODO(mitchellh): wait for the attributes we modified to
// persist the change...
}
if err := setTags(ec2conn, d); err != nil { if err := setTags(ec2conn, d); err != nil {
return err return err

View File

@ -145,10 +145,17 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
CheckDestroy: testAccCheckInstanceDestroy, CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccInstanceConfigSourceDest, Config: testAccInstanceConfigSourceDestDisable,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists( testAccCheckInstanceExists("aws_instance.foo", &v),
"aws_instance.foo", &v), testCheck(false),
),
},
resource.TestStep{
Config: testAccInstanceConfigSourceDestEnable,
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists("aws_instance.foo", &v),
testCheck(true), testCheck(true),
), ),
}, },
@ -156,8 +163,7 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
resource.TestStep{ resource.TestStep{
Config: testAccInstanceConfigSourceDestDisable, Config: testAccInstanceConfigSourceDestDisable,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists( testAccCheckInstanceExists("aws_instance.foo", &v),
"aws_instance.foo", &v),
testCheck(false), testCheck(false),
), ),
}, },
@ -388,7 +394,7 @@ resource "aws_instance" "foo" {
} }
` `
const testAccInstanceConfigSourceDest = ` const testAccInstanceConfigSourceDestEnable = `
resource "aws_vpc" "foo" { resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16" cidr_block = "10.1.0.0/16"
} }