Don't error when enabling DNS hostnames in a VPC

The AWS API call ModifyVpcAttribute will allow only one attribute to be
modified at a time. Modifying both results in the error:

    Fields for multiple attribute types specified: enableDnsHostnames, enableDnsSupport

Retructure the provider to honor this restriction.

Also, enable DNS support before attempting to enable DNS hostnames,
since the former is a prerequisite of the latter.

Additionally, fix what must have been a copy&paste error, setting
enable_dns_support to the value of enable_dns_hostnames.
This commit is contained in:
Phil Frost 2015-03-20 14:44:42 -04:00
parent 9545f26fa0
commit b49fba6b61
1 changed files with 25 additions and 21 deletions

View File

@ -185,29 +185,14 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
// Turn on partial mode // Turn on partial mode
d.Partial(true) d.Partial(true)
vpcid := d.Id() vpcid := d.Id()
modifyOpts := &ec2.ModifyVPCAttributeRequest{
VPCID: &vpcid,
}
if d.HasChange("enable_dns_hostnames") {
val := d.Get("enable_dns_hostnames").(bool)
modifyOpts.EnableDNSHostnames = &ec2.AttributeBooleanValue{
Value: &val,
}
log.Printf(
"[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v",
d.Id(), modifyOpts)
if err := ec2conn.ModifyVPCAttribute(modifyOpts); err != nil {
return err
}
d.SetPartial("enable_dns_hostnames")
}
if d.HasChange("enable_dns_support") { if d.HasChange("enable_dns_support") {
val := d.Get("enable_dns_hostnames").(bool) val := d.Get("enable_dns_support").(bool)
modifyOpts.EnableDNSSupport = &ec2.AttributeBooleanValue{ modifyOpts := &ec2.ModifyVPCAttributeRequest{
Value: &val, VPCID: &vpcid,
EnableDNSSupport: &ec2.AttributeBooleanValue{
Value: &val,
},
} }
log.Printf( log.Printf(
@ -220,6 +205,25 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("enable_dns_support") d.SetPartial("enable_dns_support")
} }
if d.HasChange("enable_dns_hostnames") {
val := d.Get("enable_dns_hostnames").(bool)
modifyOpts := &ec2.ModifyVPCAttributeRequest{
VPCID: &vpcid,
EnableDNSHostnames: &ec2.AttributeBooleanValue{
Value: &val,
},
}
log.Printf(
"[INFO] Modifying enable_dns_hostnames vpc attribute for %s: %#v",
d.Id(), modifyOpts)
if err := ec2conn.ModifyVPCAttribute(modifyOpts); err != nil {
return err
}
d.SetPartial("enable_dns_hostnames")
}
if err := setTags(ec2conn, d); err != nil { if err := setTags(ec2conn, d); err != nil {
return err return err
} else { } else {