Commit e16806d8 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

fix: Allow combining records and aliases (#11)

parent 05623b69
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.31.0
rev: v1.40.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- id: terraform_tflint
args:
- '--args=--only=terraform_deprecated_interpolation'
- '--args=--only=terraform_deprecated_index'
- '--args=--only=terraform_unused_declarations'
- '--args=--only=terraform_comment_syntax'
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_version'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
- '--args=--only=terraform_workspace_remote'
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
rev: v3.2.0
hooks:
- id: check-merge-conflict
......@@ -72,7 +72,7 @@ Note that `depends_on` in modules is available since Terraform 0.13.
## Examples
* [Complete Route53 zones and records example](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/examples/complete)
* [Complete Route53 zones and records example](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/examples/complete) which shows how to create Route53 records of various types like S3 bucket and CloudFront distribution.
## Conditional creation
......
# Route53 zones and records example
Configuration in this directory creates Route53 zones and records.
Configuration in this directory creates Route53 zones and records for various types of resources - S3 bucket, CloudFront distribution, static records.
## Usage
......@@ -17,7 +17,10 @@ Note that this example may create resources which cost money. Run `terraform des
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
| Name | Version |
|------|---------|
| terraform | >= 0.12.6, < 0.14 |
| aws | >= 2.49, < 4.0 |
## Providers
......@@ -29,6 +32,9 @@ No input.
## Outputs
No output.
| Name | Description |
|------|-------------|
| this\_route53\_record\_fqdn | FQDN built using the zone domain and name |
| this\_route53\_record\_name | The name of the record |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
......@@ -26,17 +26,9 @@ module "records" {
source = "../../modules/records"
zone_name = keys(module.zones.this_route53_zone_zone_id)[0]
// zone_id = module.zones.this_route53_zone_zone_id["terraform-aws-modules-example.com"]
# zone_id = module.zones.this_route53_zone_zone_id["terraform-aws-modules-example.com"]
records = [
// {
// name = "apigateway1"
// type = "A"
// alias = {
// name = "..."
// zone_id = "..."
// }
// },
{
name = ""
type = "A"
......@@ -45,7 +37,63 @@ module "records" {
"10.10.10.10",
]
},
{
name = "s3-bucket"
type = "A"
alias = {
name = module.s3_bucket.this_s3_bucket_website_domain
zone_id = module.s3_bucket.this_s3_bucket_hosted_zone_id
}
},
{
name = "cloudfront"
type = "A"
alias = {
name = module.cloudfront.this_cloudfront_distribution_domain_name
zone_id = module.cloudfront.this_cloudfront_distribution_hosted_zone_id
}
},
]
depends_on = [module.zones]
depends_on = [module.zones] #, module.cloudfront, module.s3_bucket]
}
#########
# Extras - should be created in advance
#########
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket_prefix = "s3-bucket-"
force_destroy = true
website = {
index_document = "index.html"
}
}
module "cloudfront" {
source = "terraform-aws-modules/cloudfront/aws"
enabled = true
wait_for_deployment = false
origin = {
s3_bucket = {
domain_name = module.s3_bucket.this_s3_bucket_bucket_regional_domain_name
}
}
cache_behavior = {
default = {
target_origin_id = "s3_bucket"
viewer_protocol_policy = "allow-all"
}
}
viewer_certificate = {
cloudfront_default_certificate = true
}
}
//output "users_unencrypted_this_sqs_queue_id" {
// description = "The URL for the created Amazon SQS queue"
// value = module.users_unencrypted.this_sqs_queue_id
//}
//
//output "users_unencrypted_this_sqs_queue_arn" {
// description = "The ARN of the SQS queue"
// value = module.users_unencrypted.this_sqs_queue_arn
//}
//
//output "users_encrypted_this_sqs_queue_id" {
// description = "The URL for the created Amazon SQS queue"
// value = module.users_encrypted.this_sqs_queue_id
//}
//
//output "users_encrypted_this_sqs_queue_arn" {
// description = "The ARN of the SQS queue"
// value = module.users_encrypted.this_sqs_queue_arn
//}
output "this_route53_record_name" {
description = "The name of the record"
value = module.records.this_route53_record_name
}
output "this_route53_record_fqdn" {
description = "FQDN built using the zone domain and name"
value = module.records.this_route53_record_fqdn
}
......@@ -5,13 +5,16 @@ This module creates DNS records in Route53 zone.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
| Name | Version |
|------|---------|
| terraform | >= 0.12.6, < 0.14 |
| aws | >= 2.49, < 4.0 |
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
| aws | >= 2.49, < 4.0 |
## Inputs
......
locals {
// convert from list to map with unique keys
# convert from list to map with unique keys
recordsets = { for rs in var.records : "${rs.name} ${rs.type}" => rs }
}
......@@ -12,7 +12,8 @@ data "aws_route53_zone" "this" {
}
resource "aws_route53_record" "this" {
for_each = var.create && (var.zone_id != null || var.zone_name != null) ? local.recordsets : {}
for_each = var.create && (var.zone_id != null || var.zone_name != null) ? local.recordsets : object({})
# for_each = local.recordsets
zone_id = data.aws_route53_zone.this[0].zone_id
......
terraform {
required_version = ">= 0.12.6, < 0.14"
required_providers {
aws = ">= 2.49, < 4.0"
}
}
......@@ -5,13 +5,16 @@ This module creates Route53 zones.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
| Name | Version |
|------|---------|
| terraform | >= 0.12.6, < 0.14 |
| aws | >= 2.49, < 4.0 |
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
| aws | >= 2.49, < 4.0 |
## Inputs
......
......@@ -5,10 +5,5 @@ resource "aws_route53_zone" "this" {
comment = lookup(each.value, "comment", null)
force_destroy = lookup(each.value, "force_destroy", false)
// delegation_set_id = ""
// vpc {
// vpc_id = ""
// }
tags = lookup(each.value, "tags", null)
}
terraform {
required_version = ">= 0.12.6, < 0.14"
required_providers {
aws = ">= 2.49, < 4.0"
}
}
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