-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,55 @@ | ||
# terraform-aws-route53 | ||
# terraform-aws-route53 | ||
Terraform module to create route 53 hosted zones. | ||
|
||
## Usages | ||
|
||
### Example for public zone: | ||
|
||
```hcl | ||
module "public_zone_name" { | ||
source = "[email protected]:nimbux911/terraform-aws-route53/tags/v1.0" | ||
zone_name = "name." | ||
record_set = [ { | ||
record_name = "name." | ||
type = "A" // Valid values are A, AAAA, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV and TXT | ||
ttl = 300 | ||
records = ["IP"] | ||
} ] | ||
tags = { | ||
Environment = var.environment | ||
Purpose = "Api endpoint" | ||
} | ||
} | ||
``` | ||
|
||
### Example for private zone: | ||
|
||
```hcl | ||
module "private_zone_name" { | ||
source = "[email protected]:nimbux911/terraform-aws-route53/tags/1.0" | ||
zone_name = "name." | ||
vpc_id = "vpc-id" | ||
record_set = [ { | ||
record_name = "name." | ||
type = "A" // Valid values are A, AAAA, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SPF, SRV and TXT | ||
ttl = 300 | ||
records = ["IP"] | ||
} ] | ||
tags = { | ||
Environment = var.environment | ||
Purpouse = "Api endpoint" | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| zone_id | The ID of Hosted Zone | | ||
| name_servers | A list of name servers in associated (or default) delegation set | | ||
| zone_name | Route53 Hosted Zone domain name | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
locals { | ||
zone_id = concat( | ||
aws_route53_zone.private.*.zone_id, | ||
aws_route53_zone.public.*.zone_id, | ||
)[0] | ||
name_servers = concat( | ||
aws_route53_zone.private.*.name_servers, | ||
aws_route53_zone.public.*.name_servers, | ||
)[0] | ||
# convert from list to map with unique keys | ||
record_set = { for rs in var.record_set : join(" ", compact(["${rs.name} ${rs.type}", lookup(rs, "set_identifier", "")])) => rs } | ||
} | ||
|
||
resource "aws_route53_zone" "public" { | ||
count = var.vpc_id == "" ? 1 : 0 | ||
name = var.zone_name | ||
comment = var.comment | ||
force_destroy = var.force_destroy | ||
tags = var.tags | ||
} | ||
|
||
resource "aws_route53_zone" "private" { | ||
count = var.vpc_id != "" ? 1 : 0 | ||
name = var.zone_name | ||
comment = var.comment | ||
force_destroy = var.force_destroy | ||
vpc { | ||
vpc_id = var.vpc_id | ||
} | ||
tags = var.tags | ||
} | ||
|
||
# resource "aws_route53_zone_association" "secondary" { | ||
# count = var.vpc_id != "" ? 1 : 0 | ||
# zone_id = aws_route53_zone.private[count.index].zone_id | ||
# vpc_id = var.vpc_id | ||
# } | ||
|
||
resource "aws_route53_record" "record_set" { | ||
for_each = local.record_set | ||
zone_id = local.zone_id | ||
name = each.value.name | ||
type = each.value.type | ||
ttl = lookup(each.value, "ttl", null) | ||
records = lookup(each.value, "records", null) | ||
|
||
dynamic "alias" { | ||
for_each = length(keys(lookup(each.value, "alias", {}))) == 0 ? [] : [true] | ||
|
||
content { | ||
name = each.value.alias.dns_name | ||
zone_id = each.value.alias.zone_id | ||
evaluate_target_health = lookup(each.value.alias, "evaluate_target_health", false) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
output "zone_id" { | ||
description = "Private zone ID created" | ||
value = local.zone_id | ||
} | ||
output "name_servers" { | ||
description = "A list of name servers in associated (or default) delegation set" | ||
value = local.name_servers | ||
} | ||
output "zone_name" { | ||
description = "Route53 Hosted Zone domain name" | ||
value = var.zone_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
variable "zone_name" { | ||
description = "This is the name of the hosted zone" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "vpc_id" { | ||
description = "ID of the VPC to associate" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "tags" { | ||
description = "A map of tags to add to IAM role resources" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "record_set" { | ||
description = "List of maps of DNS records" | ||
type = any | ||
default = [] | ||
} | ||
|
||
variable "comment" { | ||
description = "A comment for the hosted zone" | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "force_destroy" { | ||
description = "Whether to destroy all records (possibly managed outside of Terraform) in the zone when destroying the zone" | ||
type = bool | ||
default = false | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
terraform { | ||
required_version = ">= 0.13" | ||
} |