Skip to content

Commit

Permalink
feat: Support base_path mapping for custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Hammond committed Sep 15, 2021
1 parent 808a064 commit 5c1fc76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ data "template_file" "_" {
}

data "aws_api_gateway_domain_name" "_" {
depends_on = [aws_api_gateway_domain_name._]
count = var.api_domain_name == "" ? 0: 1
depends_on = [aws_api_gateway_domain_name._]
count = var.api_domain_name == "" ? 0 : 1
domain_name = var.api_domain_name
}

Expand Down Expand Up @@ -66,22 +66,23 @@ resource "aws_api_gateway_method_settings" "_" {
# Domain Setup
#
resource "aws_api_gateway_domain_name" "_" {
domain_name = var.api_domain_name
domain_name = var.api_domain_name
endpoint_configuration {
types = ["REGIONAL"]
}
regional_certificate_arn = var.acm_certificate_arn
security_policy = "TLS_1_2"
security_policy = "TLS_1_2"

count = var.api_domain_name == "" ? 0 :1
count = var.api_domain_name == "" ? 0 : 1
}

resource "aws_api_gateway_base_path_mapping" "_" {
count = var.api_domain_name == "" ? 0 :1
count = var.api_domain_name == "" ? 0 : 1

api_id = aws_api_gateway_rest_api._.id
domain_name = aws_api_gateway_domain_name._[0].domain_name
stage_name = aws_api_gateway_stage._.stage_name
base_path = var.api_base_path
}

# -----------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ variable "api_domain_name" {
default = ""
}

variable "api_base_path" {
description = "The base path to use for custom domain mappings"
type = string
default = ""
}

variable "acm_certificate_arn" {
description = "The ARN of the ACM certificate to use for the custom domain name"
type = string
Expand Down

0 comments on commit 5c1fc76

Please sign in to comment.