Module doesn't work when sourced via terragrunt

#1

Not certain where I am going wrong, but setting this up in vpc.tf works fine. But migrating to terragrunt doesn’t work. Just wanting to understand why below cannot be setup the way it is.

terragrunt = {
  include {
    path = "${find_in_parent_folders()}"
  }
  terraform = {
    source = "github.com/terraform-aws-modules/terraform-aws-vpc"
    version = "1.17.0"
  }
}

name                              = "dev-vpc"
cidr                              = "10.10.0.0/16"
azs                               = ["us-east-1b", "us-east-1c", "us-east-1d"]
private_subnets                   = ["10.10.0.0/20", "10.10.32.0/20", "10.10.64.0/20"]
public_subnets                    = ["10.10.16.0/20", "10.10.48.0/20", "10.10.80.0/20"]
database_subnets                  = ["10.10.200.0/24", "10.10.201.0/24", "10.10.202.0/24"]

create_database_subnet_group      = false
enable_nat_gateway                = true
enable_vpn_gateway                = false
enable_s3_endpoint                = false
enable_dynamodb_endpoint          = false
enable_dhcp_options               = true

tags = {
  Owner       = "user"
  Environment = "dev"
  Name        = "complete"
}

Running terragrunt plan results in:

Initializing modules...
- module.vpc
  Found version 1.17.0 of terraform-aws-modules/vpc/aws on registry.terraform.io
  Getting source "terraform-aws-modules/vpc/aws"
Initializing the backend...
Error: output 'natgw_ids': unknown resource 'aws_nat_gateway.this' referenced in variable aws_nat_gateway.this.*.id
Error: output 'elasticache_subnet_group': unknown resource 'aws_elasticache_subnet_group.elasticache' referenced in variable aws_elasticache_subnet_group.elasticache.*.id
Error: output 'igw_id': unknown resource 'aws_internet_gateway.this' referenced in variable aws_internet_gateway.this.*.id
...
#2

I’m not familiar with the VPC module in the Terraform registry, so I’m not sure, but a few questions:

  1. What does your folder structure look like?
  2. Do you still have a vpc.tf or other .tf files in the same folder as the terraform.tfvars file you’re using with Terragrunt? The Found version 1.17.0 of terraform-aws-modules/vpc/aws on registry.terraform.io text in your logs suggests you are using module { source = "..." } code somewhere, but it’s not clear where that’s coming from, as it’s not Terragrunt.
#3

This is folder structure

├── account
│   ├── dev
│   │   ├── ap-northeast-1
│   │   │   ├── main.tf
│   │   │   └── terraform.tfvars
│   │   ├── us-east-1
│   │   │   ├── main.tf
│   │   │   └── terraform.tfvars
│   ├── main.tf
│   ├── terraform.tfvars

Running the terragrunt command terragrun plan from account/dev/virginia. If I move the module declaration info main.tf using the example code from the registry, sorta the terraform way—everything works. That reduces terraform.tfvars to:

terragrunt = {
  include {
    path = "${find_in_parent_folders()}"
  }
}

But I was hoping to be able to keep the modules and vars in just the terraform.tfvars

#4

I think this was due to me using the wrong version of the aws provider. The issue has resolved on it’s own.