Create records in AWS Route 53 for ACM certificate

78 Views Asked by At

/acm - main.tf

resource "aws_acm_certificate" "test" {
  domain_name       = "www.example.com"
  validation_method = "DNS"

  lifecycle {
    create_before_destroy = true
  }
}

outputs.tf

output "Example_ACM_Cert_arn" {
  description = "ACM certificate for "Example""
  value       = aws_acm_certificate.Example.arn
}

route 53/ main.tf

resource "aws_route53_record" ""www.example.com"" {
  zone_id = var.example_zone_id
  name    = "www.example.com"
  type    = "CNAME"
  ttl     = "60"
  records = [var.Example_ACM_Cert_arn]
}

variables.tf

variable "Example_ACM_Cert_arn" {
    type = string
}

variable "example_zone_id" {
    type        = string
    description = "example zone id"
    default     = "00000000000000000000" 
}

I saw this tutorial in terraform but i dont understand how to do it if the ACM and the Route 53 is not on the same module...

resource "aws_acm_certificate" "example" {
  domain_name       = "example.com"
  validation_method = "DNS"
}

data "aws_route53_zone" "example" {
  name         = "example.com"
  private_zone = false
}

resource "aws_route53_record" "example" {
  for_each = {
    for dvo in aws_acm_certificate.example.domain_validation_options : dvo.domain_name => {
      name   = dvo.resource_record_name
      record = dvo.resource_record_value
      type   = dvo.resource_record_type
    }
  }

  allow_overwrite = true
  name            = each.value.name
  records         = [each.value.record]
  ttl             = 60
  type            = each.value.type
  zone_id         = data.aws_route53_zone.example.zone_id
}

resource "aws_acm_certificate_validation" "example" {
  certificate_arn         = aws_acm_certificate.example.arn
  validation_record_fqdns = [for record in aws_route53_record.example : record.fqdn]
}

resource "aws_lb_listener" "example" {
  # ... other configuration ...

  certificate_arn = aws_acm_certificate_validation.example.certificate_arn
}

Hello everyone! I'm new in Terraform and I'm trying to Create records in AWS Route 53 for ACM certificate via Terraofrm but i can't figure it out.

0

There are 0 best solutions below