generated from terraform-modules/template_aws_submodules
-
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
16 changed files
with
189 additions
and
5 deletions.
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,5 +1,5 @@ | ||
| # Versions | ||
|
|
||
| * v1.0.0 -- {{ yyyy-mm-dd }} | ||
| - initial creation | ||
| * 1.0.0 -- 2023-03-24 | ||
| - initial creation with cname | ||
|
|
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 @@ | ||
| ../common/availabilty_zones.tf |
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 @@ | ||
| ../common/data.tf |
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 @@ | ||
| ../common/defaults.tf |
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 { | ||
| account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id | ||
| account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew" | ||
|
|
||
| base_tags = { | ||
| "boc:tf_module_version" = local._module_version | ||
| "boc:created_by" = "terraform" | ||
| } | ||
| } | ||
|
|
||
| locals { | ||
| name_parts = split(".", var.name) | ||
| host_name = var.name_parts[0] | ||
| zone = trimprefix(var.name, format("%v.", local.host_name)) | ||
| private_zone = local.account_environment == "gov" ? true : var.private_zone | ||
| rr_type = uppercase(var.type) | ||
| default_enable_ptr = lookup(local._defaults.enable_ptr, var.type, false) | ||
| default_heritage_prefix = lookup(local._defaults.heritage_prefix, var.type, "") != "" ? format("%v.", lookup(local._defaults.heritage_prefix, var.type)) : "" | ||
| is_cname = var.type == "cname" | ||
| base_heritage_tags = [ | ||
| format("heritage=%v", local._defaults.heritage_label), | ||
| format("%v/account_id=%v", local._defaults.heritage_label, data.aws_caller_identity.current.account_id), | ||
| format("%v/region=%v", local._defaults.heritage_label, local.region), | ||
| format("%v/create_time=%d", local._defaults.heritage_label, time_static.timestamp.unix) | ||
| ] | ||
| heritage_tags = [for k, v in var.heritage_tags : format("%v/%v", local._defaults.heritage_label, k)] | ||
| } | ||
|
|
||
|
|
||
| # if the zone grab fails here, it either doesn't exist or it is not associated with this VPC | ||
| data "aws_route53_zone" "zone" { | ||
| name = local.zone | ||
| private_zone = local.private_zone | ||
| } | ||
|
|
||
| resource "time_static" "timestamp" {} | ||
|
|
||
| resource "aws_route53_record" "entry" { | ||
| count = local.is_cname ? 1 : 0 | ||
| zone_id = data.aws_route53_zone.zone.zone_id | ||
| name = var.name | ||
| type = local.rr_type | ||
| ttl = var.ttl | ||
| records = var.values | ||
| } | ||
|
|
||
|
|
||
| resource "aws_route53_record" "entry_heritage" { | ||
| count = var.enable_heritage ? 1 : 0 | ||
| zone_id = data.aws_route53_zone.zone.zone_id | ||
| name = format("%v%v", aws_route53_record.entry.name) | ||
|
|
||
| type = "TXT" | ||
| ttl = var.ttl | ||
| records = [join(",", concat(local.base_heritage_tags, local.heritage_tags))] | ||
| } |
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 @@ | ||
| ../common/prefixes.tf |
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 @@ | ||
| ../common/variables.common.availability_zones.tf |
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 @@ | ||
| ../common/variables.common.tf |
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 @@ | ||
| ../common/variables.tf |
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 @@ | ||
| ../common/version.tf |
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 @@ | ||
| ../common/versions.tf |
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,4 +1,21 @@ | ||
| locals { | ||
| _defaults = { | ||
| enable_ptr = { | ||
| cname = false | ||
| a = false | ||
| aaaa = false | ||
| txt = false | ||
| host = true | ||
| ptr = true | ||
| } | ||
| heritage_label = "terraform" | ||
| heritage_prefix = { | ||
| cname = "_txt" | ||
| a = "" | ||
| aaaa = "" | ||
| txt = "_txt" | ||
| host = "" | ||
| ptr = "" | ||
| } | ||
| } | ||
| } |
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,46 @@ | ||
| data "aws_route53_zone" "lakefront" { | ||
| name = var.vpc_domain_name | ||
| private_zone = true | ||
| } | ||
|
|
||
| resource "aws_route53_record" "lakefront_cname" { | ||
| zone_id = data.aws_route53_zone.lakefront.zone_id | ||
| name = format("%v.%v", local.app_shortname, data.aws_route53_zone.lakefront.name) | ||
| type = "CNAME" | ||
| ttl = "900" | ||
| records = [format("%v.execute-api.%v.amazonaws.com", data.aws_api_gateway_rest_api.lakefront.id, local.region)] | ||
| } | ||
|
|
||
| resource "time_static" "lakefront_txt" {} | ||
|
|
||
| resource "aws_route53_record" "lakefront_txt" { | ||
| zone_id = data.aws_route53_zone.lakefront.zone_id | ||
| name = format("_txt.%v", aws_route53_record.lakefront_cname.name) | ||
|
|
||
| type = "TXT" | ||
| ttl = "900" | ||
| records = [format("heritage=terraform,terraform/account_id=%v,terraform/region=%v,terraform/terraform/create_time=%d", | ||
| data.aws_caller_identity.current.account_id, local.region, time_static.lakefront_txt.unix)] | ||
| } | ||
|
|
||
| variable "zone" { | ||
| description = "DNS Zone into which to create the record. By default, it will extract this from the name" | ||
| type = string | ||
| default = null | ||
| } | ||
|
|
||
| variable "name" { | ||
| description = "FQDN DNS name to create. If the zone (everything after the first dot) does not exist or is not associated to the VPC, this creation will fail." | ||
| type = string | ||
| } | ||
|
|
||
| variable "record_type" { | ||
| description = "Type of DNS record to create: cname, a, aaaa, ptr, txt, host (ptr and a and/or aaaa)" | ||
| type = string | ||
| default = "host" | ||
|
|
||
| validation { | ||
| condition = contains(["cname", "a", "aaaa", "ptr", "txt", "host"], lowercase(var.record_type)) | ||
| error_message = "The record type must be one of: cname, a, aaaa, ptr, txt, or host" | ||
| } | ||
| } |
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 @@ | ||
| # variable "zone" { | ||
| # description = "DNS Zone into which to create the record. By default, it will extract this from the name" | ||
| # type = string | ||
| # default = null | ||
| # } | ||
|
|
||
| variable "name" { | ||
| description = "FQDN DNS name to create. If the zone (everything after the first dot) does not exist or is not associated to the VPC, this creation will fail." | ||
| type = string | ||
|
|
||
| validation { | ||
| condition = length(split(".", var.name)) > 1 | ||
| error_message = "Invalid name, must use FQDN with a hostname and domain name" | ||
| } | ||
| } | ||
|
|
||
| variable "record_type" { | ||
| description = "Type of DNS record to create: cname, a, aaaa, ptr, txt, host (ptr and a and/or aaaa)" | ||
| type = string | ||
| default = "host" | ||
|
|
||
| validation { | ||
| condition = contains(["cname", "a", "aaaa", "ptr", "txt", "host"], var.record_type) | ||
| error_message = "The record type must be one of: cname, a, aaaa, ptr, txt, or host" | ||
| } | ||
| } | ||
|
|
||
| variable "enable_ptr" { | ||
| description = "Flag to enable or disable creation of a PTR record. Used for type ptr and host" | ||
| type = bool | ||
| default = null | ||
| } | ||
|
|
||
| variable "enable_heritage" { | ||
| description = "Flag to enable or disable creation a TXT record for heritage. For CNAMEs, it uses a prefix of _txt on the name" | ||
| type = bool | ||
| default = true | ||
| } | ||
|
|
||
| variable "heritage_tags" { | ||
| description = "Map of key/value pairs to set into the heritage. These should be static so as not to update the heritage TXT record frequently" | ||
| type = map(string) | ||
| default = {} | ||
| } | ||
|
|
||
| variable "private_zone" { | ||
| description = "Flag indicating public or private zone. Assumes private by default, and can set public only for non-gov region" | ||
| type = bool | ||
| default = true | ||
| } | ||
|
|
||
| variable "ttl" { | ||
| description = "DNS RR Time To Live (ttl). Default 900s (15m)." | ||
| type = number | ||
| default = 900 | ||
| } |
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,3 +1,3 @@ | ||
| locals { | ||
| _module_version = "0.0.0" | ||
| _module_version = "1.0.0" | ||
| } |
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,9 +1,9 @@ | ||
| terraform { | ||
| required_version = ">= 1.0" | ||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = ">= 3.66.0" | ||
| version = ">= 4" | ||
| } | ||
| } | ||
| # required_version = ">= 0.13" | ||
| } |