Skip to content

Commit

Permalink
feat: Allow hosted zone name to be passed in separately (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonnenpinguin authored Aug 26, 2024
1 parent 881eacd commit bcd2fdb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ This will create records that allow users to access the API Gateway using the fo
- `customer1.mydomain.com`
- `customer2.mydomain.com`

## Specific Hosted Zone

If you want to create the domain name in a specific hosted zone, you can use the `hosted_zone_name` input parameter:

```hcl
module "api_gateway" {
source = "terraform-aws-modules/apigateway-v2/aws"
...
hosted_zone_name = "api.mydomain.com"
domain_name = "prod.api.mydomain.com"
...
}
```

## Conditional Creation

The following values are provided to toggle on/off creation of the associated resources as desired:
Expand Down Expand Up @@ -219,6 +234,7 @@ module "api_gateway" {
| <a name="input_domain_name_certificate_arn"></a> [domain\_name\_certificate\_arn](#input\_domain\_name\_certificate\_arn) | The ARN of an AWS-managed certificate that will be used by the endpoint for the domain name. AWS Certificate Manager is the only supported source | `string` | `null` | no |
| <a name="input_domain_name_ownership_verification_certificate_arn"></a> [domain\_name\_ownership\_verification\_certificate\_arn](#input\_domain\_name\_ownership\_verification\_certificate\_arn) | ARN of the AWS-issued certificate used to validate custom domain ownership (when certificate\_arn is issued via an ACM Private CA or mutual\_tls\_authentication is configured with an ACM-imported certificate.) | `string` | `null` | no |
| <a name="input_fail_on_warnings"></a> [fail\_on\_warnings](#input\_fail\_on\_warnings) | Whether warnings should return an error while API Gateway is creating or updating the resource using an OpenAPI specification. Defaults to `false`. Applicable for HTTP APIs | `bool` | `null` | no |
| <a name="input_hosted_zone_name"></a> [hosted\_zone\_name](#input\_hosted\_zone\_name) | Optional domain name of the Hosted Zone where the domain should be created | `string` | `null` | no |
| <a name="input_mutual_tls_authentication"></a> [mutual\_tls\_authentication](#input\_mutual\_tls\_authentication) | The mutual TLS authentication configuration for the domain name | `map(string)` | `{}` | no |
| <a name="input_name"></a> [name](#input\_name) | The name of the API. Must be less than or equal to 128 characters in length | `string` | `""` | no |
| <a name="input_protocol_type"></a> [protocol\_type](#input\_protocol\_type) | The API protocol. Valid values: `HTTP`, `WEBSOCKET` | `string` | `"HTTP"` | no |
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ locals {
data "aws_route53_zone" "this" {
count = local.create_domain_name && var.create_domain_records ? 1 : 0

name = local.stripped_domain_name
name = coalesce(var.hosted_zone_name, local.stripped_domain_name)
}

resource "aws_route53_record" "this" {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ variable "domain_name" {
default = ""
}

variable "hosted_zone_name" {
description = "Optional domain name of the Hosted Zone where the domain should be created"
type = string
default = null
}

variable "domain_name_certificate_arn" {
description = "The ARN of an AWS-managed certificate that will be used by the endpoint for the domain name. AWS Certificate Manager is the only supported source"
type = string
Expand Down
1 change: 1 addition & 0 deletions wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module "wrapper" {
domain_name_certificate_arn = try(each.value.domain_name_certificate_arn, var.defaults.domain_name_certificate_arn, null)
domain_name_ownership_verification_certificate_arn = try(each.value.domain_name_ownership_verification_certificate_arn, var.defaults.domain_name_ownership_verification_certificate_arn, null)
fail_on_warnings = try(each.value.fail_on_warnings, var.defaults.fail_on_warnings, null)
hosted_zone_name = try(each.value.hosted_zone_name, var.defaults.hosted_zone_name, null)
mutual_tls_authentication = try(each.value.mutual_tls_authentication, var.defaults.mutual_tls_authentication, {})
name = try(each.value.name, var.defaults.name, "")
protocol_type = try(each.value.protocol_type, var.defaults.protocol_type, "HTTP")
Expand Down

0 comments on commit bcd2fdb

Please sign in to comment.