Title
#general
Basar Soker

Basar Soker

04/28/2022, 1:56 PM
Hello everyone! Thanks a lot for this amazing tool. Nowadays we have been trying to implement it to our environment, however I run into a problem that I explained here. I had the same problem during Atlantis implementation and skipped it somehow, but for Infracost, it seems mandatory. Have you ever come across with this issue? Thanks in advance!
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 2:07 PM
Hi Basar, welcome! I’ve not been able to reproduce this. Do you have an example project it happens on?
Basar Soker

Basar Soker

04/28/2022, 2:16 PM
Hi Ali! in fact any terragrunt dependency relationship should give the same error, though here you can see my terragrunt files.
2:18 PM
locals {
 ....
}

dependency "vpc" {
  config_path = "../../vpc/${local.aws_service_name}"
  mock_outputs_allowed_terraform_commands = ["init", "plan", "destroy", "apply", "import"]
  mock_outputs = {
    azs                 = ["eu-west-1a", "eu-west-1c"]
    vpc_id              = "vpc-99999999"
    elasticache_subnets = ["172.0.9.0/24", "172.0.10.0/24"]
  }  
}


terraform {
  source = "git::<ssh://git@github.com/cloudposse/terraform-aws-elasticache-redis.git//?ref=0.42.0>"
}
# Include all settings from the root terragrunt.hcl file
include {
  path = find_in_parent_folders()
}


# the following part is filled in line with <https://github.com/cloudposse/terraform-aws-elasticache-redis#inputs>
# you may define your own parameters accordingly
inputs = {
  name                             = local.aws_service_name
  environment                      = local.environment
  availability_zones               = dependency.vpc.outputs.azs
  vpc_id                           = dependency.vpc.outputs.vpc_id
  #use_existing_security_groups    = false
  create_security_group            = true
  # give the following parameter as a list of objects. for more check this <https://github.com/cloudposse/terraform-aws-elasticache-redis/issues/153>
  additional_security_group_rules  = [{type = "ingress", from_port = 6379, to_port = 6379, protocol = "tcp", cidr_blocks =  ["20.0.0.0/24", "20.0.1.0/24"]}]
  subnets                          = dependency.vpc.outputs.elasticache_subnets
  cluster_size                     = 1
  instance_type                    = "cache.t3.small"
  apply_immediately                = true
  automatic_failover_enabled       = false
  engine_version                   = "4.0.10"
  family                           = "redis4.0"
  multi_az_enabled                 = false
  at_rest_encryption_enabled       = false
  transit_encryption_enabled       = false
  cloudwatch_metric_alarms_enabled = false
  snapshot_retention_limit         = 7

  tags = {
...
  }
}
2:19 PM
and the terragrunt file of the dependency
2:21 PM
locals {
  aws_service_name = basename(get_terragrunt_dir())
  
}

terraform {
  source = "git::<ssh://git@github.com/terraform-aws-modules/terraform-aws-vpc.git//.?ref=v3.12.0>"
}

include {
  path = find_in_parent_folders()
}

# the following part is filled in line with <https://github.com/terraform-aws-modules/terraform-aws-vpc#inputs>
# you may define your own parameters accordingly
inputs = {
  name                               = local.aws_service_name
  region                             = local.aws_region
  cidr                               = "20.0.0.0/16"
  public_subnets                     = ["20.0.0.0/24", "20.0.1.0/24"]
  private_subnets                    = ["20.0.3.0/24", "20.0.4.0/24"]
  database_subnets                   = ["20.0.6.0/24", "20.0.7.0/24"]
  elasticache_subnets                = ["20.0.9.0/24", "20.0.10.0/24"]
  azs                                = ["eu-west-1a", "eu-west-1c"]
  public_subnet_suffix               = "public"
  private_subnet_suffix              = "private"
  database_subnet_suffix             = "database"
  elasticache_subnet_suffix          = "elasticache"
  create_database_subnet_route_table = true
  enable_nat_gateway                 = true
  
  vpc_tags = {}
  
  private_subnet_tags = {
    "Subnet" = "Private",
  }
  
  public_subnet_tags = {
    "Subnet" = "Public"
  }
  
  tags = {
    terraform                       = "true"
    environment                     = local.aws_service_name
    # please write your own department
    department                      = ""
    name                            = local.aws_service_name 
  }
}
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 2:24 PM
Thanks, I’m trying a few things but still only able to reproduce when using
run-all
commands, not
terragrunt show
directly
2:28 PM
I don’t know much about the mock outputs, but is there any harm adding
show
to
mock_outputs_allowed_terraform_commands
?
Basar Soker

Basar Soker

04/28/2022, 2:28 PM
once I run the commands in here I am getting the error, which are,
terragrunt run-all plan -out tfplan.binary
terragrunt show  $(find . -name tfplan.binary)
2:32 PM
As I explained here, using
run-all plan
and
show
commands sequentially has a known issue, thus I tried to do it with
plan
and
show
and still getting the same error. It is related to terragrunt itself, but I just wanted know if have you seen this problem anywhere else.
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 2:50 PM
Yeah, it’s only something I’ve seen with
run-all
before. I know the
--terragrunt-ignore-external-dependencies
is meant to be for
run-all
but I’m curious if using it with
terragrunt show
helps as well?
Basar Soker

Basar Soker

04/28/2022, 3:09 PM
Do you mean running
terragrunt show --terragrunt-ignore-external-dependencies
? if so, I can try
3:13 PM
nope, still same error 😔
$ terragrunt show tfplan-3.binary   --terragrunt-ignore-external-dependencies
ERRO[0020] .../terragrunt.hcl is a dependency of .../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[0020] Unable to determine underlying exit code, so Terragrunt will exit with error code 1
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 3:27 PM
Hmm, did adding
show
to
mock_outputs_allowed_terraform_commands
help with anything?
Basar Soker

Basar Soker

04/28/2022, 3:31 PM
😳 I never thought it before, let me try
4:13 PM
I feel stupid and super grateful 😃 Though, I had two tweak
terragrunt run-all plan -out tfplan.binary
to
terragrunt plan -out tfplan.binary
here.
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 4:17 PM
did
mock_outputs_allowed_terraform_commands
work?
Basar Soker

Basar Soker

04/28/2022, 4:18 PM
yep this solves the problem but as I said, this does not work for
run-all plan
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 4:20 PM
Interesting, thanks for diving into this with me! With
run-all plan
maybe
--terragrunt-ignore-external-dependencies
is needed?
Basar Soker

Basar Soker

04/28/2022, 4:20 PM
let me try this one too
4:23 PM
yep, this one works too
4:24 PM
in a nutshell, either this or this has to be done. maybe this should be changed here
Alistair (Infracost)

Alistair (Infracost)

04/28/2022, 4:34 PM
Thanks! I’ve updated that docs page 🙏
Basar Soker

Basar Soker

04/28/2022, 4:46 PM
great! thank you all again for this super tool!