Merge pull request #85 from vertis/aws_associate_public_ip_address
Add associate_public_ip_address as an attribute on the aws_instance resource
This commit is contained in:
commit
fa13a12a6e
|
@ -34,13 +34,19 @@ 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"],
|
||||||
UserData: []byte(userData),
|
AssociatePublicIpAddress: associatePublicIPAddress,
|
||||||
|
UserData: []byte(userData),
|
||||||
}
|
}
|
||||||
if raw := flatmap.Expand(rs.Attributes, "security_groups"); raw != nil {
|
if raw := flatmap.Expand(rs.Attributes, "security_groups"); raw != nil {
|
||||||
if sgs, ok := raw.([]interface{}); ok {
|
if sgs, ok := raw.([]interface{}); ok {
|
||||||
|
@ -187,14 +193,15 @@ func resource_aws_instance_diff(
|
||||||
meta interface{}) (*terraform.ResourceDiff, error) {
|
meta interface{}) (*terraform.ResourceDiff, error) {
|
||||||
b := &diff.ResourceBuilder{
|
b := &diff.ResourceBuilder{
|
||||||
Attrs: map[string]diff.AttrType{
|
Attrs: map[string]diff.AttrType{
|
||||||
"ami": diff.AttrTypeCreate,
|
"ami": diff.AttrTypeCreate,
|
||||||
"availability_zone": diff.AttrTypeCreate,
|
"availability_zone": diff.AttrTypeCreate,
|
||||||
"instance_type": diff.AttrTypeCreate,
|
"instance_type": diff.AttrTypeCreate,
|
||||||
"key_name": diff.AttrTypeCreate,
|
"key_name": diff.AttrTypeCreate,
|
||||||
"security_groups": diff.AttrTypeCreate,
|
"security_groups": diff.AttrTypeCreate,
|
||||||
"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{
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
|
@ -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,
|
If you are within a VPC, you'll need to use the security group ID. Otherwise,
|
||||||
for EC2, use the security group name.
|
for EC2, use the security group name.
|
||||||
* `subnet_id` - (Optional) The VPC Subnet ID to launch in.
|
* `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
|
* `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.
|
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.
|
* `user_data` - (Optional) The user data to provide when launching the instance.
|
||||||
|
@ -48,4 +49,3 @@ The following attributes are exported:
|
||||||
* `public_ip` - The public IP address.
|
* `public_ip` - The public IP address.
|
||||||
* `security_groups` - The associated security groups.
|
* `security_groups` - The associated security groups.
|
||||||
* `subnet_id` - The VPC subnet ID.
|
* `subnet_id` - The VPC subnet ID.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue