Skip to content

Commit

Permalink
add a, aaaa and host
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Mar 24, 2023
1 parent c5063ef commit cd78240
Show file tree
Hide file tree
Showing 68 changed files with 888 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
* 1.0.0 -- 2023-03-24
- initial creation with cname

* 1.0.1 -- 2023-03-24
- create new submodules: a, aaaa, host
44 changes: 44 additions & 0 deletions a/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 97 additions & 0 deletions a/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# About

This submodule creates an A (IPv4) entry of the fully qualified domain name (FQDN) selected in `name`. The zone
is calculcated by splitting after the first dot. If the zone does not exist in Route 53, and the zone is not associated
with the VPC in which this is executed, you will get an error such as this:

```script
Error: no matching Route53Zone found
with module.lakefront_cname_test.data.aws_route53_zone.zone,
on .terraform/modules/lakefront_cname_test/cname/zone_forward.tf line 2, in data "aws_route53_zone" "zone":
2: data "aws_route53_zone" "zone" {
```

You will need to either fix the domain name (zone) or request the VPC have access to the zone. Generally speaking,
all zones where DNS entries are permitted are already associated with the appropriate VPCs. Under normal conditions,
you will want to use the `var.vpc_domain_name` (from the shared parent VPC), or from a `data` resource (see [example](#using-dhcp-options-data-resource)).

The record(s) created use a default TTL of 900. You may change this with the `ttl` option.

This also creates what we call a heritage record. This is an indication of _what_ thing created the record, and when. It is added by
the dynamic route53 Lambdas for EC2 instances, and within this module, it uses its own details.

The record looks like:

```console
% dig +short in txt EXAMPLE
```

## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4 |
| <a name="requirement_time"></a> [time](#requirement\_time) | >= 0.9.1 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.60.0 |
| <a name="provider_time"></a> [time](#provider\_time) | 0.9.1 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_entry_ip_addresses"></a> [entry\_ip\_addresses](#module\_entry\_ip\_addresses) | git@github.e.it.census.gov:terraform-modules/dns-lookup.git | tf-upgrade |

## Resources

| Name | Type |
|------|------|
| [aws_route53_record.entry](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.entry_heritage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.entry_ipv4_ptr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.entry_ipv4_ptr_heritage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.entry_ipv6_ptr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.entry_ipv6_ptr_heritage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [time_static.timestamp](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/static) | resource |
| [aws_arn.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/arn) | data source |
| [aws_availability_zone.zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zone) | data source |
| [aws_availability_zones.zones](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
| [aws_route53_zone.ipv4_ptr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
| [aws_route53_zone.ipv6_ptr](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
| [aws_route53_zone.zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_alias"></a> [account\_alias](#input\_account\_alias) | AWS Account Alias | `string` | `""` | no |
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | AWS Account ID (default will pull from current user) | `string` | `""` | no |
| <a name="input_availability_zones"></a> [availability\_zones](#input\_availability\_zones) | AWS Availability Zones to use (by default will use all available) | `list(string)` | `[]` | no |
| <a name="input_enable_heritage"></a> [enable\_heritage](#input\_enable\_heritage) | Flag to enable or disable creation a TXT record for heritage. For CNAMEs, it uses a prefix of \_txt on the name | `bool` | `true` | no |
| <a name="input_enable_ptr"></a> [enable\_ptr](#input\_enable\_ptr) | Flag to enable or disable creation of a PTR record. Used for type ptr and host | `bool` | `null` | no |
| <a name="input_heritage_tags"></a> [heritage\_tags](#input\_heritage\_tags) | Map of key/value pairs to set into the heritage. These should be static so as not to update the heritage TXT record frequently | `map(string)` | `{}` | no |
| <a name="input_name"></a> [name](#input\_name) | 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. | `string` | n/a | yes |
| <a name="input_override_prefixes"></a> [override\_prefixes](#input\_override\_prefixes) | Override built-in prefixes by component. This should be used primarily for common infrastructure things | `map(string)` | `{}` | no |
| <a name="input_private_zone"></a> [private\_zone](#input\_private\_zone) | Flag indicating public or private zone. Assumes private by default, and can set public only for non-gov region | `bool` | `true` | no |
| <a name="input_record_type"></a> [record\_type](#input\_record\_type) | Type of DNS record to create: cname, a, aaaa, ptr, txt, host (ptr and a and/or aaaa) | `string` | `"host"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | AWS Tags to apply to appropriate resources | `map(string)` | `{}` | no |
| <a name="input_ttl"></a> [ttl](#input\_ttl) | DNS RR Time To Live (ttl). Default 900s (15m). | `number` | `900` | no |
| <a name="input_values"></a> [values](#input\_values) | DNS value to set for the name. May be a string or list of strings (like multiple IP addresses) | `any` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_availability_zone_ids"></a> [availability\_zone\_ids](#output\_availability\_zone\_ids) | VPC Availability zone id list |
| <a name="output_availability_zone_names"></a> [availability\_zone\_names](#output\_availability\_zone\_names) | VPC Availability zone name list |
| <a name="output_availability_zone_suffixes"></a> [availability\_zone\_suffixes](#output\_availability\_zone\_suffixes) | VPC Availability zone suffix list |
| <a name="output_heritage_name"></a> [heritage\_name](#output\_heritage\_name) | DNS Name created for the heritage record, if enabled |
| <a name="output_name"></a> [name](#output\_name) | DNS Name created (same as what was provided) |
1 change: 1 addition & 0 deletions a/availabilty_zones.tf
1 change: 1 addition & 0 deletions a/common.tf
1 change: 1 addition & 0 deletions a/data.tf
1 change: 1 addition & 0 deletions a/defaults.tf
1 change: 1 addition & 0 deletions a/entry.tf
1 change: 1 addition & 0 deletions a/entry_heritage.tf
1 change: 1 addition & 0 deletions a/entry_ptr.tf
1 change: 1 addition & 0 deletions a/entry_ptr_heritage.tf
1 change: 1 addition & 0 deletions a/heritage_tags.tf
89 changes: 89 additions & 0 deletions a/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* aws-dns :: a
* # About
*
* This submodule creates an A (IPv4) entry of the fully qualified domain name (FQDN) selected in `name`. The zone
* is calculcated by splitting after the first dot. If the zone does not exist in Route 53, and the zone is not associated
* with the VPC in which this is executed, you will get an error such as this:
*
* ```script
* Error: no matching Route53Zone found
*
* with module.lakefront_cname_test.data.aws_route53_zone.zone,
* on .terraform/modules/lakefront_cname_test/cname/zone_forward.tf line 2, in data "aws_route53_zone" "zone":
* 2: data "aws_route53_zone" "zone" {
* ```
*
* You will need to either fix the domain name (zone) or request the VPC have access to the zone. Generally speaking,
* all zones where DNS entries are permitted are already associated with the appropriate VPCs. Under normal conditions,
* you will want to use the `var.vpc_domain_name` (from the shared parent VPC), or from a `data` resource (see [example](#using-dhcp-options-data-resource)).
*
* The record(s) created use a default TTL of 900. You may change this with the `ttl` option.
*
* This also creates what we call a heritage record. This is an indication of _what_ thing created the record, and when. It is added by
* the dynamic route53 Lambdas for EC2 instances, and within this module, it uses its own details.
*
* The record looks like:
*
* ```console
* % dig +short in txt EXAMPLE
EXAMPLE> 900 IN TXT "heritage=terraform,terraform/account_id=818199694861,terraform/region=us-gov-west-1,terraform/create_time=1679501130"
* ```
*
* The fields/key-value pairs are
*
* | name | description |
* |------|-------------|
* | heritage=terraform | primary label indicating all other values will be use _terraform_/ as a prefix |
* | {label}/{key}={value} | label (above); key and value (below) |
* | account_id | AWS Account ID |
* | region | AWS Region where this has been created |
* | create_time | Unix epoch time on creation of this and the associated record |
*
* You may add additional values here, such as an ALB ID or other useful, short values which do not change, in the `heritage_tags` map:
*
* ```hcl
* heritage_tags = {
* alb_id = aws_lb.my_lb.id
* }
* ```
*
* Be sure not to use an ARN as a value, and avoid values which change frequently.
*
* # Caveats
* ## Simple, using vpc_domain_name from parent
*
* ```hcl
* module "lakefront_cname" {
* source = "git@github.e.it.census.gov:terraform-modules/aws-dns//cname"
*
* name = format("%v.%v", local.app_shortname, var.vpc_domain_name)
* values = format("%v.execute-api.%v.amazonaws.com", data.aws_api_gateway_rest_api.lakefront.id, local.region)
* }
* ```
*
# ## Using DHCP options data resource
*
* data "aws_vpc_dhcp_options" "options" {
* filter {
* name = "vpc-id"
* values = [local.vpc_id]
* }
* }
*
* module "stat_cname"
* {
* source  = "git@github.e.it.census.gov:terraform-modules/aws-dns//cname"
* name    = format("%v.%v","stat",data.aws_vpc_dhc_options.options.domain_name)
* values  = aws_lb.adsd_dapps_dev_stat_lb.dns_name
* }
* ```
*
*/

locals {
record_type = "a"
# values = [local.default_values[0]]
ipv4_hosts = [for h in local.default_values : h if length(regexall("\\.", h)) == 3 && ! can(regex("/", h))]
ipv6_hosts = [for h in local.default_values : h if length(regexall(":", h)) != 0 && ! can(regex("/", h))]
values = local.ipv4_hosts
}
9 changes: 9 additions & 0 deletions a/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
output "name" {
description = "DNS Name created (same as what was provided)"
value = var.name
}

output "heritage_name" {
description = "DNS Name created for the heritage record, if enabled"
value = try(aws_route53_record.entry_heritage[0].name, null)
}
1 change: 1 addition & 0 deletions a/prefixes.tf
1 change: 1 addition & 0 deletions a/variables.common.availability_zones.tf
1 change: 1 addition & 0 deletions a/variables.common.tf
1 change: 1 addition & 0 deletions a/variables.tf
1 change: 1 addition & 0 deletions a/version.tf
1 change: 1 addition & 0 deletions a/versions.tf
4 changes: 4 additions & 0 deletions a/x
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
../common/entry_heritage.tf
../common/entry.tf
../common/heritage_tags.tf
../common/zone_forward.tf
1 change: 1 addition & 0 deletions a/zone_forward.tf
44 changes: 44 additions & 0 deletions aaaa/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd78240

Please sign in to comment.