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 vpc dns attribute support #172

Merged
merged 1 commit into from
Aug 20, 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
95 changes: 88 additions & 7 deletions builtin/providers/aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"fmt"
"log"
"strconv"
"time"

"github.com/hashicorp/terraform/helper/diff"
Expand Down Expand Up @@ -53,6 +54,36 @@ func resource_aws_vpc_create(
s.ID, err)
}

if attr, ok := d.Attributes["enable_dns_support"]; ok {
options := new(ec2.ModifyVpcAttribute)

options.EnableDnsSupport = attr.New != "" && attr.New != "false"
options.SetEnableDnsSupport = true

s.Attributes["enable_dns_support"] = strconv.FormatBool(options.EnableDnsSupport)

log.Printf("[INFO] Modifying vpc attributes for %s: %#v", s.ID, options)

if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil {
return s, err
}
}

if attr, ok := d.Attributes["enable_dns_hostnames"]; ok {
options := new(ec2.ModifyVpcAttribute)

options.EnableDnsHostnames = attr.New != "" && attr.New != "false"
options.SetEnableDnsHostnames = true

s.Attributes["enable_dns_hostnames"] = strconv.FormatBool(options.EnableDnsHostnames)

log.Printf("[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v", s.ID, options)

if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil {
return s, err
}
}

// Update our attributes and return
return resource_aws_vpc_update_state(s, vpcRaw.(*ec2.VPC))
}
Expand All @@ -61,11 +92,43 @@ func resource_aws_vpc_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
// This should never be called because we have no update-able
// attributes
panic("Update for VPC is not supported")
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
rs := s.MergeDiff(d)

log.Printf("[DEBUG] attributes: %#v", d.Attributes)

if attr, ok := d.Attributes["enable_dns_support"]; ok {
options := new(ec2.ModifyVpcAttribute)

options.EnableDnsSupport = attr.New != "" && attr.New != "false"
options.SetEnableDnsSupport = true

rs.Attributes["enable_dns_support"] = strconv.FormatBool(options.EnableDnsSupport)

return nil, nil
log.Printf("[INFO] Modifying enable_dns_support vpc attribute for %s: %#v", s.ID, options)

if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil {
return s, err
}
}

if attr, ok := d.Attributes["enable_dns_hostnames"]; ok {
options := new(ec2.ModifyVpcAttribute)

options.EnableDnsHostnames = attr.New != "" && attr.New != "false"
options.SetEnableDnsHostnames = true

rs.Attributes["enable_dns_hostnames"] = strconv.FormatBool(options.EnableDnsHostnames)

log.Printf("[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v", s.ID, options)

if _, err := ec2conn.ModifyVpcAttribute(s.ID, options); err != nil {
return s, err
}
}

return rs, nil
}

func resource_aws_vpc_destroy(
Expand Down Expand Up @@ -101,8 +164,19 @@ func resource_aws_vpc_refresh(
return nil, nil
}

vpc := vpcRaw.(*ec2.VPC)
return resource_aws_vpc_update_state(s, vpc)
if dnsSupportResp, err := ec2conn.VpcAttribute(s.ID, "enableDnsSupport"); err != nil {
return s, err
} else {
s.Attributes["enable_dns_support"] = strconv.FormatBool(dnsSupportResp.EnableDnsSupport)
}

if dnsHostnamesResp, err := ec2conn.VpcAttribute(s.ID, "enableDnsHostnames"); err != nil {
return s, err
} else {
s.Attributes["enable_dns_hostnames"] = strconv.FormatBool(dnsHostnamesResp.EnableDnsHostnames)
}

return resource_aws_vpc_update_state(s, vpcRaw.(*ec2.VPC))
}

func resource_aws_vpc_diff(
Expand All @@ -111,7 +185,14 @@ func resource_aws_vpc_diff(
meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
"cidr_block": diff.AttrTypeCreate,
"cidr_block": diff.AttrTypeCreate,
"enable_dns_support": diff.AttrTypeUpdate,
"enable_dns_hostnames": diff.AttrTypeUpdate,
},

ComputedAttrs: []string{
"enable_dns_support",
"enable_dns_hostnames",
},
}

Expand Down
1 change: 1 addition & 0 deletions builtin/providers/aws/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func init() {
Destroy: resource_aws_vpc_destroy,
Diff: resource_aws_vpc_diff,
Refresh: resource_aws_vpc_refresh,
Update: resource_aws_vpc_update,
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions website/source/docs/providers/aws/r/vpc.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ resource "aws_vpc" "main" {
The following arguments are supported:

* `cidr_block` - (Required) The CIDR block for the VPC.
* `enable_dns_support` - (Optional) A boolean flag to enable/disable DNS support in the VPC. Defaults true.
* `enable_dns_hostnames` - (Optional) A boolean flag to enable/disable DNS hostnames in the VPC. Defaults false.

## Attributes Reference

The following attributes are exported:

* `id` - The ID of the VPC
* `cidr_block` - The CIDR block of the VPC
* `enable_dns_support` - Whether or not the VPC has DNS support
* `enable_dns_hostnames` - Whether or not the VPC has DNS hostname support