provider/aws: Fixed the aws_vpc enable_dns_support handling on creation

This commit is contained in:
Ninir 2016-11-16 20:05:49 +01:00
parent e7411891f4
commit 281eba72ad
2 changed files with 51 additions and 19 deletions

View File

@ -23,59 +23,59 @@ func resourceAwsVpc() *schema.Resource {
}, },
Schema: map[string]*schema.Schema{ Schema: map[string]*schema.Schema{
"cidr_block": &schema.Schema{ "cidr_block": {
Type: schema.TypeString, Type: schema.TypeString,
Required: true, Required: true,
ForceNew: true, ForceNew: true,
ValidateFunc: validateCIDRNetworkAddress, ValidateFunc: validateCIDRNetworkAddress,
}, },
"instance_tenancy": &schema.Schema{ "instance_tenancy": {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ForceNew: true, ForceNew: true,
Computed: true, Computed: true,
}, },
"enable_dns_hostnames": &schema.Schema{ "enable_dns_hostnames": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"enable_dns_support": &schema.Schema{ "enable_dns_support": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"enable_classiclink": &schema.Schema{ "enable_classiclink": {
Type: schema.TypeBool, Type: schema.TypeBool,
Optional: true, Optional: true,
Computed: true, Computed: true,
}, },
"main_route_table_id": &schema.Schema{ "main_route_table_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"default_network_acl_id": &schema.Schema{ "default_network_acl_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"dhcp_options_id": &schema.Schema{ "dhcp_options_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"default_security_group_id": &schema.Schema{ "default_security_group_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"default_route_table_id": &schema.Schema{ "default_route_table_id": {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
@ -260,7 +260,9 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("enable_dns_support") d.SetPartial("enable_dns_support")
} }
if d.HasChange("enable_dns_support") { _, hasEnableDnsSupportOption := d.GetOk("enable_dns_support")
if !hasEnableDnsSupportOption || d.HasChange("enable_dns_support") {
val := d.Get("enable_dns_support").(bool) val := d.Get("enable_dns_support").(bool)
modifyOpts := &ec2.ModifyVpcAttributeInput{ modifyOpts := &ec2.ModifyVpcAttributeInput{
VpcId: &vpcid, VpcId: &vpcid,

View File

@ -19,7 +19,7 @@ func TestAccAWSVpc_basic(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy, CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccVpcConfig, Config: testAccVpcConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc), testAccCheckVpcExists("aws_vpc.foo", &vpc),
@ -42,7 +42,7 @@ func TestAccAWSVpc_dedicatedTenancy(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy, CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccVpcDedicatedConfig, Config: testAccVpcDedicatedConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.bar", &vpc), testAccCheckVpcExists("aws_vpc.bar", &vpc),
@ -62,7 +62,7 @@ func TestAccAWSVpc_tags(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy, CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccVpcConfigTags, Config: testAccVpcConfigTags,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc), testAccCheckVpcExists("aws_vpc.foo", &vpc),
@ -73,7 +73,7 @@ func TestAccAWSVpc_tags(t *testing.T) {
), ),
}, },
resource.TestStep{ {
Config: testAccVpcConfigTagsUpdate, Config: testAccVpcConfigTagsUpdate,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc), testAccCheckVpcExists("aws_vpc.foo", &vpc),
@ -93,7 +93,7 @@ func TestAccAWSVpc_update(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy, CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccVpcConfig, Config: testAccVpcConfig,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc), testAccCheckVpcExists("aws_vpc.foo", &vpc),
@ -102,7 +102,7 @@ func TestAccAWSVpc_update(t *testing.T) {
"aws_vpc.foo", "cidr_block", "10.1.0.0/16"), "aws_vpc.foo", "cidr_block", "10.1.0.0/16"),
), ),
}, },
resource.TestStep{ {
Config: testAccVpcConfigUpdate, Config: testAccVpcConfigUpdate,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc), testAccCheckVpcExists("aws_vpc.foo", &vpc),
@ -195,7 +195,7 @@ func TestAccAWSVpc_bothDnsOptionsSet(t *testing.T) {
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy, CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccVpcConfig_BothDnsOptions, Config: testAccVpcConfig_BothDnsOptions,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -208,13 +208,31 @@ func TestAccAWSVpc_bothDnsOptionsSet(t *testing.T) {
}) })
} }
// https://github.com/hashicorp/terraform/issues/10168
func TestAccAWSVpc_DisabledDnsSupport(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
{
Config: testAccVpcConfig_DisabledDnsSupport,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_vpc.bar", "enable_dns_support", "false"),
),
},
},
})
}
func TestAccAWSVpc_classiclinkOptionSet(t *testing.T) { func TestAccAWSVpc_classiclinkOptionSet(t *testing.T) {
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy, CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ {
Config: testAccVpcConfig_ClassiclinkOption, Config: testAccVpcConfig_ClassiclinkOption,
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -278,6 +296,18 @@ resource "aws_vpc" "bar" {
} }
` `
const testAccVpcConfig_DisabledDnsSupport = `
provider "aws" {
region = "eu-central-1"
}
resource "aws_vpc" "bar" {
cidr_block = "10.2.0.0/16"
enable_dns_support = false
}
`
const testAccVpcConfig_ClassiclinkOption = ` const testAccVpcConfig_ClassiclinkOption = `
resource "aws_vpc" "bar" { resource "aws_vpc" "bar" {
cidr_block = "172.2.0.0/16" cidr_block = "172.2.0.0/16"