mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
AWS/Route53Zone - create private hosted zone associated with VPC.
This commit is contained in:
parent
beb3ea949d
commit
bf97d6a80f
@ -28,6 +28,18 @@ func resourceAwsRoute53Zone() *schema.Resource {
|
|||||||
ForceNew: true,
|
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{
|
"zone_id": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
@ -53,6 +65,15 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
|
|||||||
HostedZoneConfig: comment,
|
HostedZoneConfig: comment,
|
||||||
CallerReference: aws.String(time.Now().Format(time.RFC3339Nano)),
|
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)
|
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name)
|
||||||
resp, err := r53.CreateHostedZone(req)
|
resp, err := r53.CreateHostedZone(req)
|
||||||
|
@ -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 {
|
func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||||
for _, rs := range s.RootModule().Resources {
|
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}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
@ -55,6 +55,8 @@ The following arguments are supported:
|
|||||||
|
|
||||||
* `name` - (Required) This is the name of the hosted zone.
|
* `name` - (Required) This is the name of the hosted zone.
|
||||||
* `tags` - (Optional) A mapping of tags to assign to the 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
|
## Attributes Reference
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user