Skip to content

Commit

Permalink
Merge pull request #1021 from hashicorp/b-aws-instance-source-dest-ch…
Browse files Browse the repository at this point in the history
…eck-on-create

providers/aws: fix source_dest_check on instance creation
  • Loading branch information
mitchellh committed Feb 23, 2015
2 parents f6249ff + 473b03c commit 84b1db4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
23 changes: 8 additions & 15 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,26 +487,19 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {

func resourceAwsInstanceUpdate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn

modify := false
opts := new(ec2.ModifyInstance)

if d.HasChange("source_dest_check") {
opts.SetSourceDestCheck = true
opts.SourceDestCheck = d.Get("source_dest_check").(bool)
modify = true
}
opts.SetSourceDestCheck = true
opts.SourceDestCheck = d.Get("source_dest_check").(bool)

if modify {
log.Printf("[INFO] Modifying instance %s: %#v", d.Id(), opts)
if _, err := ec2conn.ModifyInstance(d.Id(), opts); err != nil {
return err
}

// TODO(mitchellh): wait for the attributes we modified to
// persist the change...
log.Printf("[INFO] Modifying instance %s: %#v", d.Id(), opts)
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 {
return err
} else {
Expand Down
18 changes: 12 additions & 6 deletions builtin/providers/aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,25 @@ func TestAccAWSInstance_sourceDestCheck(t *testing.T) {
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccInstanceConfigSourceDest,
Config: testAccInstanceConfigSourceDestDisable,
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(
"aws_instance.foo", &v),
testAccCheckInstanceExists("aws_instance.foo", &v),
testCheck(false),
),
},

resource.TestStep{
Config: testAccInstanceConfigSourceDestEnable,
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists("aws_instance.foo", &v),
testCheck(true),
),
},

resource.TestStep{
Config: testAccInstanceConfigSourceDestDisable,
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(
"aws_instance.foo", &v),
testAccCheckInstanceExists("aws_instance.foo", &v),
testCheck(false),
),
},
Expand Down Expand Up @@ -388,7 +394,7 @@ resource "aws_instance" "foo" {
}
`

const testAccInstanceConfigSourceDest = `
const testAccInstanceConfigSourceDestEnable = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
Expand Down

0 comments on commit 84b1db4

Please sign in to comment.