Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform refer to locals in another directory

I have a directory name "3-tier" In which there are two more directories namely ec2 and vpc. The exact directory structure is as attached below

enter image description here

The main.tf in vpc directory has a locals block defined:

locals {
    owner = var.owner
    environment = var.environment
    Name = "${local.owner}-${local.environment}-${var.vpc_name}"
    common_tags = {
        Owner = local.owner
        Environment = local.environment
        Name = local.Name
    }
}

In the ec2 directory main.tf file I have loaded the module as below

module "vpc_module" {
    source = "../vpc/"
}

How can I refer to the locals present in vpc directory main.tf file from ec2 directory main.tf file?

like image 663
vidyadhar reddy Avatar asked Sep 06 '25 03:09

vidyadhar reddy


1 Answers

How can I refer to the locals present in vpc directory main.tf file from ec2 directory main.tf file?

You can't do this directly. You have to add them as output values to your vpc module. Then you will be able to access them through outputs of your vpc module.

like image 107
Marcin Avatar answered Sep 09 '25 17:09

Marcin