Skip to content

Commit

Permalink
Fix bug with parsing extra arguments (#67)
Browse files Browse the repository at this point in the history
Co-authored-by: dmattia <david@transcend.io>
  • Loading branch information
dmattia and dmattia authored Sep 30, 2020
1 parent a751434 commit 518fba2
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,15 @@ func getDependencies(path string) ([]string, error) {
if parsedConfig.Terraform != nil && parsedConfig.Terraform.ExtraArgs != nil {
extraArgs := parsedConfig.Terraform.ExtraArgs
for _, arg := range extraArgs {
for _, file := range *arg.RequiredVarFiles {
dependencies = append(dependencies, file)
if arg.RequiredVarFiles != nil {
for _, file := range *arg.RequiredVarFiles {
dependencies = append(dependencies, file)
}
}
for _, file := range *arg.OptionalVarFiles {
dependencies = append(dependencies, file)
if arg.OptionalVarFiles != nil {
for _, file := range *arg.OptionalVarFiles {
dependencies = append(dependencies, file)
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions cmd/golden/extraArguments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,27 @@ projects:
- dev.tfvars
- us-east-1.tfvars
dir: child
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: no_files_at_all
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- ../dev.tfvars
- ../us-east-1.tfvars
- dev.tfvars
- us-east-1.tfvars
dir: only_optional_files
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- ../terraform.tfvars
dir: only_required_files
version: 3
20 changes: 20 additions & 0 deletions test_examples/extra_arguments/no_files_at_all/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include {
path = find_in_parent_folders()
}

terraform {
source = "git::git@github.com:transcend-io/terraform-aws-fargate-container?ref=v0.0.4"
extra_arguments "conditional_vars" {
commands = [
"apply",
"plan",
"import",
"push",
"refresh"
]
}
}

inputs = {
foo = "bar"
}
30 changes: 30 additions & 0 deletions test_examples/extra_arguments/only_optional_files/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
include {
path = find_in_parent_folders()
}

terraform {
source = "git::git@github.com:transcend-io/terraform-aws-fargate-container?ref=v0.0.4"
extra_arguments "conditional_vars" {
commands = [
"apply",
"plan",
"import",
"push",
"refresh"
]

# Small note: get_env can't really be supported very well here.
# In a case like this, I'd use a for loop to construct
# `extra_atlantis_dependencies` in locals for all possible regions
optional_var_files = [
"${get_parent_terragrunt_dir()}/${get_env("TF_VAR_env", "dev")}.tfvars",
"${get_parent_terragrunt_dir()}/${get_env("TF_VAR_region", "us-east-1")}.tfvars",
"${get_terragrunt_dir()}/${get_env("TF_VAR_env", "dev")}.tfvars",
"${get_terragrunt_dir()}/${get_env("TF_VAR_region", "us-east-1")}.tfvars"
]
}
}

inputs = {
foo = "bar"
}
24 changes: 24 additions & 0 deletions test_examples/extra_arguments/only_required_files/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include {
path = find_in_parent_folders()
}

terraform {
source = "git::git@github.com:transcend-io/terraform-aws-fargate-container?ref=v0.0.4"
extra_arguments "conditional_vars" {
commands = [
"apply",
"plan",
"import",
"push",
"refresh"
]

required_var_files = [
"${get_parent_terragrunt_dir()}/terraform.tfvars"
]
}
}

inputs = {
foo = "bar"
}

0 comments on commit 518fba2

Please sign in to comment.