Skip to content

Commit 553bf72

Browse files
author
Jan Sebastian Siwy
authored
Merge pull request #1 from babbel/initial
Initial version
2 parents 3e12de1 + 59f67e3 commit 553bf72

File tree

11 files changed

+147
-2
lines changed

11 files changed

+147
-2
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
3+
updates:
4+
- package-ecosystem: github-actions
5+
directory: /
6+
schedule:
7+
interval: weekly
8+
day: sunday
9+
time: "11:00"
10+
timezone: Europe/Berlin

.github/workflows/validate.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Validate
2+
3+
on: push
4+
5+
env:
6+
AWS_REGION: local
7+
8+
jobs:
9+
validate:
10+
runs-on: ubuntu-20.04
11+
defaults:
12+
run:
13+
working-directory: _test
14+
steps:
15+
- uses: actions/checkout@v2.4.0
16+
- uses: hashicorp/setup-terraform@v1.3.2
17+
with:
18+
terraform_version: 0.15.5
19+
- run: terraform init
20+
- run: terraform validate

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/_test/.terraform
2+
/_test/.terraform.lock.hcl

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## v1.0.0
4+
5+
- [Initial version](https://github.com/babbel/terraform-aws-acm/pull/1)

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2022 Babbel GmbH
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
1-
# terraform-aws-acm
2-
Terraform module creating an ACM certificate
1+
# AWS Certificate Manager (ACM) Terraform module creating and validating an ACM certificate
2+
3+
Terraform module which creates a ACM certificate in one region and validates it using Route53 DNS.
4+
5+
This is a simplified version of the [`terraform-aws-modules/acm/aws`](https://registry.terraform.io/modules/terraform-aws-modules/acm/aws) module which is waiting before returning certificate ARN as the `this_acm_certificate_arn` output until the validation is completed (returning `aws_acm_certificate_validation#certificate_arn` instead of `aws_acm_certificate#arn`). This is necessary for a seamless `terraform apply` incl. the resources using that certificate.
6+
7+
## Usage
8+
9+
```tf
10+
module "acm" {
11+
source = "babbel/acm/aws"
12+
version = "~> 1.0"
13+
14+
primary_domain_name = "example.com"
15+
16+
domain_names_to_zone_ids = {
17+
"example.com" = "XYZXYZXYZXYZXYZ"
18+
"www.example.com" = "YZXYZXYZXYZXYZX"
19+
}
20+
21+
tags = {
22+
app = "some-service"
23+
env = "production"
24+
}
25+
}
26+
```

_test/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module "acm" {
2+
source = "./.."
3+
4+
primary_domain_name = "example.com"
5+
6+
domain_names_to_zone_ids = {
7+
"example.com" = "XYZXYZXYZXYZXYZ"
8+
"www.example.com" = "YZXYZXYZXYZXYZX"
9+
}
10+
11+
tags = {
12+
app = "some-service"
13+
env = "production"
14+
}
15+
}

main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "aws_acm_certificate" "this" {
2+
domain_name = var.primary_domain_name
3+
subject_alternative_names = setsubtract(keys(var.domain_names_to_zone_ids), [var.primary_domain_name])
4+
validation_method = "DNS"
5+
6+
tags = var.tags
7+
8+
lifecycle {
9+
create_before_destroy = true
10+
}
11+
}
12+
13+
resource "aws_route53_record" "validation" {
14+
for_each = {
15+
for dvo in aws_acm_certificate.this.domain_validation_options : dvo.domain_name => {
16+
name = dvo.resource_record_name
17+
record = dvo.resource_record_value
18+
type = dvo.resource_record_type
19+
}
20+
}
21+
22+
zone_id = var.domain_names_to_zone_ids[each.key]
23+
name = each.value.name
24+
type = each.value.type
25+
ttl = 60
26+
27+
records = [each.value.record]
28+
}
29+
30+
resource "aws_acm_certificate_validation" "this" {
31+
certificate_arn = aws_acm_certificate.this.arn
32+
33+
validation_record_fqdns = [for record in aws_route53_record.validation : record.fqdn]
34+
}

outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "acm_certificate_arn" {
2+
description = "The ARN of the certificate"
3+
value = aws_acm_certificate_validation.this.certificate_arn
4+
}

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
variable "primary_domain_name" {
2+
description = "A domain name for which the certificate should be issued"
3+
type = string
4+
}
5+
6+
variable "domain_names_to_zone_ids" {
7+
description = "Map of domain names (incl. `var.primary_domain_name`) to Route53 hosted zone IDs"
8+
type = map(string)
9+
}
10+
11+
variable "tags" {
12+
description = "A mapping of tags to assign to the resource"
13+
type = map(string)
14+
default = {}
15+
}

0 commit comments

Comments
 (0)