-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug with --ignore-parent-terragrunt (#37)
Co-authored-by: dmattia <david@transcend.io>
- Loading branch information
Showing
13 changed files
with
169 additions
and
13 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION=0.4.5 | ||
VERSION=0.5.0 | ||
PATH_BUILD=build/ | ||
FILE_COMMAND=terragrunt-atlantis-config | ||
FILE_ARCH=darwin_amd64 | ||
|
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,11 @@ | ||
automerge: false | ||
parallel_apply: true | ||
parallel_plan: true | ||
projects: | ||
- autoplan: | ||
enabled: false | ||
when_modified: | ||
- '*.hcl' | ||
- '*.tf*' | ||
dir: child/deep | ||
version: 3 |
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,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/gruntwork-io/terragrunt/config" | ||
"github.com/gruntwork-io/terragrunt/options" | ||
"github.com/gruntwork-io/terragrunt/util" | ||
"github.com/hashicorp/hcl/v2/gohcl" | ||
"github.com/hashicorp/hcl/v2/hclparse" | ||
"github.com/zclconf/go-cty/cty/function" | ||
) | ||
|
||
type parsedHcl struct { | ||
Terraform *terraformConfig `hcl:"terraform,block"` | ||
} | ||
|
||
type terraformConfig struct { | ||
Source *string `hcl:"source,attr"` | ||
} | ||
|
||
func isParentModule(path string, terragruntOptions *options.TerragruntOptions) (bool, error) { | ||
configString, err := util.ReadFileAsString(path) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
parser := hclparse.NewParser() | ||
file, err := parseHcl(parser, configString, path) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
extensions := config.EvalContextExtensions{} | ||
evalContext := config.CreateTerragruntEvalContext(path, terragruntOptions, extensions) | ||
|
||
// Mock all the functions out so they don't do anything. Otherwise they may throw errors that we don't care about | ||
evalContext.Functions = map[string]function.Function{} | ||
|
||
// We don't need to check the errors/diagnostics coming from `DecodeBody`, as when errors come up, | ||
// it will leave the partially parsed result in the output object. | ||
var parsed parsedHcl | ||
gohcl.DecodeBody(file.Body, evalContext, &parsed) | ||
|
||
if parsed.Terraform == nil || parsed.Terraform.Source == nil { | ||
return true, nil | ||
} | ||
|
||
return 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,5 @@ | ||
locals { | ||
account_name = "prod" | ||
aws_account_id = "000000000" | ||
aws_profile = "prod" | ||
} |
11 changes: 11 additions & 0 deletions
11
test_examples/invalid_parent_module/child/deep/terragrunt.hcl
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,11 @@ | ||
include { | ||
path = find_in_parent_folders() | ||
} | ||
|
||
terraform { | ||
source = "git::git@github.com:transcend-io/terraform-aws-fargate-container?ref=v0.0.4" | ||
} | ||
|
||
inputs = { | ||
foo = "bar" | ||
} |
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 @@ | ||
locals { | ||
environment = "prod" | ||
} |
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 @@ | ||
locals { | ||
aws_region = "eu-west-1" | ||
} |
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,56 @@ | ||
###################################################################################################################### | ||
# This file (and test directory) is a fork of https://github.com/gruntwork-io/terragrunt-infrastructure-live-example # | ||
###################################################################################################################### | ||
|
||
locals { | ||
account_vars = read_terragrunt_config(find_in_parent_folders("account.hcl")) | ||
region_vars = read_terragrunt_config(find_in_parent_folders("region.hcl")) | ||
environment_vars = read_terragrunt_config(find_in_parent_folders("env.hcl")) | ||
account_name = local.account_vars.locals.account_name | ||
account_id = local.account_vars.locals.aws_account_id | ||
aws_region = local.region_vars.locals.aws_region | ||
} | ||
|
||
# Generate an AWS provider block | ||
generate "provider" { | ||
path = "provider.tf" | ||
if_exists = "overwrite_terragrunt" | ||
contents = <<EOF | ||
provider "aws" { | ||
region = "${local.aws_region}" | ||
# Only these AWS Account IDs may be operated on by this template | ||
allowed_account_ids = ["${local.account_id}"] | ||
} | ||
EOF | ||
} | ||
|
||
# Configure Terragrunt to automatically store tfstate files in an S3 bucket | ||
remote_state { | ||
backend = "s3" | ||
config = { | ||
encrypt = true | ||
bucket = "${get_env("TG_BUCKET_PREFIX", "")}terragrunt-example-terraform-state-${local.account_name}-${local.aws_region}" | ||
key = "${path_relative_to_include()}/terraform.tfstate" | ||
region = local.aws_region | ||
dynamodb_table = "terraform-locks" | ||
} | ||
generate = { | ||
path = "backend.tf" | ||
if_exists = "overwrite_terragrunt" | ||
} | ||
} | ||
|
||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# GLOBAL PARAMETERS | ||
# These variables apply to all configurations in this subfolder. These are automatically merged into the child | ||
# `terragrunt.hcl` config via the include block. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Configure root level variables that all resources can inherit. This is especially helpful with multi-account configs | ||
# where terraform_remote_state data sources are placed directly into the modules. | ||
inputs = merge( | ||
local.account_vars.locals, | ||
local.region_vars.locals, | ||
local.environment_vars.locals, | ||
) |
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 @@ | ||
locals { | ||
ahhhhhh = "pst" | ||
} |