gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.12k stars 986 forks source link

terragrunt apply fails for module #825

Open jamie3 opened 5 years ago

jamie3 commented 5 years ago

I am using a module from the registry and it is failing. Note: Running this in vscode bash shell.

Steps to reproduce

export TERRAGRUNT_DOWNLOAD=/c/.terragrunt-cache
terragrunt init
terragrunt apply
Error: Unsupported argument

  on waf.tf line 137, in module "owasp_top_10":
 137:   product_domain                 = "tsi"

An argument named "product_domain" is not expected here.

Error: Unsupported argument

  on waf.tf line 138, in module "owasp_top_10":
 138:   service_name                   = "tsiwaf"

An argument named "service_name" is not expected here.

Error: Unsupported argument

  on waf.tf line 139, in module "owasp_top_10":
 139:   environment                    = "${var.environment}"

An argument named "environment" is not expected here.

Error: Unsupported argument

  on waf.tf line 140, in module "owasp_top_10":
 140:   description                    = "OWASP Top 10 rules"

An argument named "description" is not expected here.

Error: Unsupported argument

  on waf.tf line 141, in module "owasp_top_10":
 141:   target_scope                   = "regional"

An argument named "target_scope" is not expected here.

Error: Unsupported argument

  on waf.tf line 142, in module "owasp_top_10":
 142:   create_rule_group              = "true"

An argument named "create_rule_group" is not expected here.

Error: Unsupported argument

  on waf.tf line 143, in module "owasp_top_10":
 143:   max_expected_uri_size          = "512"

An argument named "max_expected_uri_size" is not expected here.

Error: Unsupported argument

  on waf.tf line 144, in module "owasp_top_10":
 144:   max_expected_query_string_size = "1024"

An argument named "max_expected_query_string_size" is not expected here.

Error: Unsupported argument

  on waf.tf line 145, in module "owasp_top_10":
 145:   max_expected_body_size         = "4096"

An argument named "max_expected_body_size" is not expected here.

Error: Unsupported argument

  on waf.tf line 146, in module "owasp_top_10":
 146:   max_expected_cookie_size       = "4093"

An argument named "max_expected_cookie_size" is not expected here.

Error: Unsupported argument

  on waf.tf line 147, in module "owasp_top_10":
 147:   csrf_expected_header           = "x-csrf-token"

An argument named "csrf_expected_header" is not expected here.

Error: Unsupported argument

  on waf.tf line 148, in module "owasp_top_10":
 148:   csrf_expected_size             = "36"

An argument named "csrf_expected_size" is not expected here.

[terragrunt] 2019/08/08 12:55:31 Hit multiple errors:
exit status 1
# Adds OWASP Top 10 rules to WAF
module "owasp_top_10" {
  source  = "traveloka/waf-owasp-top-10-rules/aws"
  version = "0.2.0"
  # insert the 5 required variables here

  # This module is published on the registry: https://registry.terraform.io/modules/traveloka/waf-owasp-top-10-rules
  #source = "../modules/terraform-aws-waf-owasp-top-10-rules"

  # For a better understanding of what are those parameters mean,
  # please read the description of each variable in the variables.tf file:
  # https://github.com/traveloka/terraform-aws-waf-owasp-top-10-rules/blob/master/variables.tf
  product_domain                 = "tsi"
  service_name                   = "tsiwaf"
  environment                    = "${var.environment}"
  description                    = "OWASP Top 10 rules"
  target_scope                   = "regional"
  create_rule_group              = "true"
  max_expected_uri_size          = "512"
  max_expected_query_string_size = "1024"
  max_expected_body_size         = "4096"
  max_expected_cookie_size       = "4093"
  csrf_expected_header           = "x-csrf-token"
  csrf_expected_size             = "36"
}

I verified the module and tf files were downloaded by going to the terragrunt cache folder.

If I just run terraform init in the path where the .tf files are it works.

brikis98 commented 5 years ago

What does your terragrunt.hcl look like?

jamie3 commented 5 years ago
terraform {
    source = "${get_terragrunt_dir()}/../../../../../infrastructure//waf"
}

# Include parent settings
include {
    path = "${find_in_parent_folders()}"
}

inputs = {
    # IP CIDR which the WAF will block
    blacklisted_ips = [
        "37.9.0.0/20",      # 4096 RU Russian Federation
        "37.9.16.0/20",     # 4096 KZ Kazakhstan
        "37.9.32.0/20",     # 4096 RU Russian Federation
        "37.9.48.0/21",     # 2048 RU Russian Federation
        "37.9.64.0/18",     # 16384 RU Russian Federation
        "37.9.128.0/21",    # 2048 RU Russian Federation
        "37.9.144.0/20",    # 4096 RU Russian Federation
        "37.9.240.0/21"     # 2048 RU Russian Federation
    ]
}
jamie3 commented 5 years ago

