providers/aws/aws_instance: source_dest_check support
This commit is contained in:
parent
88dd1baafe
commit
2fa6ca1c4e
|
@ -3,6 +3,7 @@ package aws
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/diff"
|
||||
|
@ -21,6 +22,7 @@ func resource_aws_instance_create(
|
|||
// Merge the diff into the state so that we have all the attributes
|
||||
// properly.
|
||||
rs := s.MergeDiff(d)
|
||||
delete(rs.Attributes, "source_dest_check")
|
||||
|
||||
// Create the instance
|
||||
runOpts := &ec2.RunInstances{
|
||||
|
@ -64,7 +66,41 @@ func resource_aws_instance_create(
|
|||
instance = instanceRaw.(*ec2.Instance)
|
||||
|
||||
// Set our attributes
|
||||
return resource_aws_instance_update_state(rs, instance)
|
||||
rs, err = resource_aws_instance_update_state(rs, instance)
|
||||
if err != nil {
|
||||
return rs, err
|
||||
}
|
||||
|
||||
// Update if we need to
|
||||
return resource_aws_instance_update(rs, d, meta)
|
||||
}
|
||||
|
||||
func resource_aws_instance_update(
|
||||
s *terraform.ResourceState,
|
||||
d *terraform.ResourceDiff,
|
||||
meta interface{}) (*terraform.ResourceState, error) {
|
||||
p := meta.(*ResourceProvider)
|
||||
ec2conn := p.ec2conn
|
||||
rs := s.MergeDiff(d)
|
||||
|
||||
modify := false
|
||||
opts := new(ec2.ModifyInstance)
|
||||
|
||||
if attr, ok := d.Attributes["source_dest_check"]; ok {
|
||||
modify = true
|
||||
opts.SourceDestCheck = attr.New != "" && attr.New != "false"
|
||||
rs.Attributes["source_dest_check"] = strconv.FormatBool(
|
||||
opts.SourceDestCheck)
|
||||
}
|
||||
|
||||
if modify {
|
||||
log.Printf("[INFO] Modifing instance %s: %#v", s.ID, opts)
|
||||
if _, err := ec2conn.ModifyInstance(s.ID, opts); err != nil {
|
||||
return s, err
|
||||
}
|
||||
}
|
||||
|
||||
return rs, nil
|
||||
}
|
||||
|
||||
func resource_aws_instance_destroy(
|
||||
|
@ -110,6 +146,7 @@ func resource_aws_instance_diff(
|
|||
"availability_zone": diff.AttrTypeCreate,
|
||||
"instance_type": diff.AttrTypeCreate,
|
||||
"subnet_id": diff.AttrTypeCreate,
|
||||
"source_dest_check": diff.AttrTypeUpdate,
|
||||
},
|
||||
|
||||
ComputedAttrs: []string{
|
||||
|
|
|
@ -28,6 +28,34 @@ 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")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccInstanceConfigSourceDest,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckInstanceExists(
|
||||
"aws_instance.foo", &v),
|
||||
testCheck,
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccAWSInstance_vpc(t *testing.T) {
|
||||
var v ec2.Instance
|
||||
|
||||
|
@ -114,6 +142,25 @@ resource "aws_instance" "foo" {
|
|||
}
|
||||
`
|
||||
|
||||
const testAccInstanceConfigSourceDest = `
|
||||
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 = true
|
||||
}
|
||||
`
|
||||
|
||||
const testAccInstanceConfigVPC = `
|
||||
resource "aws_vpc" "foo" {
|
||||
cidr_block = "10.1.0.0/16"
|
||||
|
|
|
@ -39,6 +39,7 @@ func init() {
|
|||
Destroy: resource_aws_instance_destroy,
|
||||
Diff: resource_aws_instance_diff,
|
||||
Refresh: resource_aws_instance_refresh,
|
||||
Update: resource_aws_instance_update,
|
||||
},
|
||||
|
||||
"aws_internet_gateway": resource.Resource{
|
||||
|
|
Loading…
Reference in New Issue