Skip to content

Commit 24e0b12

Browse files
committed
Init
0 parents  commit 24e0b12

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## About
2+
Terraform module to create TLS certificate from AWS ACM
3+
4+
Features:
5+
* Multiple domains support (SAN)
6+
* Auto validation using DNS
7+
8+
Limitations:
9+
* all DNS zone should be in the same AWS account
10+
11+
## Usage
12+
13+
it's a tricky to pass list of hostnames and its Route 53 zone_ids. The format is a string of comma-separated hostnames list
14+
and corresponding coma-separated zone_id list (the order in lists should be the same):
15+
16+
```
17+
module "certificate" {
18+
source = "github.com/jetbrains-infra/terraform-aws-acm-certificate"
19+
hostnames = "example.com,example.net" // required
20+
zone_ids = "${aws_route53_zone.example_com.id},${aws_route53_zone.example_net.id}" // required
21+
}
22+
```
23+
24+
## Outputs
25+
26+
* `arn` - certificate ARN

certificate.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_acm_certificate" "default" {
2+
domain_name = "${local.main_domain}"
3+
subject_alternative_names = ["${local.alternative_names}"]
4+
validation_method = "DNS"
5+
}
6+
7+
resource "aws_route53_record" "proof" {
8+
count = "${local.hostname_count}"
9+
name = "${element(aws_acm_certificate.default.domain_validation_options.*.resource_record_name, count.index)}"
10+
type = "${element(aws_acm_certificate.default.domain_validation_options.*.resource_record_type, count.index)}"
11+
zone_id = "${element(var.zone_ids, count.index)}"
12+
records = ["${element(aws_acm_certificate.default.domain_validation_options.*.resource_record_value, count.index)}"]
13+
ttl = 60
14+
}
15+
16+
resource "aws_acm_certificate_validation" "default" {
17+
certificate_arn = "${aws_acm_certificate.default.arn}"
18+
validation_record_fqdns = ["${aws_route53_record.proof.fqdn}"]
19+
}

outputs.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "arn" {
2+
value = "${aws_acm_certificate.default.arn}"
3+
}

settings.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "aws" {
2+
alias = "us"
3+
region = "us-east-1"
4+
}

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
variable "hostnames" {}
2+
variable "zone_ids" {}
3+
variable "region" {
4+
default = "eu-west-1"
5+
}
6+
7+
locals {
8+
main_domain = "${element(split(",", var.hostnames), 0)}"
9+
alternative_names = "${slice(split(",", var.hostnames), 1, length(split(",", var.hostnames)))}"
10+
hostname_count = "${length(split(",", var.hostnames))}"
11+
}
12+
13+
provider "aws" {
14+
region = "${var.region}"
15+
}

0 commit comments

Comments
 (0)