From 0f81fc967040b54f5230357bfd6ecfd11a662eb5 Mon Sep 17 00:00:00 2001 From: Mateusz Jenek Date: Mon, 5 Feb 2024 16:40:43 +0300 Subject: [PATCH] resolve discussions --- examples/route53/README.md | 42 +++++++++++++ examples/route53/main.tf | 31 ++++++++++ examples/route53/providers.tf | 12 ++++ examples/route53/terraform.tfvars.example | 30 ++++++++++ examples/route53/variables.tf | 60 +++++++++++++++++++ .../route53/basic/README.md | 37 ++++++++++++ .../route53/{ => basic}/main.tf | 19 +++--- .../route53/{ => basic}/outputs.tf | 0 .../route53/{ => basic}/providers.tf | 0 .../route53/basic/terraform.tfvars.example | 33 ++++++++++ .../route53/basic/variables.tf | 59 ++++++++++++++++++ humanitec-resource-defs/route53/variables.tf | 35 ----------- modules/route53/basic/README.md | 43 +++++++++++++ modules/route53/basic/main.tf | 27 +++++++++ modules/route53/{ => basic}/outputs.tf | 0 modules/route53/{ => basic}/providers.tf | 2 + .../route53/basic/terraform.tfvars.example | 29 +++++++++ modules/route53/basic/variables.tf | 55 +++++++++++++++++ modules/route53/main.tf | 11 ---- modules/route53/variables.tf | 31 ---------- 20 files changed, 471 insertions(+), 85 deletions(-) create mode 100644 examples/route53/README.md create mode 100644 examples/route53/main.tf create mode 100644 examples/route53/providers.tf create mode 100644 examples/route53/terraform.tfvars.example create mode 100644 examples/route53/variables.tf create mode 100644 humanitec-resource-defs/route53/basic/README.md rename humanitec-resource-defs/route53/{ => basic}/main.tf (53%) rename humanitec-resource-defs/route53/{ => basic}/outputs.tf (100%) rename humanitec-resource-defs/route53/{ => basic}/providers.tf (100%) create mode 100644 humanitec-resource-defs/route53/basic/terraform.tfvars.example create mode 100644 humanitec-resource-defs/route53/basic/variables.tf delete mode 100644 humanitec-resource-defs/route53/variables.tf create mode 100644 modules/route53/basic/README.md create mode 100644 modules/route53/basic/main.tf rename modules/route53/{ => basic}/outputs.tf (100%) rename modules/route53/{ => basic}/providers.tf (86%) create mode 100644 modules/route53/basic/terraform.tfvars.example create mode 100644 modules/route53/basic/variables.tf delete mode 100644 modules/route53/main.tf delete mode 100644 modules/route53/variables.tf diff --git a/examples/route53/README.md b/examples/route53/README.md new file mode 100644 index 0000000..b60dfb5 --- /dev/null +++ b/examples/route53/README.md @@ -0,0 +1,42 @@ + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 1.3.0 | +| humanitec | ~> 0 | + +## Providers + +| Name | Version | +|------|---------| +| humanitec | ~> 0 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| route53 | ../../humanitec-resource-defs/route53/basic | n/a | + +## Resources + +| Name | Type | +|------|------| +| [humanitec_application.example](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/application) | resource | +| [humanitec_resource_definition_criteria.redis](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition_criteria) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| access\_key | AWS Access Key | `string` | n/a | yes | +| hosted\_zone | The name of the hosted zone in which this record set will reside. | `string` | n/a | yes | +| region | AWS Region | `string` | n/a | yes | +| secret\_key | AWS Secret Key | `string` | n/a | yes | +| subdomain | The subdomain of the DNS name that the DNS record is for. | `string` | n/a | yes | +| ip\_address | The IPv4 address that the DNS name should resolve to. | `string` | `""` | no | +| ipv6\_address | The IPv6 address that the DNS name should resolve to. | `string` | `""` | no | +| name | A valid fully qualified domain name that the DNS name should resolve to. | `string` | `""` | no | +| resource\_packs\_aws\_rev | AWS Resource Pack git branch | `string` | `"refs/heads/main"` | no | +| resource\_packs\_aws\_url | AWS Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-aws.git"` | no | + \ No newline at end of file diff --git a/examples/route53/main.tf b/examples/route53/main.tf new file mode 100644 index 0000000..a5997b6 --- /dev/null +++ b/examples/route53/main.tf @@ -0,0 +1,31 @@ +locals { + res_def_prefix = "${var.name}-" +} + +resource "humanitec_application" "example" { + id = var.name + name = var.name +} + +module "route53" { + source = "../../humanitec-resource-defs/route53/basic" + + access_key = var.access_key + secret_key = var.secret_key + resource_packs_aws_url = var.resource_packs_aws_url + resource_packs_aws_rev = var.resource_packs_aws_rev + region = var.region + + prefix = local.res_def_prefix + + hosted_zone = var.hosted_zone + subdomain = var.subdomain + ip_address = var.ip_address + ipv6_address = var.ipv6_address + name = var.domain_name +} + +resource "humanitec_resource_definition_criteria" "redis" { + resource_definition_id = module.route53.id + app_id = humanitec_application.example.id +} diff --git a/examples/route53/providers.tf b/examples/route53/providers.tf new file mode 100644 index 0000000..53e6404 --- /dev/null +++ b/examples/route53/providers.tf @@ -0,0 +1,12 @@ +terraform { + required_providers { + humanitec = { + source = "humanitec/humanitec" + version = "~> 0" + } + } + + required_version = ">= 1.3.0" +} + +provider "humanitec" {} diff --git a/examples/route53/terraform.tfvars.example b/examples/route53/terraform.tfvars.example new file mode 100644 index 0000000..a7eaf2f --- /dev/null +++ b/examples/route53/terraform.tfvars.example @@ -0,0 +1,30 @@ + +# AWS Access Key +access_key = "" + +# The name of the hosted zone in which this record set will reside. +hosted_zone = "" + +# The IPv4 address that the DNS name should resolve to. +ip_address = "" + +# The IPv6 address that the DNS name should resolve to. +ipv6_address = "" + +# A valid fully qualified domain name that the DNS name should resolve to. +name = "" + +# AWS Region +region = "" + +# AWS Resource Pack git branch +resource_packs_aws_rev = "refs/heads/main" + +# AWS Resource Pack git url +resource_packs_aws_url = "https://github.com/humanitec-architecture/resource-packs-aws.git" + +# AWS Secret Key +secret_key = "" + +# The subdomain of the DNS name that the DNS record is for. +subdomain = "" \ No newline at end of file diff --git a/examples/route53/variables.tf b/examples/route53/variables.tf new file mode 100644 index 0000000..25e6354 --- /dev/null +++ b/examples/route53/variables.tf @@ -0,0 +1,60 @@ +variable "access_key" { + description = "AWS Access Key" + type = string +} + +variable "secret_key" { + description = "AWS Secret Key" + type = string +} + +variable "region" { + description = "AWS Region" + type = string +} + +variable "resource_packs_aws_url" { + description = "AWS Resource Pack git url" + type = string + default = "https://github.com/humanitec-architecture/resource-packs-aws.git" +} + +variable "resource_packs_aws_rev" { + description = "AWS Resource Pack git branch" + type = string + default = "refs/heads/main" +} + +variable "name" { + description = "Name of the example application" + type = string + default = "route53-test" +} + +variable "hosted_zone" { + description = "The name of the hosted zone in which this record set will reside." + type = string +} + +variable "subdomain" { + description = "The subdomain of the DNS name that the DNS record is for." + type = string +} + +variable "ip_address" { + description = "The IPv4 address that the DNS name should resolve to." + type = string + default = "" +} + +variable "ipv6_address" { + description = "The IPv6 address that the DNS name should resolve to." + type = string + default = "" +} + +variable "domain_name" { + description = "A valid fully qualified domain name that the DNS name should resolve to." + type = string + default = "" +} \ No newline at end of file diff --git a/humanitec-resource-defs/route53/basic/README.md b/humanitec-resource-defs/route53/basic/README.md new file mode 100644 index 0000000..5cbc4e1 --- /dev/null +++ b/humanitec-resource-defs/route53/basic/README.md @@ -0,0 +1,37 @@ + + + +## Providers + +| Name | Version | +|------|---------| +| humanitec | n/a | + +## Resources + +| Name | Type | +|------|------| +| [humanitec_resource_definition.main](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs/resources/resource_definition) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| access\_key | AWS Access Key | `string` | n/a | yes | +| hosted\_zone | The name of the hosted zone in which this record set will reside. | `string` | n/a | yes | +| prefix | Prefix for all resources | `string` | n/a | yes | +| region | AWS Region | `string` | n/a | yes | +| secret\_key | AWS Secret Key | `string` | n/a | yes | +| subdomain | The subdomain of the DNS name that the DNS record is for. | `string` | n/a | yes | +| ip\_address | The IPv4 address that the DNS name should resolve to. | `string` | `""` | no | +| ipv6\_address | The IPv6 address that the DNS name should resolve to. | `string` | `""` | no | +| name | A valid fully qualified domain name that the DNS name should resolve to. | `string` | `""` | no | +| resource\_packs\_aws\_rev | AWS Resource Pack git branch | `string` | `"refs/heads/main"` | no | +| resource\_packs\_aws\_url | AWS Resource Pack git url | `string` | `"https://github.com/humanitec-architecture/resource-packs-aws.git"` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| id | n/a | + \ No newline at end of file diff --git a/humanitec-resource-defs/route53/main.tf b/humanitec-resource-defs/route53/basic/main.tf similarity index 53% rename from humanitec-resource-defs/route53/main.tf rename to humanitec-resource-defs/route53/basic/main.tf index c6c23db..3b3692b 100644 --- a/humanitec-resource-defs/route53/main.tf +++ b/humanitec-resource-defs/route53/basic/main.tf @@ -14,18 +14,21 @@ resource "humanitec_resource_definition" "main" { values_string = jsonencode({ source = { - path = "modules/route53" + path = "modules/route53/basic" rev = var.resource_packs_aws_rev - url = "https://github.com/humanitec-architecture/resource-packs-aws.git" + url = var.resource_packs_aws_url } variables = { - region = var.region - res_id = "$${context.res.id}" - dns_zone = var.dns_zone - dns_name = var.dns_name - dns_type = var.dns_type - dns_ttl = var.dns_ttl + region = var.region + res_id = "$${context.res.id}" + app_id = "$${context.app.id}" + env_id = "$${context.env.id}" + hosted_zone = var.hosted_zone + subdomain = var.subdomain + ip_address = var.ip_address + ipv6_address = var.ipv6_address + name = var.name } }) } diff --git a/humanitec-resource-defs/route53/outputs.tf b/humanitec-resource-defs/route53/basic/outputs.tf similarity index 100% rename from humanitec-resource-defs/route53/outputs.tf rename to humanitec-resource-defs/route53/basic/outputs.tf diff --git a/humanitec-resource-defs/route53/providers.tf b/humanitec-resource-defs/route53/basic/providers.tf similarity index 100% rename from humanitec-resource-defs/route53/providers.tf rename to humanitec-resource-defs/route53/basic/providers.tf diff --git a/humanitec-resource-defs/route53/basic/terraform.tfvars.example b/humanitec-resource-defs/route53/basic/terraform.tfvars.example new file mode 100644 index 0000000..e1f7430 --- /dev/null +++ b/humanitec-resource-defs/route53/basic/terraform.tfvars.example @@ -0,0 +1,33 @@ + +# AWS Access Key +access_key = "" + +# The name of the hosted zone in which this record set will reside. +hosted_zone = "" + +# The IPv4 address that the DNS name should resolve to. +ip_address = "" + +# The IPv6 address that the DNS name should resolve to. +ipv6_address = "" + +# A valid fully qualified domain name that the DNS name should resolve to. +name = "" + +# Prefix for all resources +prefix = "" + +# AWS Region +region = "" + +# AWS Resource Pack git branch +resource_packs_aws_rev = "refs/heads/main" + +# AWS Resource Pack git url +resource_packs_aws_url = "https://github.com/humanitec-architecture/resource-packs-aws.git" + +# AWS Secret Key +secret_key = "" + +# The subdomain of the DNS name that the DNS record is for. +subdomain = "" \ No newline at end of file diff --git a/humanitec-resource-defs/route53/basic/variables.tf b/humanitec-resource-defs/route53/basic/variables.tf new file mode 100644 index 0000000..0ab4d79 --- /dev/null +++ b/humanitec-resource-defs/route53/basic/variables.tf @@ -0,0 +1,59 @@ +variable "prefix" { + description = "Prefix for all resources" + type = string +} + +variable "resource_packs_aws_url" { + description = "AWS Resource Pack git url" + type = string + default = "https://github.com/humanitec-architecture/resource-packs-aws.git" +} + +variable "resource_packs_aws_rev" { + description = "AWS Resource Pack git branch" + type = string + default = "refs/heads/main" +} + +variable "access_key" { + description = "AWS Access Key" + type = string +} + +variable "secret_key" { + description = "AWS Secret Key" + type = string +} + +variable "region" { + description = "AWS Region" + type = string +} + +variable "hosted_zone" { + description = "The name of the hosted zone in which this record set will reside." + type = string +} + +variable "subdomain" { + description = "The subdomain of the DNS name that the DNS record is for." + type = string +} + +variable "ip_address" { + description = "The IPv4 address that the DNS name should resolve to." + type = string + default = "" +} + +variable "ipv6_address" { + description = "The IPv6 address that the DNS name should resolve to." + type = string + default = "" +} + +variable "name" { + description = "A valid fully qualified domain name that the DNS name should resolve to." + type = string + default = "" +} diff --git a/humanitec-resource-defs/route53/variables.tf b/humanitec-resource-defs/route53/variables.tf deleted file mode 100644 index 4511010..0000000 --- a/humanitec-resource-defs/route53/variables.tf +++ /dev/null @@ -1,35 +0,0 @@ -variable "prefix" { - type = string -} - -variable "resource_packs_aws_rev" { - type = string -} - -variable "access_key" { - type = string -} - -variable "secret_key" { - type = string -} - -variable "region" { - type = string -} - -variable "dns_zone" { - type = string -} - -variable "dns_name" { - type = string -} - -variable "dns_type" { - type = string -} - -variable "dns_ttl" { - type = string -} diff --git a/modules/route53/basic/README.md b/modules/route53/basic/README.md new file mode 100644 index 0000000..1fe2b2f --- /dev/null +++ b/modules/route53/basic/README.md @@ -0,0 +1,43 @@ + +## Requirements + +| Name | Version | +|------|---------| +| terraform | >= 1.3.0 | +| aws | ~> 5.0 | + +## Providers + +| Name | Version | +|------|---------| +| aws | ~> 5.0 | + +## Resources + +| Name | Type | +|------|------| +| [aws_route53_record.record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource | +| [aws_route53_zone.hosted_zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| access\_key | AWS Access Key | `string` | n/a | yes | +| app\_id | n/a | `string` | n/a | yes | +| env\_id | n/a | `string` | n/a | yes | +| hosted\_zone | The name of the hosted zone in which this record set will reside. | `string` | n/a | yes | +| region | AWS Region | `string` | n/a | yes | +| res\_id | n/a | `string` | n/a | yes | +| secret\_key | AWS Secret Key | `string` | n/a | yes | +| subdomain | The subdomain of the DNS name that the DNS record is for. | `string` | n/a | yes | +| ip\_address | The IPv4 address that the DNS name should resolve to. | `string` | `""` | no | +| ipv6\_address | The IPv6 address that the DNS name should resolve to. | `string` | `""` | no | +| name | A valid fully qualified domain name that the DNS name should resolve to. | `string` | `""` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| host | n/a | + \ No newline at end of file diff --git a/modules/route53/basic/main.tf b/modules/route53/basic/main.tf new file mode 100644 index 0000000..694606c --- /dev/null +++ b/modules/route53/basic/main.tf @@ -0,0 +1,27 @@ +locals { + types = ["A", "AAAA", "CNAME"] + provided_records = [var.ip_address, var.ipv6_address, var.name] + records = [for r in local.provided_records : r if r != ""] + + # If every record is empty, then the type is A, but this will be caught below. + type = local.types[index(local.provided_records, length(local.records) > 0 ? local.records[0] : "A")] +} + +data "aws_route53_zone" "hosted_zone" { + name = var.hosted_zone +} + +resource "aws_route53_record" "record" { + name = "${var.subdomain}.${var.hosted_zone}" + zone_id = data.aws_route53_zone.hosted_zone.id + type = local.type + ttl = 300 + records = local.records + + lifecycle { + precondition { + condition = length(local.records) > 1 + error_message = "Only one of ip_address, ipv6_address or name is supported." + } + } +} diff --git a/modules/route53/outputs.tf b/modules/route53/basic/outputs.tf similarity index 100% rename from modules/route53/outputs.tf rename to modules/route53/basic/outputs.tf diff --git a/modules/route53/providers.tf b/modules/route53/basic/providers.tf similarity index 86% rename from modules/route53/providers.tf rename to modules/route53/basic/providers.tf index fb50a1f..38763b0 100644 --- a/modules/route53/providers.tf +++ b/modules/route53/basic/providers.tf @@ -18,6 +18,8 @@ provider "aws" { default_tags { tags = { "managed-by" = "humanitec" + "hum-app-id" = var.app_id + "hum-env-id" = var.env_id "hum-res-id" = var.res_id } } diff --git a/modules/route53/basic/terraform.tfvars.example b/modules/route53/basic/terraform.tfvars.example new file mode 100644 index 0000000..0611a76 --- /dev/null +++ b/modules/route53/basic/terraform.tfvars.example @@ -0,0 +1,29 @@ + +# AWS Access Key +access_key = "" + +app_id = "" +env_id = "" + +# The name of the hosted zone in which this record set will reside. +hosted_zone = "" + +# The IPv4 address that the DNS name should resolve to. +ip_address = "" + +# The IPv6 address that the DNS name should resolve to. +ipv6_address = "" + +# A valid fully qualified domain name that the DNS name should resolve to. +name = "" + +# AWS Region +region = "" + +res_id = "" + +# AWS Secret Key +secret_key = "" + +# The subdomain of the DNS name that the DNS record is for. +subdomain = "" \ No newline at end of file diff --git a/modules/route53/basic/variables.tf b/modules/route53/basic/variables.tf new file mode 100644 index 0000000..95c0f35 --- /dev/null +++ b/modules/route53/basic/variables.tf @@ -0,0 +1,55 @@ + +variable "access_key" { + description = "AWS Access Key" + type = string +} + +variable "secret_key" { + description = "AWS Secret Key" + type = string +} + +variable "region" { + description = "AWS Region" + type = string +} + +variable "res_id" { + type = string +} + +variable "app_id" { + type = string +} + +variable "env_id" { + type = string +} + +variable "hosted_zone" { + description = "The name of the hosted zone in which this record set will reside." + type = string +} + +variable "subdomain" { + description = "The subdomain of the DNS name that the DNS record is for." + type = string +} + +variable "ip_address" { + description = "The IPv4 address that the DNS name should resolve to." + type = string + default = "" +} + +variable "ipv6_address" { + description = "The IPv6 address that the DNS name should resolve to." + type = string + default = "" +} + +variable "name" { + description = "A valid fully qualified domain name that the DNS name should resolve to." + type = string + default = "" +} \ No newline at end of file diff --git a/modules/route53/main.tf b/modules/route53/main.tf deleted file mode 100644 index c8db0bf..0000000 --- a/modules/route53/main.tf +++ /dev/null @@ -1,11 +0,0 @@ -resource "aws_route53_zone" "zone" { - name = var.dns_zone -} - -resource "aws_route53_record" "record" { - zone_id = aws_route53_zone.zone.zone_id - name = var.dns_name - type = var.dns_type - ttl = var.dns_ttl - records = aws_route53_zone.zone.name_servers -} diff --git a/modules/route53/variables.tf b/modules/route53/variables.tf deleted file mode 100644 index aa78130..0000000 --- a/modules/route53/variables.tf +++ /dev/null @@ -1,31 +0,0 @@ -variable "region" { - type = string -} - -variable "access_key" { - type = string -} - -variable "secret_key" { - type = string -} - -variable "res_id" { - type = string -} - -variable "dns_zone" { - type = string -} - -variable "dns_name" { - type = string -} - -variable "dns_type" { - type = string -} - -variable "dns_ttl" { - type = string -}