Skip to content

Commit bcd2fdb

Browse files
feat: Allow hosted zone name to be passed in separately (#119)
1 parent 881eacd commit bcd2fdb

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ This will create records that allow users to access the API Gateway using the fo
120120
- `customer1.mydomain.com`
121121
- `customer2.mydomain.com`
122122

123+
## Specific Hosted Zone
124+
125+
If you want to create the domain name in a specific hosted zone, you can use the `hosted_zone_name` input parameter:
126+
127+
```hcl
128+
module "api_gateway" {
129+
source = "terraform-aws-modules/apigateway-v2/aws"
130+
131+
...
132+
hosted_zone_name = "api.mydomain.com"
133+
domain_name = "prod.api.mydomain.com"
134+
...
135+
}
136+
```
137+
123138
## Conditional Creation
124139

125140
The following values are provided to toggle on/off creation of the associated resources as desired:
@@ -219,6 +234,7 @@ module "api_gateway" {
219234
| <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 |
220235
| <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 |
221236
| <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 |
237+
| <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 |
222238
| <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 |
223239
| <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 |
224240
| <a name="input_protocol_type"></a> [protocol\_type](#input\_protocol\_type) | The API protocol. Valid values: `HTTP`, `WEBSOCKET` | `string` | `"HTTP"` | no |

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ locals {
134134
data "aws_route53_zone" "this" {
135135
count = local.create_domain_name && var.create_domain_records ? 1 : 0
136136

137-
name = local.stripped_domain_name
137+
name = coalesce(var.hosted_zone_name, local.stripped_domain_name)
138138
}
139139

140140
resource "aws_route53_record" "this" {

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ variable "domain_name" {
144144
default = ""
145145
}
146146

147+
variable "hosted_zone_name" {
148+
description = "Optional domain name of the Hosted Zone where the domain should be created"
149+
type = string
150+
default = null
151+
}
152+
147153
variable "domain_name_certificate_arn" {
148154
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"
149155
type = string

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module "wrapper" {
2323
domain_name_certificate_arn = try(each.value.domain_name_certificate_arn, var.defaults.domain_name_certificate_arn, null)
2424
domain_name_ownership_verification_certificate_arn = try(each.value.domain_name_ownership_verification_certificate_arn, var.defaults.domain_name_ownership_verification_certificate_arn, null)
2525
fail_on_warnings = try(each.value.fail_on_warnings, var.defaults.fail_on_warnings, null)
26+
hosted_zone_name = try(each.value.hosted_zone_name, var.defaults.hosted_zone_name, null)
2627
mutual_tls_authentication = try(each.value.mutual_tls_authentication, var.defaults.mutual_tls_authentication, {})
2728
name = try(each.value.name, var.defaults.name, "")
2829
protocol_type = try(each.value.protocol_type, var.defaults.protocol_type, "HTTP")

0 commit comments

Comments
 (0)