Commit 69077873 authored by Anton Babenko's avatar Anton Babenko

Added route53 modules for zones and records

parents
# Change Log
All notable changes to this project will be documented in this file.
{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
{{/* SKIPPING RULES - START */ -}}
{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
{{- if not (contains .Subject "[ci skip]") -}}
{{- if not (contains .Subject "[skip ci]") -}}
{{- if not (hasPrefix .Subject "Merge pull request ") -}}
{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
{{- /* SKIPPING RULES - END */ -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{/* SKIPPING RULES - START */ -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{/* SKIPPING RULES - END */ -}}
{{ end }}
{{ end -}}
{{ else }}
{{ range .Unreleased.Commits -}}
{{/* SKIPPING RULES - START */ -}}
{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
{{- if not (contains .Subject "[ci skip]") -}}
{{- if not (contains .Subject "[skip ci]") -}}
{{- if not (hasPrefix .Subject "Merge pull request ") -}}
{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
{{- /* SKIPPING RULES - END */ -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{/* SKIPPING RULES - START */ -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{/* SKIPPING RULES - END */ -}}
{{ end }}
{{ end -}}
{{ end -}}
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ if .CommitGroups -}}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
{{/* SKIPPING RULES - START */ -}}
{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
{{- if not (contains .Subject "[ci skip]") -}}
{{- if not (contains .Subject "[skip ci]") -}}
{{- if not (hasPrefix .Subject "Merge pull request ") -}}
{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
{{- /* SKIPPING RULES - END */ -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{/* SKIPPING RULES - START */ -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{/* SKIPPING RULES - END */ -}}
{{ end }}
{{ end -}}
{{ else }}
{{ range .Commits -}}
{{/* SKIPPING RULES - START */ -}}
{{- if not (hasPrefix .Subject "Updated CHANGELOG") -}}
{{- if not (contains .Subject "[ci skip]") -}}
{{- if not (contains .Subject "[skip ci]") -}}
{{- if not (hasPrefix .Subject "Merge pull request ") -}}
{{- if not (hasPrefix .Subject "Added CHANGELOG") -}}
{{- /* SKIPPING RULES - END */ -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{/* SKIPPING RULES - START */ -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{/* SKIPPING RULES - END */ -}}
{{ end }}
{{ end -}}
{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
{{- if .Versions }}
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
{{ range .Versions -}}
{{ if .Tag.Previous -}}
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
{{ end -}}
{{ end -}}
{{ end -}}
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/terraform-aws-modules/terraform-aws-route53
options:
header:
pattern: "^(.*)$"
pattern_maps:
- Subject
# EditorConfig is awesome: http://EditorConfig.org
# Uses editorconfig to maintain consistent coding styles
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
[*.{tf,tfvars}]
indent_size = 2
indent_style = space
[*.md]
max_line_length = 0
trim_trailing_whitespace = false
[Makefile]
tab_width = 2
indent_style = tab
[COMMIT_EDITMSG]
max_line_length = 0
.terraform
terraform.tfstate
*.tfstate*
terraform.tfvars
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.31.0
hooks:
- id: terraform_fmt
- id: terraform_docs
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v3.1.0
hooks:
- id: check-merge-conflict
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
.PHONY: changelog release
changelog:
git-chglog -o CHANGELOG.md --next-tag `semtag final -s minor -o`
release:
semtag final -s minor
# Route53 Terraform module
Terraform module which creates Route53 resources.
There are independent submodules:
* [zones](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/zones) - to manage Route53 zones
* [records](https://github.com/terraform-aws-modules/terraform-aws-route53/tree/master/modules/records) - to manage Route53 records
This module currently does not have all arguments supported by the Terraform AWS providers.
## Terraform versions
Terraform 0.12. Pin module version to `~> v1.0`. Submit pull-requests to `master` branch.
## Usage
### Create Route53 zones and records
```hcl
module "zones" {
source = "terraform-aws-modules/route53/aws//modules/zones"
version = "~> 1.0"
zones = {
"terraform-aws-modules-example.com" = {
comment = "terraform-aws-modules-examples.com (production)"
tags = {
env = "production"
}
}
"myapp.com" = {
comment = "myapp.com"
}
}
}
module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "~> 1.0"
zone_name = keys(module.zones.this_route53_zone_zone_id)[0]
records = [
{
name = "apigateway1"
type = "A"
alias = {
name = "d-10qxlbvagl.execute-api.eu-west-1.amazonaws.com"
zone_id = "ZLY8HYME6SFAD"
}
},
{
name = ""
type = "A"
ttl = 3600
records = [
"10.10.10.10",
]
},
]
depends_on = [module.zones]
}
```
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)
## Conditional creation
Sometimes you need to have a way to create resources conditionally but Terraform does not allow to use `count` inside `module` block, so the solution is to specify argument `create`.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
| Name | Version |
|------|---------|
| terraform | >= 0.12.6, < 0.14 |
| aws | ~> 2.49 |
## Providers
No provider.
## Inputs
No input.
## Outputs
No output.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Authors
Module managed by [Anton Babenko](https://github.com/antonbabenko).
## License
Apache 2 Licensed. See LICENSE for full details.
# Route53 zones and records example
Configuration in this directory creates Route53 zones and records.
## Usage
To run this example you need to execute:
```bash
$ terraform init
$ terraform plan
$ terraform apply
```
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
## Providers
No provider.
## Inputs
No input.
## Outputs
No output.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
provider "aws" {
region = "eu-west-1"
}
module "zones" {
source = "../../modules/zones"
zones = {
"terraform-aws-modules-example.com" = {
comment = "terraform-aws-modules-examples.com (production)"
tags = {
Name = "terraform-aws-modules-example.com"
}
}
"app.terraform-aws-modules-example.com" = {
comment = "app.terraform-aws-modules-example.com"
tags = {
Name = "app.terraform-aws-modules-example.com"
}
}
}
}
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"]
records = [
// {
// name = "apigateway1"
// type = "A"
// alias = {
// name = "..."
// zone_id = "..."
// }
// },
{
name = ""
type = "A"
ttl = 3600
records = [
"10.10.10.10",
]
},
]
depends_on = [module.zones]
}
//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
//}
# Route53 Records
This module creates DNS records in Route53 zone.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| create | Whether to create DNS records | `bool` | `true` | no |
| private\_zone | Whether Route53 zone is private or public | `bool` | `false` | no |
| records | List of maps of DNS records | `any` | `[]` | no |
| zone\_id | ID of DNS zone | `string` | `null` | no |
| zone\_name | Name of DNS zone | `string` | `null` | no |
## Outputs
| 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 -->
locals {
// convert from list to map with unique keys
recordsets = { for rs in var.records : "${rs.name} ${rs.type}" => rs }
}
data "aws_route53_zone" "this" {
count = var.create && (var.zone_id != null || var.zone_name != null) ? 1 : 0
zone_id = var.zone_id
name = var.zone_name
private_zone = var.private_zone
}
resource "aws_route53_record" "this" {
for_each = var.create && (var.zone_id != null || var.zone_name != null) ? local.recordsets : {}
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
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.name # module.api_gateway.this_apigatewayv2_domain_name_configuration.0.target_domain_name
zone_id = each.value.alias.zone_id
evaluate_target_health = lookup(each.value.alias, "evaluate_target_health", false)
}
}
}
output "this_route53_record_name" {
description = "The name of the record"
value = { for k, v in aws_route53_record.this : k => v.name }
}
output "this_route53_record_fqdn" {
description = "FQDN built using the zone domain and name"
value = { for k, v in aws_route53_record.this : k => v.fqdn }
}
variable "create" {
description = "Whether to create DNS records"
type = bool
default = true
}
variable "zone_id" {
description = "ID of DNS zone"
type = string
default = null
}
variable "zone_name" {
description = "Name of DNS zone"
type = string
default = null
}
variable "private_zone" {
description = "Whether Route53 zone is private or public"
type = bool
default = false
}
variable "records" {
description = "List of maps of DNS records"
type = any
default = []
}
# Route53 Zones
This module creates Route53 zones.
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
No requirements.
## Providers
| Name | Version |
|------|---------|
| aws | n/a |
## Inputs
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| create | Whether to create Route53 zone | `bool` | `true` | no |
| zones | Map of Route53 zone parameters | `map(any)` | `{}` | no |
## Outputs
| Name | Description |
|------|-------------|
| this\_route53\_zone\_name\_servers | Name servers of Route53 zone |
| this\_route53\_zone\_zone\_id | Zone ID of Route53 zone |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
resource "aws_route53_zone" "this" {
for_each = var.create ? var.zones : {}
name = each.key
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)
}
output "this_route53_zone_zone_id" {
description = "Zone ID of Route53 zone"
value = { for k, v in aws_route53_zone.this : k => v.zone_id }
}
output "this_route53_zone_name_servers" {
description = "Name servers of Route53 zone"
value = { for k, v in aws_route53_zone.this : k => v.name_servers }
}
variable "create" {
description = "Whether to create Route53 zone"
type = bool
default = true
}
variable "zones" {
description = "Map of Route53 zone parameters"
type = map(any)
default = {}
}
terraform {
required_version = ">= 0.12.6, < 0.14"
required_providers {
aws = "~> 2.49"
}
}
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