From 65d5688cee73ffe65460125c4f9ba6683a0c2266 Mon Sep 17 00:00:00 2001 From: Ke Zhang Date: Thu, 7 Nov 2019 09:21:38 -0800 Subject: [PATCH] Define local.validation_domains properly. This local variable references `aws_acm_certificate.this`, which might be empty if `var.create_certificate` is false. --- main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 6014b59..81d90d5 100644 --- a/main.tf +++ b/main.tf @@ -3,7 +3,7 @@ locals { distinct_domain_names = distinct(concat([var.domain_name], [for s in var.subject_alternative_names : replace(s, "*.", "")])) // Copy domain_validation_options for the distinct domain names - validation_domains = [for k, v in aws_acm_certificate.this[0].domain_validation_options : tomap(v) if contains(local.distinct_domain_names, v.domain_name)] + validation_domains = var.create_certificate ? [for k, v in aws_acm_certificate.this[0].domain_validation_options : tomap(v) if contains(local.distinct_domain_names, v.domain_name)] : [] } resource "aws_acm_certificate" "this" {