1

I would like to use the output (object) as a attribute of another resources. I have the module like below:

locals {
  lb_domain = {
    lb_public = {
        domain = "dev.example.net"
    },
    lb_internal = {
        domain = "dev.internal.example.net"
    }
}
module "dev_acm" {
  source  = "terraform-aws-modules/acm/aws"
  version = "3.5.0"

  for_each = local.lb_domain

  domain_name = each.value.domain
  zone_id     = data.aws_route53_zone.this.id
}

And output of this module. this is the object, I would like to use this for another resources module.dev_acm:

   + dev_acm = {
      + lb_internal   = {
          + acm_certificate_arn                       = (known after apply)
          + acm_certificate_domain_validation_options = [
              + {
                  + domain_name           = "dev.internal.example.net"
                  + resource_record_name  = (known after apply)
                  + resource_record_type  = (known after apply)
                  + resource_record_value = (known after apply)
                },
            ]
          + acm_certificate_status                    = (known after apply)
          + acm_certificate_validation_emails         = (known after apply)
          + distinct_domain_names                     = [
              + "dev.internal.example.net",
            ]
          + validation_domains                        = (known after apply)
          + validation_route53_record_fqdns           = [
              + (known after apply),
            ]
        }
      + lb_public = {
          + acm_certificate_arn                       = (known after apply)
          + acm_certificate_domain_validation_options = [
              + {
                  + domain_name           = "dev.example.net"
                  + resource_record_name  = (known after apply)
                  + resource_record_type  = (known after apply)
                  + resource_record_value = (known after apply)
                },
            ]
          + acm_certificate_status                    = (known after apply)
          + acm_certificate_validation_emails         = (known after apply)
          + distinct_domain_names                     = [
              + "dev.example.net",
            ]
          + validation_domains                        = (known after apply)
          + validation_route53_record_fqdns           = [
              + (known after apply),
            ]
        }
    }

How I can use acm_certificate_arn public lb_public in the output for another services?
Something like that: module.dev_acm.lb_internal.acm_certificate_arn

Nightt
  • 392
  • 1
  • 4
  • 18
  • 2
    Which one do you want to use, public or private or both? Also, how did you define the output? Can you add that to the question as well? – Marko E Oct 27 '22 at 17:38
  • Thanks for your comment @Marko E, I just added it. I would like to use `lb_public` for another services. – Nightt Oct 28 '22 at 02:38
  • Use as the answer of @Mark B `module.dev_acm["lb_public"].acm_certificate_arn` it works. – Nightt Oct 28 '22 at 03:14

1 Answers1

1

That's an extremely strange way of looking at a Terraform module output. I suggest looking at the documentation for the module you are using, instead of looking at the output that way. Not to mention what you are looking at doesn't indicate that certain things are created via for_each.

How I can use acm_certificate_arn in the output for another services? Something like that: module.dev_acm.lb_internal.acm_certificate_arn

Taking the documantion I linked, and the documentation for referencing for_each instances, it would be:

module.dev_acm["lb_public"].acm_certificate_arn

or

module.dev_acm["lb_internal"].acm_certificate_arn

Mark B
  • 183,023
  • 24
  • 297
  • 295