Commit abaab05d authored by Takumi Takahashi's avatar Takumi Takahashi Committed by GitHub

feat: Add support for failover_routing_policy and health_check_id (#33)

parent e35eb785
...@@ -94,7 +94,7 @@ jobs: ...@@ -94,7 +94,7 @@ jobs:
- name: Install pre-commit dependencies - name: Install pre-commit dependencies
run: | run: |
pip install pre-commit pip install pre-commit
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12.0-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/ curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12\..+?-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/ curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
- name: Execute pre-commit - name: Execute pre-commit
# Run all pre-commit checks on max version supported # Run all pre-commit checks on max version supported
......
...@@ -24,7 +24,9 @@ Note that this example may create resources which cost money. Run `terraform des ...@@ -24,7 +24,9 @@ Note that this example may create resources which cost money. Run `terraform des
## Providers ## Providers
No providers. | Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 2.49 |
## Modules ## Modules
...@@ -40,7 +42,9 @@ No providers. ...@@ -40,7 +42,9 @@ No providers.
## Resources ## Resources
No resources. | Name | Type |
|------|------|
| [aws_route53_health_check.failover](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_health_check) | resource |
## Inputs ## Inputs
......
...@@ -75,7 +75,7 @@ module "records" { ...@@ -75,7 +75,7 @@ module "records" {
{ {
name = "test" name = "test"
type = "CNAME" type = "CNAME"
ttl = "5" ttl = 5
records = ["test.example.com."] records = ["test.example.com."]
set_identifier = "test-primary" set_identifier = "test-primary"
weighted_routing_policy = { weighted_routing_policy = {
...@@ -85,12 +85,37 @@ module "records" { ...@@ -85,12 +85,37 @@ module "records" {
{ {
name = "test" name = "test"
type = "CNAME" type = "CNAME"
ttl = "5" ttl = 5
records = ["test2.example.com."] records = ["test2.example.com."]
set_identifier = "test-secondary" set_identifier = "test-secondary"
weighted_routing_policy = { weighted_routing_policy = {
weight = 10 weight = 10
} }
},
{
name = "failover-primary"
type = "A"
set_identifier = "failover-primary"
health_check_id = aws_route53_health_check.failover.id
alias = {
name = module.cloudfront.this_cloudfront_distribution_domain_name
zone_id = module.cloudfront.this_cloudfront_distribution_hosted_zone_id
}
failover_routing_policy = {
type = "PRIMARY"
}
},
{
name = "failover-secondary"
type = "A"
set_identifier = "failover-secondary"
alias = {
name = module.s3_bucket.this_s3_bucket_website_domain
zone_id = module.s3_bucket.this_s3_bucket_hosted_zone_id
}
failover_routing_policy = {
type = "SECONDARY"
}
} }
] ]
...@@ -107,6 +132,15 @@ module "disabled_records" { ...@@ -107,6 +132,15 @@ module "disabled_records" {
# Extras - should be created in advance # Extras - should be created in advance
######### #########
resource "aws_route53_health_check" "failover" {
fqdn = module.cloudfront.this_cloudfront_distribution_domain_name
port = 443
type = "HTTPS"
resource_path = "/index.html"
failure_threshold = 3
request_interval = 30
}
module "s3_bucket" { module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws" source = "terraform-aws-modules/s3-bucket/aws"
......
...@@ -16,11 +16,12 @@ resource "aws_route53_record" "this" { ...@@ -16,11 +16,12 @@ resource "aws_route53_record" "this" {
zone_id = data.aws_route53_zone.this[0].zone_id zone_id = data.aws_route53_zone.this[0].zone_id
name = each.value.name != "" ? "${each.value.name}.${data.aws_route53_zone.this[0].name}" : data.aws_route53_zone.this[0].name name = each.value.name != "" ? "${each.value.name}.${data.aws_route53_zone.this[0].name}" : data.aws_route53_zone.this[0].name
type = each.value.type type = each.value.type
ttl = lookup(each.value, "ttl", null) ttl = lookup(each.value, "ttl", null)
records = lookup(each.value, "records", null) records = lookup(each.value, "records", null)
set_identifier = lookup(each.value, "set_identifier", null) set_identifier = lookup(each.value, "set_identifier", null)
health_check_id = lookup(each.value, "health_check_id", null)
dynamic "alias" { dynamic "alias" {
for_each = length(keys(lookup(each.value, "alias", {}))) == 0 ? [] : [true] for_each = length(keys(lookup(each.value, "alias", {}))) == 0 ? [] : [true]
...@@ -32,6 +33,14 @@ resource "aws_route53_record" "this" { ...@@ -32,6 +33,14 @@ resource "aws_route53_record" "this" {
} }
} }
dynamic "failover_routing_policy" {
for_each = length(keys(lookup(each.value, "failover_routing_policy", {}))) == 0 ? [] : [true]
content {
type = each.value.failover_routing_policy.type
}
}
dynamic "weighted_routing_policy" { dynamic "weighted_routing_policy" {
for_each = length(keys(lookup(each.value, "weighted_routing_policy", {}))) == 0 ? [] : [true] for_each = length(keys(lookup(each.value, "weighted_routing_policy", {}))) == 0 ? [] : [true]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment