Skip to content

Commit d004a24

Browse files
authored
Merge pull request hashicorp#10171 from Ninir/vpc_enable_dns_support
provider/aws: Fixed the aws_vpc enable_dns_support handling on creation
2 parents 50ecb74 + 281eba7 commit d004a24

2 files changed

Lines changed: 51 additions & 19 deletions

File tree

builtin/providers/aws/resource_aws_vpc.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,59 +23,59 @@ func resourceAwsVpc() *schema.Resource {
2323
},
2424

2525
Schema: map[string]*schema.Schema{
26-
"cidr_block": &schema.Schema{
26+
"cidr_block": {
2727
Type: schema.TypeString,
2828
Required: true,
2929
ForceNew: true,
3030
ValidateFunc: validateCIDRNetworkAddress,
3131
},
3232

33-
"instance_tenancy": &schema.Schema{
33+
"instance_tenancy": {
3434
Type: schema.TypeString,
3535
Optional: true,
3636
ForceNew: true,
3737
Computed: true,
3838
},
3939

40-
"enable_dns_hostnames": &schema.Schema{
40+
"enable_dns_hostnames": {
4141
Type: schema.TypeBool,
4242
Optional: true,
4343
Computed: true,
4444
},
4545

46-
"enable_dns_support": &schema.Schema{
46+
"enable_dns_support": {
4747
Type: schema.TypeBool,
4848
Optional: true,
4949
Computed: true,
5050
},
5151

52-
"enable_classiclink": &schema.Schema{
52+
"enable_classiclink": {
5353
Type: schema.TypeBool,
5454
Optional: true,
5555
Computed: true,
5656
},
5757

58-
"main_route_table_id": &schema.Schema{
58+
"main_route_table_id": {
5959
Type: schema.TypeString,
6060
Computed: true,
6161
},
6262

63-
"default_network_acl_id": &schema.Schema{
63+
"default_network_acl_id": {
6464
Type: schema.TypeString,
6565
Computed: true,
6666
},
6767

68-
"dhcp_options_id": &schema.Schema{
68+
"dhcp_options_id": {
6969
Type: schema.TypeString,
7070
Computed: true,
7171
},
7272

73-
"default_security_group_id": &schema.Schema{
73+
"default_security_group_id": {
7474
Type: schema.TypeString,
7575
Computed: true,
7676
},
7777

78-
"default_route_table_id": &schema.Schema{
78+
"default_route_table_id": {
7979
Type: schema.TypeString,
8080
Computed: true,
8181
},
@@ -260,7 +260,9 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error {
260260
d.SetPartial("enable_dns_support")
261261
}
262262

263-
if d.HasChange("enable_dns_support") {
263+
_, hasEnableDnsSupportOption := d.GetOk("enable_dns_support")
264+
265+
if !hasEnableDnsSupportOption || d.HasChange("enable_dns_support") {
264266
val := d.Get("enable_dns_support").(bool)
265267
modifyOpts := &ec2.ModifyVpcAttributeInput{
266268
VpcId: &vpcid,

builtin/providers/aws/resource_aws_vpc_test.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestAccAWSVpc_basic(t *testing.T) {
1919
Providers: testAccProviders,
2020
CheckDestroy: testAccCheckVpcDestroy,
2121
Steps: []resource.TestStep{
22-
resource.TestStep{
22+
{
2323
Config: testAccVpcConfig,
2424
Check: resource.ComposeTestCheckFunc(
2525
testAccCheckVpcExists("aws_vpc.foo", &vpc),
@@ -42,7 +42,7 @@ func TestAccAWSVpc_dedicatedTenancy(t *testing.T) {
4242
Providers: testAccProviders,
4343
CheckDestroy: testAccCheckVpcDestroy,
4444
Steps: []resource.TestStep{
45-
resource.TestStep{
45+
{
4646
Config: testAccVpcDedicatedConfig,
4747
Check: resource.ComposeTestCheckFunc(
4848
testAccCheckVpcExists("aws_vpc.bar", &vpc),
@@ -62,7 +62,7 @@ func TestAccAWSVpc_tags(t *testing.T) {
6262
Providers: testAccProviders,
6363
CheckDestroy: testAccCheckVpcDestroy,
6464
Steps: []resource.TestStep{
65-
resource.TestStep{
65+
{
6666
Config: testAccVpcConfigTags,
6767
Check: resource.ComposeTestCheckFunc(
6868
testAccCheckVpcExists("aws_vpc.foo", &vpc),
@@ -73,7 +73,7 @@ func TestAccAWSVpc_tags(t *testing.T) {
7373
),
7474
},
7575

76-
resource.TestStep{
76+
{
7777
Config: testAccVpcConfigTagsUpdate,
7878
Check: resource.ComposeTestCheckFunc(
7979
testAccCheckVpcExists("aws_vpc.foo", &vpc),
@@ -93,7 +93,7 @@ func TestAccAWSVpc_update(t *testing.T) {
9393
Providers: testAccProviders,
9494
CheckDestroy: testAccCheckVpcDestroy,
9595
Steps: []resource.TestStep{
96-
resource.TestStep{
96+
{
9797
Config: testAccVpcConfig,
9898
Check: resource.ComposeTestCheckFunc(
9999
testAccCheckVpcExists("aws_vpc.foo", &vpc),
@@ -102,7 +102,7 @@ func TestAccAWSVpc_update(t *testing.T) {
102102
"aws_vpc.foo", "cidr_block", "10.1.0.0/16"),
103103
),
104104
},
105-
resource.TestStep{
105+
{
106106
Config: testAccVpcConfigUpdate,
107107
Check: resource.ComposeTestCheckFunc(
108108
testAccCheckVpcExists("aws_vpc.foo", &vpc),
@@ -195,7 +195,7 @@ func TestAccAWSVpc_bothDnsOptionsSet(t *testing.T) {
195195
Providers: testAccProviders,
196196
CheckDestroy: testAccCheckVpcDestroy,
197197
Steps: []resource.TestStep{
198-
resource.TestStep{
198+
{
199199
Config: testAccVpcConfig_BothDnsOptions,
200200
Check: resource.ComposeTestCheckFunc(
201201
resource.TestCheckResourceAttr(
@@ -208,13 +208,31 @@ func TestAccAWSVpc_bothDnsOptionsSet(t *testing.T) {
208208
})
209209
}
210210

211+
// https://github.com/hashicorp/terraform/issues/10168
212+
func TestAccAWSVpc_DisabledDnsSupport(t *testing.T) {
213+
resource.Test(t, resource.TestCase{
214+
PreCheck: func() { testAccPreCheck(t) },
215+
Providers: testAccProviders,
216+
CheckDestroy: testAccCheckVpcDestroy,
217+
Steps: []resource.TestStep{
218+
{
219+
Config: testAccVpcConfig_DisabledDnsSupport,
220+
Check: resource.ComposeTestCheckFunc(
221+
resource.TestCheckResourceAttr(
222+
"aws_vpc.bar", "enable_dns_support", "false"),
223+
),
224+
},
225+
},
226+
})
227+
}
228+
211229
func TestAccAWSVpc_classiclinkOptionSet(t *testing.T) {
212230
resource.Test(t, resource.TestCase{
213231
PreCheck: func() { testAccPreCheck(t) },
214232
Providers: testAccProviders,
215233
CheckDestroy: testAccCheckVpcDestroy,
216234
Steps: []resource.TestStep{
217-
resource.TestStep{
235+
{
218236
Config: testAccVpcConfig_ClassiclinkOption,
219237
Check: resource.ComposeTestCheckFunc(
220238
resource.TestCheckResourceAttr(
@@ -278,6 +296,18 @@ resource "aws_vpc" "bar" {
278296
}
279297
`
280298

299+
const testAccVpcConfig_DisabledDnsSupport = `
300+
provider "aws" {
301+
region = "eu-central-1"
302+
}
303+
304+
resource "aws_vpc" "bar" {
305+
cidr_block = "10.2.0.0/16"
306+
307+
enable_dns_support = false
308+
}
309+
`
310+
281311
const testAccVpcConfig_ClassiclinkOption = `
282312
resource "aws_vpc" "bar" {
283313
cidr_block = "172.2.0.0/16"

0 commit comments

Comments
 (0)