Home > Software engineering >  Retrieve the object output to use for another resources
Retrieve the object output to use for another resources

Time:10-28

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

CodePudding user response:

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

  • Related