Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add associate_public_ip_address as an attribute on the aws_instance resource #85

Merged
merged 2 commits into from
Jul 29, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ func resource_aws_instance_create(
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
runOpts := &ec2.RunInstances{
ImageId: rs.Attributes["ami"],
InstanceType: rs.Attributes["instance_type"],
KeyName: rs.Attributes["key_name"],
SubnetId: rs.Attributes["subnet_id"],
UserData: []byte(userData),
ImageId: rs.Attributes["ami"],
InstanceType: rs.Attributes["instance_type"],
KeyName: rs.Attributes["key_name"],
SubnetId: rs.Attributes["subnet_id"],
AssociatePublicIpAddress: associatePublicIPAddress,
UserData: []byte(userData),
}
if raw := flatmap.Expand(rs.Attributes, "security_groups"); raw != nil {
if sgs, ok := raw.([]interface{}); ok {
Expand Down Expand Up @@ -187,14 +193,15 @@ func resource_aws_instance_diff(
meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
"ami": diff.AttrTypeCreate,
"availability_zone": diff.AttrTypeCreate,
"instance_type": diff.AttrTypeCreate,
"key_name": diff.AttrTypeCreate,
"security_groups": diff.AttrTypeCreate,
"subnet_id": diff.AttrTypeCreate,
"source_dest_check": diff.AttrTypeUpdate,
"user_data": diff.AttrTypeCreate,
"ami": diff.AttrTypeCreate,
"availability_zone": diff.AttrTypeCreate,
"instance_type": diff.AttrTypeCreate,
"key_name": diff.AttrTypeCreate,
"security_groups": diff.AttrTypeCreate,
"subnet_id": diff.AttrTypeCreate,
"source_dest_check": diff.AttrTypeUpdate,
"user_data": diff.AttrTypeCreate,
"associate_public_ip_address": diff.AttrTypeCreate,
},

ComputedAttrs: []string{
Expand Down
1 change: 1 addition & 0 deletions builtin/providers/aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,6 @@ resource "aws_instance" "foo" {
ami = "ami-4fccb37f"
instance_type = "m1.small"
subnet_id = "${aws_subnet.foo.id}"
associate_public_ip_address = true
}
`
2 changes: 1 addition & 1 deletion website/source/docs/providers/aws/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The following arguments are supported:
If you are within a VPC, you'll need to use the security group ID. Otherwise,
for EC2, use the security group name.
* `subnet_id` - (Optional) The VPC Subnet ID to launch in.
* `associate_public_ip_address` - (Optional) Associate a public ip address with an instance in a VPC.
* `source_dest_check` - (Optional) Controls if traffic is routed to the instance when
the destination address does not match the instance. Used for NAT or VPNs. Defaults false.
* `user_data` - (Optional) The user data to provide when launching the instance.
Expand All @@ -48,4 +49,3 @@ The following attributes are exported:
* `public_ip` - The public IP address.
* `security_groups` - The associated security groups.
* `subnet_id` - The VPC subnet ID.