Doing more investigation is seems this is a terragrunt issue.

infrastructure\waf
live\production-account\production-env\us-west-2\waf

When I run terraform init in infrastructure\waf it successfully downloads the module.

When I run terragrunt init in the live\production-account\production-env\us-west-2\waf folder I get the following error:

Initializing modules...
Downloading traveloka/waf-owasp-top-10-rules/aws 0.2.0 for owasp_top_10...

Error: Failed to download module

Could not download module "owasp_top_10" (waf.tf:126) source code from
"https://api.github.com/repos/traveloka/terraform-aws-waf-owasp-top-10-rules/tarball/v0.2.0//*?archive=tar.gz":
open
.terraform\modules\owasp_top_10\traveloka-terraform-aws-waf-owasp-top-10-rules-a0fc16d\.github\CODE_OF_CONDUCT.md:
The system cannot find the path specified..

Error: Failed to download module

Could not download module "owasp_top_10" (waf.tf:126) source code from
"https://api.github.com/repos/traveloka/terraform-aws-waf-owasp-top-10-rules/tarball/v0.2.0//*?archive=tar.gz":
open
.terraform\modules\owasp_top_10\traveloka-terraform-aws-waf-owasp-top-10-rules-a0fc16d\.github\CODE_OF_CONDUCT.md:
The system cannot find the path specified..

[terragrunt] 2019/08/14 15:27:08 Hit multiple errors:
exit status 1

If I change my terragrunt download directory to export TERRAGRUNT_DOWNLOAD=/c/.terragrunt-cache it works.

Using Windows 10, vscode bash shell.

jamie3 commented 5 years ago

After I change the download directory I get the error from my original post. I found the issue:

My directory structure is as follows:

infrastructure\modules\my-module   (locally developed modules go here) 
infrastructure\waf
export TERRAGRUNT_DOWNLOAD=/c/.terragrunt-cache
cd live\production-account\production-env\us-west-2\waf
terragrunt init

Initializing modules...
Downloading traveloka/waf-owasp-top-10-rules/aws 0.2.0 for owasp_top_10...
- owasp_top_10 in .terraform\modules\owasp_top_10\traveloka-terraform-aws-waf-owasp-top-10-rules-a0fc16d

# OK GOOD MODULE WAS DOWNLOADED!!

ls -la C:\.terragrunt-cache\x7-oAnEDG1WwfZ5JhOpHjDxn62s\0BJ6pIZapeyXhNBDvO_JhJyFP9A\modules

drwxr-xr-x 1 Jamie 197121   0 Aug 14 15:31 .
drwxr-xr-x 1 Jamie 197121   0 Aug 14 15:31 ..
drwxr-xr-x 1 Jamie 197121   0 Aug 14 15:31 my-module

ls -la C:\.terragrunt-cache\x7-oAnEDG1WwfZ5JhOpHjDxn62s\0BJ6pIZapeyXhNBDvO_JhJyFP9A\waf\.terraform\modules\owasp_top_10

drwxr-xr-x 1 Jamie 197121   0 Aug 14 15:31 .
drwxr-xr-x 1 Jamie 197121   0 Aug 14 15:31 ..
drwxr-xr-x 1 Jamie 197121   0 Aug 14 15:31 traveloka-terraform-aws-waf-owasp-top-10-rules-a0fc16d

ls -la /c/.terragrunt-cache/x7-oAnEDG1WwfZ5JhOpHjDxn62s/0BJ6pIZapeyXhNBDvO_JhJyFP9A/waf/.terraform/modules/owasp_top_10/traveloka-terraform-aws-waf-owasp-top-10-rules-a0fc16d/
total 30
drwxr-xr-x 1 Jamie 197121     0 Aug 14 15:46 .
drwxr-xr-x 1 Jamie 197121     0 Aug 14 15:46 ..
drwxr-xr-x 1 Jamie 197121     0 Aug  5 03:27 .github
-rw-r--r-- 1 Jamie 197121   114 Aug  5 03:27 .gitignore
-rw-r--r-- 1 Jamie 197121   452 Aug  5 03:27 CHANGELOG.md
-rw-r--r-- 1 Jamie 197121  3614 Aug  5 03:27 CONTRIBUTING.md
drwxr-xr-x 1 Jamie 197121     0 Aug  5 03:27 examples
-rw-r--r-- 1 Jamie 197121 11357 Aug  5 03:27 LICENSE
-rw-r--r-- 1 Jamie 197121  3707 Aug  5 03:27 README.md

For whatever reason the module isnt being downloaded as there is no main.tf.

If I run terraform init in the infrastructure/waf folder and ls -la .terraform/modules the main.tf is present.

mmclane commented 5 years ago

I am seeing a similar issue the past couple of days but in my case, if I delete .terragrunt-cache it will work for about 1 run, then it will go back to complaining about unsupported arguments again.

jamie3 commented 5 years ago

Any update on this?