-
Notifications
You must be signed in to change notification settings - Fork 0
/
acm.tf
43 lines (38 loc) · 1.4 KB
/
acm.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
resource "aws_acm_certificate" "cert" {
domain_name = var.domain_name
subject_alternative_names = ["*.${var.domain_name}"]
validation_method = "DNS"
lifecycle {
create_before_destroy = true
}
}
resource "cloudflare_record" "acm" {
depends_on = [aws_acm_certificate.cert]
zone_id = var.cloudflare_zone_id
name = element(tolist(aws_acm_certificate.cert.domain_validation_options), 0).resource_record_name
type = element(tolist(aws_acm_certificate.cert.domain_validation_options), 0).resource_record_type
value = element(tolist(aws_acm_certificate.cert.domain_validation_options), 0).resource_record_value
lifecycle {
ignore_changes = [
value
]
}
}
resource "aws_acm_certificate_validation" "cert" {
depends_on = [aws_acm_certificate.cert]
certificate_arn = aws_acm_certificate.cert.arn
}
resource "cloudflare_record" "cname" {
depends_on = [aws_cloudfront_distribution.s3_distribution]
zone_id = var.cloudflare_zone_id
name = var.domain_name
value = aws_cloudfront_distribution.s3_distribution.domain_name
type = "CNAME"
}
resource "cloudflare_record" "www" {
depends_on = [aws_cloudfront_distribution.s3_distribution]
zone_id = var.cloudflare_zone_id
name = "www"
value = aws_s3_bucket.redirect_website.website_endpoint
type = "CNAME"
}