Add associate_public_ip_address as an attribute of the aws_instance resource

This commit is contained in:
Luke Chadwick 2014-07-29 22:06:53 +10:00
parent 44489d2dfe
commit 974074fee9
2 changed files with 21 additions and 13 deletions

View File

@ -34,12 +34,18 @@ func resource_aws_instance_create(
userData = attr.NewExtra.(string) userData = attr.NewExtra.(string)
} }
associatePublicIPAddress := false
if attr, ok := d.Attributes["associate_public_ip_address"]; ok {
associatePublicIPAddress = attr.New != "" && attr.New != "false"
}
// Build the creation struct // Build the creation struct
runOpts := &ec2.RunInstances{ runOpts := &ec2.RunInstances{
ImageId: rs.Attributes["ami"], ImageId: rs.Attributes["ami"],
InstanceType: rs.Attributes["instance_type"], InstanceType: rs.Attributes["instance_type"],
KeyName: rs.Attributes["key_name"], KeyName: rs.Attributes["key_name"],
SubnetId: rs.Attributes["subnet_id"], SubnetId: rs.Attributes["subnet_id"],
AssociatePublicIpAddress: associatePublicIPAddress,
UserData: []byte(userData), UserData: []byte(userData),
} }
if raw := flatmap.Expand(rs.Attributes, "security_groups"); raw != nil { if raw := flatmap.Expand(rs.Attributes, "security_groups"); raw != nil {
@ -195,6 +201,7 @@ func resource_aws_instance_diff(
"subnet_id": diff.AttrTypeCreate, "subnet_id": diff.AttrTypeCreate,
"source_dest_check": diff.AttrTypeUpdate, "source_dest_check": diff.AttrTypeUpdate,
"user_data": diff.AttrTypeCreate, "user_data": diff.AttrTypeCreate,
"associate_public_ip_address": diff.AttrTypeCreate,
}, },
ComputedAttrs: []string{ ComputedAttrs: []string{

View File

@ -252,5 +252,6 @@ resource "aws_instance" "foo" {
ami = "ami-4fccb37f" ami = "ami-4fccb37f"
instance_type = "m1.small" instance_type = "m1.small"
subnet_id = "${aws_subnet.foo.id}" subnet_id = "${aws_subnet.foo.id}"
associate_public_ip_address = true
} }
` `