-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Allow multiple domains in one cert #137
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
locals { | ||
# Use existing (via data source) or create new zone (will fail validation, if zone is not reachable) | ||
use_existing_route53_zone = true | ||
use_existing_route53_zone = var.use_existing_route53_zone | ||
|
||
domain = "terraform-aws-modules.modules.tf" | ||
domain = var.domain | ||
extra_domain = var.extra_domain | ||
|
||
# Removing trailing dot from domain - just to be sure :) | ||
domain_name = trimsuffix(local.domain, ".") | ||
|
||
region = "us-east-1" | ||
|
||
zone_id = try(data.aws_route53_zone.this[0].zone_id, aws_route53_zone.this[0].zone_id) | ||
} | ||
|
||
|
@@ -32,8 +35,7 @@ module "acm" { | |
source = "../../" | ||
|
||
providers = { | ||
aws.acm = aws, | ||
aws.dns = aws | ||
aws = aws.acm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While your change is valid, please revert to show that there can be two distinct providers passed to the module. |
||
} | ||
|
||
domain_name = local.domain_name | ||
|
@@ -60,11 +62,13 @@ module "acm" { | |
################################################################ | ||
|
||
provider "aws" { | ||
alias = "route53" | ||
alias = "route53" | ||
region = local.region | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert all changes not necessary for your PR. |
||
} | ||
|
||
provider "aws" { | ||
alias = "acm" | ||
alias = "acm" | ||
region = local.region | ||
} | ||
|
||
module "acm_only" { | ||
|
@@ -103,3 +107,58 @@ module "route53_records_only" { | |
|
||
acm_certificate_domain_validation_options = module.acm_only.acm_certificate_domain_validation_options | ||
} | ||
|
||
########################################################## | ||
# Example 3 (use multiple domains in the same certificate): | ||
# Generate an ACM certificate for multiple domains, useful | ||
# to be used in CloudFront which only supports one ACM | ||
# certificate. | ||
########################################################## | ||
|
||
provider "aws" { | ||
region = local.region | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove |
||
} | ||
|
||
data "aws_route53_zone" "extra" { | ||
count = local.use_existing_route53_zone ? 1 : 0 | ||
|
||
name = local.extra_domain | ||
private_zone = false | ||
} | ||
|
||
resource "aws_route53_zone" "extra" { | ||
count = !local.use_existing_route53_zone ? 1 : 0 | ||
|
||
name = local.extra_domain | ||
} | ||
|
||
module "acm_multi_domain" { | ||
source = "../../" | ||
|
||
domain_name = local.domain_name | ||
zone_id = local.zone_id | ||
|
||
subject_alternative_names = [ | ||
"*.alerts.${local.domain_name}", | ||
"new.sub.${local.domain_name}", | ||
"*.${local.domain_name}", | ||
"alerts.${local.domain_name}", | ||
"*.alerts.${local.extra_domain}", | ||
"new.sub.${local.extra_domain}", | ||
"*.${local.extra_domain}", | ||
"alerts.${local.extra_domain}", | ||
local.extra_domain, | ||
"*.${local.extra_domain}" | ||
] | ||
|
||
zones = { | ||
(local.extra_domain) = try(data.aws_route53_zone.extra[0].zone_id, aws_route53_zone.extra[0].zone_id), | ||
"alerts.${local.extra_domain}" = try(data.aws_route53_zone.extra[0].zone_id, aws_route53_zone.extra[0].zone_id), | ||
"new.sub.${local.extra_domain}" = try(data.aws_route53_zone.extra[0].zone_id, aws_route53_zone.extra[0].zone_id) | ||
} | ||
|
||
tags = { | ||
Name = local.domain_name | ||
Extra_Domain = local.extra_domain | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
variable "use_existing_route53_zone" { | ||||||
description = "Use existing (via data source) or create new zone (will fail validation, if zone is not reachable)" | ||||||
type = bool | ||||||
default = true | ||||||
} | ||||||
|
||||||
variable "domain" { | ||||||
description = "Domain to be used for the tests" | ||||||
type = string | ||||||
default = "terraform-aws-modules.modules.tf" | ||||||
} | ||||||
|
||||||
variable "extra_domain" { | ||||||
description = "Extr adomain to be used for the tests" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
type = string | ||||||
default = "extra.terraform-aws-modules.modules.tf" | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this
region
, too.