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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Fixed the aws_vpc enable_dns_support handling on creation #10171

Merged
merged 1 commit into from Nov 16, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions builtin/providers/aws/resource_aws_vpc.go
Expand Up @@ -23,59 +23,59 @@ func resourceAwsVpc() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"cidr_block": &schema.Schema{
"cidr_block": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateCIDRNetworkAddress,
},

"instance_tenancy": &schema.Schema{
"instance_tenancy": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"enable_dns_hostnames": &schema.Schema{
"enable_dns_hostnames": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"enable_dns_support": &schema.Schema{
"enable_dns_support": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"enable_classiclink": &schema.Schema{
"enable_classiclink": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"main_route_table_id": &schema.Schema{
"main_route_table_id": {
Type: schema.TypeString,
Computed: true,
},

"default_network_acl_id": &schema.Schema{
"default_network_acl_id": {
Type: schema.TypeString,
Computed: true,
},

"dhcp_options_id": &schema.Schema{
"dhcp_options_id": {
Type: schema.TypeString,
Computed: true,
},

"default_security_group_id": &schema.Schema{
"default_security_group_id": {
Type: schema.TypeString,
Computed: true,
},

"default_route_table_id": &schema.Schema{
"default_route_table_id": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -260,7 +260,9 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
d.SetPartial("enable_dns_support")
}

if d.HasChange("enable_dns_support") {
_, hasEnableDnsSupportOption := d.GetOk("enable_dns_support")

if !hasEnableDnsSupportOption || d.HasChange("enable_dns_support") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems enable_dns_support is the only attribute that defaults true on AWS side here, which is why this is the only one that needs this check (if I understand correctly)

val := d.Get("enable_dns_support").(bool)
modifyOpts := &ec2.ModifyVpcAttributeInput{
VpcId: &vpcid,
Expand Down
46 changes: 38 additions & 8 deletions builtin/providers/aws/resource_aws_vpc_test.go
Expand Up @@ -19,7 +19,7 @@ func TestAccAWSVpc_basic(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccVpcConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc),
Expand All @@ -42,7 +42,7 @@ func TestAccAWSVpc_dedicatedTenancy(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccVpcDedicatedConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.bar", &vpc),
Expand All @@ -62,7 +62,7 @@ func TestAccAWSVpc_tags(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccVpcConfigTags,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc),
Expand All @@ -73,7 +73,7 @@ func TestAccAWSVpc_tags(t *testing.T) {
),
},

resource.TestStep{
{
Config: testAccVpcConfigTagsUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc),
Expand All @@ -93,7 +93,7 @@ func TestAccAWSVpc_update(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccVpcConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc),
Expand All @@ -102,7 +102,7 @@ func TestAccAWSVpc_update(t *testing.T) {
"aws_vpc.foo", "cidr_block", "10.1.0.0/16"),
),
},
resource.TestStep{
{
Config: testAccVpcConfigUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc),
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestAccAWSVpc_bothDnsOptionsSet(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccVpcConfig_BothDnsOptions,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand All @@ -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) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccVpcConfig_ClassiclinkOption,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -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 = `
resource "aws_vpc" "bar" {
cidr_block = "172.2.0.0/16"
Expand Down