AWS/Route53Zone - create private hosted zone associated with VPC.

This commit is contained in:
John Engelman 2015-04-13 12:42:20 -05:00
parent beb3ea949d
commit bf97d6a80f
3 changed files with 55 additions and 0 deletions

View File

@ -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)

View File

@ -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}"
}
`

View File

@ -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