Pankaj Moolrajani
Pankaj Moolrajani

Reputation: 75

How to refer to resource created via module in same file?

Here is the setup

Here is the code

locals {
    globals = jsondecode(file("${path.module}/../../../globals.json"))
}

module "cloudfront_distribution" {
    source                          = "../../../modules/cloudfront-distribution/"
    env                             = "prod"
    resource_name                   = "www-example-com"
    cloudfront_domain_name          = "www.example.com"
    cloudfront_domain_aliases       = ["www.example.com"]
    origin_domain_name              = "app.example-origin.com"
    subdomain_name                  = ""
    price_class                     = "PriceClass_100"
    origin_https_port               = 443
    origin_http_port                = 80
    origin_ssl_protocols            = ["TLSv1.2"]
    is_route53_record_needed        = false
    is_prerender_function_attached  = true
}


resource "aws_route53_record" "www_example_com" {
    zone_id         = "123456"
    name            = "www"
    type            = "CNAME"
    ttl             = 5
    records         = [module.cloudfront_distribution.domain_name]
}

I am getting an error in the last line where I am trying to reference to the domain name of the CloudFront created to create the route53 record. This domain name is something like this d8493jg8r.cloudfront.net

Upvotes: 0

Views: 168

Answers (1)

Mark B
Mark B

Reputation: 200466

You have to declare the distribution as an output inside the module. Then you can reference the module's outputs at the top level.

Upvotes: 1

Related Questions