-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring the variables to map * Custom domain module added * pre-commit fixes * added example for variable * enforce TLS1.2 * tf fmt * pre-commit fixes * typo fixed and map updated * ACM Cert provisioning * remove the extra new line Co-authored-by: pre-commit <[email protected]>
- Loading branch information
Showing
9 changed files
with
204 additions
and
31 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
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,50 @@ | ||
# Custom domain name for API Gateway | ||
|
||
Provides custom domain name resource for the API Gateway and the mapping of domain name to the api. | ||
|
||
Supports only REGIONAL endpoint for now. | ||
|
||
Provisions option to create ACM certifcation. Cert validation needs to be done offline. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.13.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_acm_certificate.cert](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate) | resource | | ||
| [aws_api_gateway_base_path_mapping.mapping](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_base_path_mapping) | resource | | ||
| [aws_api_gateway_domain_name.domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_domain_name) | resource | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_cert_arn"></a> [cert\_arn](#input\_cert\_arn) | Cert ARN. Create ACM cert. create\_acm\_cert and cert\_arn Mutually exclusive. | `string` | `""` | no | | ||
| <a name="input_create_acm_cert"></a> [create\_acm\_cert](#input\_create\_acm\_cert) | Create ACM cert. create\_acm\_cert and cert\_arn Mutually exclusive. | `bool` | `false` | no | | ||
| <a name="input_domain_name"></a> [domain\_name](#input\_domain\_name) | Custom domain name | `string` | n/a | yes | | ||
| <a name="input_path_mappings"></a> [path\_mappings](#input\_path\_mappings) | List of stages the usage plan can be used | <pre>map(<br> object({<br> api_id = string<br> stage_name = string<br> base_path = string<br> })<br> )</pre> | n/a | yes | | ||
| <a name="input_security_policy"></a> [security\_policy](#input\_security\_policy) | TLS Security Policy for the domain | `string` | `"TLS_1_2"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_arn"></a> [arn](#output\_arn) | ARN of domain name. | | ||
<!-- END_TF_DOCS --> |
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,31 @@ | ||
# Provisioned only for regional types. @todo: Enhance for other types as well | ||
resource "aws_api_gateway_domain_name" "domain" { | ||
domain_name = var.domain_name | ||
regional_certificate_arn = var.cert_arn == "" ? aws_acm_certificate.cert[0].arn : var.cert_arn | ||
security_policy = var.security_policy | ||
|
||
endpoint_configuration { | ||
types = ["REGIONAL"] | ||
} | ||
|
||
} | ||
|
||
resource "aws_api_gateway_base_path_mapping" "mapping" { | ||
for_each = var.path_mappings | ||
|
||
api_id = each.value.api_id | ||
stage_name = each.value.stage_name | ||
base_path = each.value.base_path | ||
domain_name = aws_api_gateway_domain_name.domain.domain_name | ||
} | ||
|
||
resource "aws_acm_certificate" "cert" { | ||
count = var.create_acm_cert && var.cert_arn == "" ? 1 : 0 | ||
|
||
domain_name = var.domain_name | ||
validation_method = "DNS" | ||
|
||
lifecycle { | ||
create_before_destroy = true | ||
} | ||
} |
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,4 @@ | ||
output "arn" { | ||
value = aws_api_gateway_domain_name.domain.arn | ||
description = "ARN of domain name." | ||
} |
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,37 @@ | ||
################################################################################ | ||
# variables for Custom domain mapping sub module | ||
################################################################################ | ||
|
||
variable "domain_name" { | ||
description = "Custom domain name" | ||
type = string | ||
} | ||
|
||
variable "security_policy" { | ||
description = "TLS Security Policy for the domain" | ||
type = string | ||
default = "TLS_1_2" | ||
} | ||
|
||
variable "create_acm_cert" { | ||
description = "Create ACM cert. create_acm_cert and cert_arn Mutually exclusive. " | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "cert_arn" { | ||
description = "Cert ARN. Create ACM cert. create_acm_cert and cert_arn Mutually exclusive." | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "path_mappings" { | ||
description = "List of stages the usage plan can be used " | ||
type = map( | ||
object({ | ||
api_id = string | ||
stage_name = string | ||
base_path = string | ||
}) | ||
) | ||
} |
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,9 @@ | ||
terraform { | ||
required_version = ">= 1.0" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 4.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
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
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