0

I'm new to terragrunt and trying to figure how to pass variables between modules. I'm following terragrunt documentation here yet no luck and fails with error:

apps tg run-all plan    
INFO[0000] The stack at /Users/xxx/sri/aws/Infrastructure/apps will be processed in the following order for command plan:
Group 1
- Module /Users/xxx/sri/aws/Infrastructure/apps/networks-vpc
- Module /Users/xxx/sri/aws/Infrastructure/apps/sri-s3-bucket

Group 2
- Module /Users/xxx/sri/aws/Infrastructure/apps/ec2-amz-lnx
 

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

module.vpc.aws_vpc.vpc: Refreshing state... [id=vpc-xxx]
module.vpc.aws_internet_gateway.igw: Refreshing state... [id=igw-xxx]
module.vpc.aws_subnet.public_subnet_a: Refreshing state... [id=subnet-xxx]
module.vpc.aws_route_table.private_b: Refreshing state... [id=rtb-xxx]
module.vpc.aws_route_table.public_b: Refreshing state... [id=rtb-xxx]
module.vpc.aws_subnet.private_subnet_b: Refreshing state... [id=subnet-xxx]
module.vpc.aws_route_table.public_a: Refreshing state... [id=rtb-xxx]
module.vpc.aws_subnet.public_subnet_b: Refreshing state... [id=subnet-xxx]
module.vpc.aws_route_table.private_a: Refreshing state... [id=rtb-xxx]
module.vpc.aws_subnet.private_subnet_a: Refreshing state... [id=subnet-xxx]
module.vpc.aws_security_group.sri_sg1: Refreshing state... [id=sg-xxx]
module.vpc.aws_route.r_a0: Refreshing state... [id=r-rtb-xxx]
module.vpc.aws_route.r_b0: Refreshing state... [id=r-rtb-xxx]
module.vpc.aws_security_group_rule.sri_sg1_ingress_rule1: Refreshing state... [id=sgrule-xxx]
module.vpc.aws_security_group_rule.sri_sg1_egress_rule1: Refreshing state... [id=sgrule-xxx]
module.vpc.aws_security_group_rule.sri_sg1_ingress_rule3: Refreshing state... [id=sgrule-xxx]
module.vpc.aws_security_group_rule.sri_sg1_ingress_rule2: Refreshing state... [id=sgrule-xxx]
module.vpc.aws_route_table_association.public_b: Refreshing state... [id=rtbassoc-xxx]
module.vpc.aws_route_table_association.private_a: Refreshing state... [id=rtbassoc-xxx]
module.vpc.aws_route_table_association.public_a: Refreshing state... [id=rtbassoc-xxx]
module.vpc.aws_route_table_association.private_b: Refreshing state... [id=rtbassoc-xxx]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.
ERRO[0008] Module /Users/xxx/sri/aws/Infrastructure/apps/ec2-amz-lnx has finished with an error: /Users/xxx/sri/aws/Infrastructure/apps/networks-vpc/terragrunt.hcl is a dependency of /Users/xxx/sri/aws/Infrastructure/apps/ec2-amz-lnx/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.  prefix=[/Users/xxx/sri/aws/Infrastructure/apps/ec2-amz-lnx] 
ERRO[0008] 1 error occurred:
        * /Users/xxx/sri/aws/Infrastructure/apps/networks-vpc/terragrunt.hcl is a dependency of /Users/xxx/sri/aws/Infrastructure/apps/ec2-amz-lnx/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.
 
ERRO[0008] Unable to determine underlying exit code, so Terragrunt will exit with error code 1 
My Folder structure:

aws tree
.
├── Infrastructure
│   ├── README.md
│   ├── apps
│   │   ├── ec2-amz-lnx
│   │   │   ├── graph.svg
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   ├── providers.tf
│   │   │   ├── terragrunt.hcl
│   │   │   ├── variables.tf
│   │   │   └── versions.tf
│   │   ├── graph.svg
│   │   ├── networks-vpc
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   ├── providers.tf
│   │   │   ├── terragrunt.hcl
│   │   │   ├── variables.tf
│   │   │   └── versions.tf
│   │   ├── sri-s3-bucket
│   │   │   ├── main.tf
│   │   │   ├── providers.tf
│   │   │   ├── terragrunt.hcl
│   │   │   ├── variables.tf
│   │   │   ├── versions.tf
│   │   │   └── website
│   │   │       └── index.html
│   │   └── website-s3
│   ├── binaries
│   │   ├── darwin
│   │   │   ├── terraform
│   │   │   └── terragrunt
│   │   ├── linux
│   │   │   ├── terraform
│   │   │   └── terragrunt
│   │   └── windows
│   │       ├── terraform.exe
│   │       └── terragrunt.exe
│   ├── environments
│   │   ├── ap-southeast-2
│   │   │   ├── npe
│   │   │   │   ├── apps
│   │   │   │   │   ├── ec2-amz-lnx.tfvars
│   │   │   │   │   ├── networks-vpc.tfvars
│   │   │   │   │   └── s3.tfvars
│   │   │   │   └── environment.hcl
│   │   │   └── prod
│   │   └── us-east-2
│   ├── modules
│   │   ├── ec2
│   │   │   ├── data.tf
│   │   │   ├── files
│   │   │   │   └── user_data_lx_amazon.tpl
│   │   │   ├── iam.tf
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   ├── s3
│   │   │   ├── main.tf
│   │   │   ├── outputs.tf
│   │   │   └── variables.tf
│   │   └── vpc
│   │       ├── main.tf
│   │       ├── outputs.tf
│   │       └── variables.tf
│   └── terragrunt.hcl
├── test.jpg

So I have written terraform modules for vpc, ec2, s3 locally under module folder, that are used by apps(workspaces)and configs/tfvars for environment based on region and environment as shown above.

As you can see above the terragrunt has put networks-vpc in Group 1 and ec2-amz-lnx in Group 2. I've made sure I've declared outputs in VPC(as below)

Outputs:

SecurityGroupID = "sg-xxx"
private_subs = {
  "private_subnet_a" = "subnet-xxx"
  "private_subnet_b" = "subnet-xxx"
}
public_subs = "subnet-xxx"
vpc_id = "vpc-xxx"

In the ec2-amz-lnx folder, I've created terragrunt.hcl file with following:

include {
  path = find_in_parent_folders()
  expose = true
}

dependency "shared_infra" {
  config_path = "../networks-vpc"
  # mock_outputs = {
  #   public_subs = "subnet-xxx"
  # }
}

dependencies {
  paths = ["../networks-vpc"]
}

inputs = {
  public_subs = dependency.shared_infra.outputs.public_subs
}

and In ec2-amz-lnx, I'm passing public_subs value like below:

module "ec2" {
  source = "../../modules/ec2"
  vpc_public_subnet_id = public_subs
  instance_type_lx      = var.instance_type_lx_value
  security_group_ids     = var.security_group_ids_value
  ec2keypair_name     = var.ec2keypair_name_value
  instance_count            = var.instance_count_value
}
Sri
  • 51
  • 4

1 Answers1

0

i ve spent some time digging with terrgarunt.

as for the error "Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outp..."

The problem with the teragrunt is that : if you have module A and module B and module B depends on module A then ==> you must deploy module B and only after that you can deploy module A. Otherwise terragrunt cant find outputs (variables) from module A to pass them to module B. so you can not deploy module A and module B at one step. You need two separate steps. Oh yeah.. "mock outputs" doesnt solve the problem.

It makes terragrunt kind of useless for now.

pure terraform doesnt have sush problem.

Alex
  • 837
  • 8
  • 9