-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Feature/terragrunt #35
Draft
sgreben
wants to merge
1
commit into
master
Choose a base branch
from
feature/terragrunt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
terraform { | ||
source = "git@github.com:terraform-aws-modules/terraform-aws-iam.git//modules/iam-assumable-roles?ref=v2.21.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/hashicorp/terraform/helper/pathorcontents | ||
|
||
go 1.15 | ||
|
||
require github.com/mitchellh/go-homedir v1.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= | ||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// https://www.terraform.io/docs/extend/guides/v2-upgrade-guide.html#removal-of-helper-pathorcontents-package | ||
package pathorcontents | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/mitchellh/go-homedir" | ||
) | ||
|
||
// If the argument is a path, Read loads it and returns the contents, | ||
// otherwise the argument is assumed to be the desired contents and is simply | ||
// returned. | ||
// | ||
// The boolean second return value can be called `wasPath` - it indicates if a | ||
// path was detected and a file loaded. | ||
func Read(poc string) (string, bool, error) { | ||
if len(poc) == 0 { | ||
return poc, false, nil | ||
} | ||
|
||
path := poc | ||
if path[0] == '~' { | ||
var err error | ||
path, err = homedir.Expand(path) | ||
if err != nil { | ||
return path, true, err | ||
} | ||
} | ||
|
||
if _, err := os.Stat(path); err == nil { | ||
contents, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return string(contents), true, err | ||
} | ||
return string(contents), true, nil | ||
} | ||
|
||
return poc, false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package scan | ||
|
||
import ( | ||
"fmt" | ||
|
||
tgconfig "github.com/gruntwork-io/terragrunt/config" | ||
tgoptions "github.com/gruntwork-io/terragrunt/options" | ||
"github.com/hashicorp/terraform-config-inspect/tfconfig" | ||
) | ||
|
||
func ScanTerragrunt(paths []string) ([]Result, error) { | ||
var out []Result | ||
for _, path := range paths { | ||
opts, err := tgoptions.NewTerragruntOptions(path) | ||
if err != nil { | ||
return nil, fmt.Errorf("build terragrunt options for %q: %w", path, err) | ||
} | ||
paths, err := tgconfig.FindConfigFilesInPath(path, opts) | ||
if err != nil { | ||
return nil, fmt.Errorf("find terragrunt config files in %q: %w", path, err) | ||
} | ||
for _, path := range paths { | ||
cfg, err := tgconfig.PartialParseConfigFile( | ||
path, | ||
opts, | ||
nil, | ||
[]tgconfig.PartialDecodeSectionType{tgconfig.TerraformSource}, | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("read terragrunt config %q: %w", path, err) | ||
} | ||
if cfg.Terraform == nil { | ||
continue | ||
} | ||
if cfg.Terraform.Source == nil { | ||
continue | ||
} | ||
out = append(out, Result{ | ||
Path: path, | ||
ModuleCall: tfconfig.ModuleCall{ | ||
Name: path, | ||
Source: *cfg.Terraform.Source, | ||
Version: "", | ||
Pos: tfconfig.SourcePos{ | ||
Filename: path, | ||
}, | ||
}, | ||
}) | ||
} | ||
} | ||
return out, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB. this is somewhat questionable - we're pretending like the Terragrunt config defines a tf module with a path like
examples/terragrunt.hcl
. Not sure what the correct choice would be though