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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] provider/aws: aws_route53_zone should recreate when vpc_id removed #8987

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions builtin/providers/aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ func resourceAwsRoute53Zone() *schema.Resource {
},

"vpc_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"delegation_set_id"},
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "",
},

"vpc_region": &schema.Schema{
Expand All @@ -59,10 +59,10 @@ func resourceAwsRoute53Zone() *schema.Resource {
},

"delegation_set_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"vpc_id"},
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

"name_servers": &schema.Schema{
Expand Down Expand Up @@ -167,6 +167,9 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
if err := d.Set("name_servers", ns); err != nil {
return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err)
}

d.Set("vpc_id", "")
d.Set("vpc_region", "")
} else {
ns, err := getNameServers(d.Id(), d.Get("name").(string), r53)
if err != nil {
Expand Down
50 changes: 50 additions & 0 deletions builtin/providers/aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,42 @@ func TestAccAWSRoute53Zone_private_region(t *testing.T) {
})
}

func TestAccAWSRoute53Zone_privateToPublic(t *testing.T) {
var before, after route53.GetHostedZoneOutput

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_route53_zone.main",
Providers: testAccProviders,
CheckDestroy: testAccCheckRoute53ZoneDestroy,
Steps: []resource.TestStep{
{
Config: testAccRoute53PrivateZoneConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &before),
testAccCheckRoute53ZoneAssociatesWithVpc("aws_vpc.main", &before),
),
},
{
Config: testAccRoute53PrivateZoneConfigToPublic,
Check: resource.ComposeTestCheckFunc(
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &after),
testAccCheckRoute53ZoneRecreated(t, &before, &after),
),
},
},
})
}

func testAccCheckRoute53ZoneRecreated(t *testing.T, before, after *route53.GetHostedZoneOutput) resource.TestCheckFunc {
return func(s *terraform.State) error {
if *before.HostedZone.Id == *after.HostedZone.Id {
t.Fatalf("Expected change of Zone IDs, but both were %v", before.HostedZone.Id)
}
return nil
}
}

func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
return testAccCheckRoute53ZoneDestroyWithProvider(s, testAccProvider)
}
Expand Down Expand Up @@ -445,6 +481,20 @@ resource "aws_route53_zone" "main" {
}
`

const testAccRoute53PrivateZoneConfigToPublic = `
resource "aws_vpc" "main" {
cidr_block = "172.29.0.0/24"
instance_tenancy = "default"
enable_dns_support = true
enable_dns_hostnames = true
}

resource "aws_route53_zone" "main" {
name = "hashicorp.com."

}
`

const testAccRoute53PrivateZoneRegionConfig = `
provider "aws" {
alias = "west"
Expand Down
11 changes: 6 additions & 5 deletions terraform/eval_diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"strings"

"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform/config"
)

Expand Down Expand Up @@ -44,8 +45,8 @@ func (n *EvalCompareDiff) Eval(ctx EvalContext) (interface{}, error) {
if same, reason := one.Same(two); !same {
log.Printf("[ERROR] %s: diffs didn't match", n.Info.Id)
log.Printf("[ERROR] %s: reason: %s", n.Info.Id, reason)
log.Printf("[ERROR] %s: diff one: %#v", n.Info.Id, one)
log.Printf("[ERROR] %s: diff two: %#v", n.Info.Id, two)
log.Printf("[ERROR] %s: diff one: %s", n.Info.Id, spew.Sdump(one))
log.Printf("[ERROR] %s: diff two: %s", n.Info.Id, spew.Sdump(two))
return nil, fmt.Errorf(
"%s: diffs didn't match during apply. This is a bug with "+
"Terraform and should be reported as a GitHub Issue.\n"+
Expand All @@ -55,12 +56,12 @@ func (n *EvalCompareDiff) Eval(ctx EvalContext) (interface{}, error) {
" Terraform Version: %s\n"+
" Resource ID: %s\n"+
" Mismatch reason: %s\n"+
" Diff One (usually from plan): %#v\n"+
" Diff Two (usually from apply): %#v\n"+
" Diff One (usually from plan): %s\n"+
" Diff Two (usually from apply): %s\n"+
"\n"+
"Also include as much context as you can about your config, state, "+
"and the steps you performed to trigger this error.\n",
n.Info.Id, Version, n.Info.Id, reason, one, two)
n.Info.Id, Version, n.Info.Id, reason, spew.Sdump(one), spew.Sdump(two))
}

return nil, nil
Expand Down