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 MapPublicIpOnLaunch #285

Merged
merged 1 commit into from
Sep 16, 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
26 changes: 23 additions & 3 deletions builtin/providers/aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ func resource_aws_subnet_create(
s.ID, err)
}

var attr string

// Map public ip on launch must be set in another API call
if attr = s.Attributes["map_public_ip_on_launch"]; attr == "true" {
modifyOpts := &ec2.ModifySubnetAttribute{
SubnetId: s.ID,
MapPublicIpOnLaunch: true,
}
log.Printf("[DEBUG] Subnet modify attributes: %#v", modifyOpts)
_, err := ec2conn.ModifySubnetAttribute(modifyOpts)
if err != nil {
return nil, fmt.Errorf("Error modify subnet attributes: %s", err)
}
}

// Update our attributes and return
return resource_aws_subnet_update_state(s, subnetRaw.(*ec2.Subnet))
}
Expand Down Expand Up @@ -125,9 +140,10 @@ func resource_aws_subnet_diff(
meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
"availability_zone": diff.AttrTypeCreate,
"cidr_block": diff.AttrTypeCreate,
"vpc_id": diff.AttrTypeCreate,
"availability_zone": diff.AttrTypeCreate,
"cidr_block": diff.AttrTypeCreate,
"vpc_id": diff.AttrTypeCreate,
"map_public_ip_on_launch": diff.AttrTypeCreate,
},

ComputedAttrs: []string{
Expand All @@ -145,6 +161,10 @@ func resource_aws_subnet_update_state(
s.Attributes["cidr_block"] = subnet.CidrBlock
s.Attributes["vpc_id"] = subnet.VpcId

if subnet.MapPublicIpOnLaunch {
s.Attributes["map_public_ip_on_launch"] = "true"
}

// We belong to a VPC
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: subnet.VpcId},
Expand Down
5 changes: 5 additions & 0 deletions builtin/providers/aws/resource_aws_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func TestAccAWSSubnet(t *testing.T) {
return fmt.Errorf("bad cidr: %s", v.CidrBlock)
}

if v.MapPublicIpOnLaunch != true {
return fmt.Errorf("bad MapPublicIpOnLaunch: %s", v.MapPublicIpOnLaunch)
}
return fmt.Errorf("bad MapPublicIpOnLaunch: %s", v.MapPublicIpOnLaunch)
return nil
}

Expand Down Expand Up @@ -104,5 +108,6 @@ resource "aws_vpc" "foo" {
resource "aws_subnet" "foo" {
cidr_block = "10.1.1.0/24"
vpc_id = "${aws_vpc.foo.id}"
map_public_ip_on_launch = true
}
`