Merge pull request #172 from deoxxa/add-vpc-dns-attributes
add vpc dns attribute support
This commit is contained in:
commit
33a7d32f40
|
@ -3,6 +3,7 @@ package aws
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/diff"
|
"github.com/hashicorp/terraform/helper/diff"
|
||||||
|
@ -53,6 +54,36 @@ func resource_aws_vpc_create(
|
||||||
s.ID, err)
|
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
|
// Update our attributes and return
|
||||||
return resource_aws_vpc_update_state(s, vpcRaw.(*ec2.VPC))
|
return resource_aws_vpc_update_state(s, vpcRaw.(*ec2.VPC))
|
||||||
}
|
}
|
||||||
|
@ -61,11 +92,43 @@ func resource_aws_vpc_update(
|
||||||
s *terraform.ResourceState,
|
s *terraform.ResourceState,
|
||||||
d *terraform.ResourceDiff,
|
d *terraform.ResourceDiff,
|
||||||
meta interface{}) (*terraform.ResourceState, error) {
|
meta interface{}) (*terraform.ResourceState, error) {
|
||||||
// This should never be called because we have no update-able
|
p := meta.(*ResourceProvider)
|
||||||
// attributes
|
ec2conn := p.ec2conn
|
||||||
panic("Update for VPC is not supported")
|
rs := s.MergeDiff(d)
|
||||||
|
|
||||||
return nil, nil
|
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)
|
||||||
|
|
||||||
|
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(
|
func resource_aws_vpc_destroy(
|
||||||
|
@ -101,8 +164,19 @@ func resource_aws_vpc_refresh(
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
vpc := vpcRaw.(*ec2.VPC)
|
if dnsSupportResp, err := ec2conn.VpcAttribute(s.ID, "enableDnsSupport"); err != nil {
|
||||||
return resource_aws_vpc_update_state(s, vpc)
|
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(
|
func resource_aws_vpc_diff(
|
||||||
|
@ -111,7 +185,14 @@ func resource_aws_vpc_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{
|
||||||
"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",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@ func init() {
|
||||||
Destroy: resource_aws_vpc_destroy,
|
Destroy: resource_aws_vpc_destroy,
|
||||||
Diff: resource_aws_vpc_diff,
|
Diff: resource_aws_vpc_diff,
|
||||||
Refresh: resource_aws_vpc_refresh,
|
Refresh: resource_aws_vpc_refresh,
|
||||||
|
Update: resource_aws_vpc_update,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ resource "aws_vpc" "main" {
|
||||||
The following arguments are supported:
|
The following arguments are supported:
|
||||||
|
|
||||||
* `cidr_block` - (Required) The CIDR block for the VPC.
|
* `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
|
## Attributes Reference
|
||||||
|
|
||||||
|
@ -28,4 +30,6 @@ The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The ID of the VPC
|
* `id` - The ID of the VPC
|
||||||
* `cidr_block` - The CIDR block 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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue