diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index 59937fbc08..d8f688e740 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -28,6 +28,18 @@ func resourceAwsRoute53Zone() *schema.Resource { ForceNew: true, }, + "vpc_id": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + + "vpc_region": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "zone_id": &schema.Schema{ Type: schema.TypeString, Computed: true, @@ -53,6 +65,15 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro HostedZoneConfig: comment, CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)), } + if v := d.Get("vpc_id"); v != nil { + req.VPC = &route53.VPC{ + VPCID: aws.String(v.(string)), + VPCRegion: aws.String(meta.(*AWSClient).region), + } + if w := d.Get("vpc_region"); w != nil { + req.VPC.VPCRegion = aws.String(w.(string)) + } + } log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name) resp, err := r53.CreateHostedZone(req) diff --git a/builtin/providers/aws/resource_aws_route53_zone_test.go b/builtin/providers/aws/resource_aws_route53_zone_test.go index 0a32cb2cdf..12ab623d30 100644 --- a/builtin/providers/aws/resource_aws_route53_zone_test.go +++ b/builtin/providers/aws/resource_aws_route53_zone_test.go @@ -84,6 +84,24 @@ func TestAccRoute53Zone(t *testing.T) { }) } +func TestAccRoute53PrivateZone(t *testing.T) { + var zone route53.HostedZone + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53ZoneDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRoute53PrivateZoneConfig, + Check: resource.ComposeTestCheckFunc( + testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone), + ), + }, + }, + }) +} + func testAccCheckRoute53ZoneDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).r53conn for _, rs := range s.RootModule().Resources { @@ -167,3 +185,17 @@ resource "aws_route53_zone" "main" { } } ` + +const testAccRoute53PrivateZoneConfig = ` +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" + vpc_id = "${aws_vpc.main.id}" +} +` diff --git a/website/source/docs/providers/aws/r/route53_zone.html.markdown b/website/source/docs/providers/aws/r/route53_zone.html.markdown index 71c03a10e9..9e09606103 100644 --- a/website/source/docs/providers/aws/r/route53_zone.html.markdown +++ b/website/source/docs/providers/aws/r/route53_zone.html.markdown @@ -55,6 +55,8 @@ The following arguments are supported: * `name` - (Required) This is the name of the hosted zone. * `tags` - (Optional) A mapping of tags to assign to the zone. +* `vpc_id` - (Optional) The VPC to associate with a private hosted zone. Specifying `vpc_id` will create a private hosted zone. +* `vpc_region` - (Optional) The VPC's region. Defaults to the region of the AWS provider. ## Attributes Reference