Skip to content

Commit

Permalink
fix abs path module (#171)
Browse files Browse the repository at this point in the history
* fix abs path module

* add newline, fix dependency
  • Loading branch information
IndraGunawan authored Oct 6, 2021
1 parent b0f809d commit d967154
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,14 @@ func getDependencies(path string, terragruntOptions *options.TerragruntOptions)
if !strings.Contains(*source, "git::") && !strings.Contains(*source, "github.com") {
dependencies = append(dependencies, filepath.Join(*source, "*.tf*"))

dir := filepath.Dir(path)
ls, err := parseTerraformLocalModuleSource(util.JoinPath(dir, *source))
var dir string

if filepath.IsAbs(*source) {
dir = *source
} else {
dir = util.JoinPath(filepath.Dir(path), *source)
}
ls, err := parseTerraformLocalModuleSource(dir)
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,13 @@ func TestLocalTerraformModuleSource(t *testing.T) {
})
}

func TestLocalTerraformAbsModuleSource(t *testing.T) {
runTest(t, filepath.Join("golden", "local_terraform_abs_module.yaml"), []string{
"--root",
filepath.Join("..", "test_examples", "local_terraform_abs_module_source"),
})
}

func TestLocalTfModuleSource(t *testing.T) {
runTest(t, filepath.Join("golden", "local_tf_module.yaml"), []string{
"--root",
Expand Down
13 changes: 13 additions & 0 deletions cmd/golden/local_terraform_abs_module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
automerge: false
parallel_apply: true
parallel_plan: true
projects:
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- ../root-module/*.tf*
- ../terraform-module/*.tf*
dir: terragrunt-module
version: 3
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-errors/errors v1.1.1 // indirect
github.com/gruntwork-io/terragrunt v0.32.2
github.com/hashicorp/go-getter v1.5.9 // indirect
github.com/hashicorp/hcl/v2 v2.10.0
github.com/hashicorp/terraform-config-inspect v0.0.0-20210625153042-09f34846faab
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/S
github.com/hashicorp/go-getter v1.5.1/go.mod h1:a7z7NPPfNQpJWcn4rSWFtdrSldqLdLPEF3d8nFMsSLM=
github.com/hashicorp/go-getter v1.5.7 h1:HBLsom8eGHLxj78ta+/MVSyct8KWG4B4z6lhBA4vJcg=
github.com/hashicorp/go-getter v1.5.7/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI=
github.com/hashicorp/go-getter v1.5.9 h1:b7ahZW50iQiUek/at3CvZhPK1/jiV6CtKcsJiR6E4R0=
github.com/hashicorp/go-getter v1.5.9/go.mod h1:BrrV/1clo8cCYu6mxvboYg+KutTiFnXjMEgDD8+i7ZI=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI=
github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "module_1" {
source = "../terraform-module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "some_resource" "some_name" {
foo = "bar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include {
path = find_in_parent_folders()
}

terraform {
source = "${get_parent_terragrunt_dir()}/root-module"
}

inputs = {
foo = "bar"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
terraform {
}

0 comments on commit d967154

Please sign in to comment.