-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes `isPathInRepo` to use wd directory instead of `RepoPath` which is likely incorrect for Terragrunt projects. The `RepoPath` property that is infered from detected projects was returning full project path for detected projects when the autdetected project was inferred from a config file. A fix for this will be addressed in a further PR. To fix the templatefile logic I've opted to use the os working directory instead, as this is more robust.
- Loading branch information
Showing
22 changed files
with
728 additions
and
7 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
190 changes: 190 additions & 0 deletions
190
cmd/infracost/testdata/breakdown_terraform_file_funcs/breakdown_terraform_file_funcs.golden
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
cmd/infracost/testdata/breakdown_terraform_file_funcs/instance.json
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 @@ | ||
{ | ||
"instance_type": "m5.large" | ||
} |
70 changes: 70 additions & 0 deletions
70
cmd/infracost/testdata/breakdown_terraform_file_funcs/main.tf
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,70 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
access_key = "mock_access_key" | ||
secret_key = "mock_secret_key" | ||
} | ||
|
||
locals { | ||
files = [ | ||
{ name = "cd", file = "instance.json", }, | ||
{ name = "sym", file = "sym-instance.json", }, | ||
{ name = "pd", file = "../../../testdata/instance.json", }, | ||
{ | ||
name = "abs", | ||
file = "/home/runner/work/infracost/infracost/cmd/infracost/testdata/breakdown_terraform_file_funcs/instance.json", | ||
}, | ||
{ name = "pdabs", file = "/home/runner/work/infracost/infracost/cmd/testdata/instance.json", }, | ||
] | ||
dirs = [ | ||
{ name = "cd", dir = "." }, | ||
{ name = "pd", dir = "../../../testdata" }, | ||
{ name = "abs", dir = "/home/runner/work/infracost/infracost/cmd/infracost/testdata/breakdown_terraform_file_funcs/" }, | ||
{ name = "pdabs", dir = "/home/runner/work/infracost/infracost/cmd/testdata/" }, | ||
|
||
] | ||
template_files = [ | ||
{ name = "cd", file = "templ.tftpl", }, | ||
{ name = "pd", file = "../../../testdata/templ.tftpl", }, | ||
{ | ||
name = "abs", file = "/home/runner/work/infracost/infracost/cmd/infracost/testdata/breakdown_terraform_file_funcs/templ.tftpl", | ||
}, | ||
{ name = "pdabs", file = "/home/runner/work/infracost/infracost/cmd/testdata/templ.tftpl", } | ||
] | ||
} | ||
|
||
resource "aws_instance" "file" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
|
||
ami = "ami-674cbc1e" | ||
instance_type = jsondecode(file(each.value)).instance_type | ||
} | ||
|
||
module "mod_files" { | ||
source = "./modules/test" | ||
} | ||
|
||
resource "aws_instance" "fileexists" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
ami = "ami-674cbc1e" | ||
instance_type = fileexists(each.value) ? "e" : "ne" | ||
} | ||
|
||
resource "aws_instance" "fileset" { | ||
for_each = { for f in local.dirs : f.name => f.dir } | ||
ami = "ami-674cbc1e" | ||
instance_type = length(fileset(each.value, "*.json")) | ||
} | ||
|
||
resource "aws_instance" "filemd5" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
ami = "ami-674cbc1e" | ||
instance_type = filemd5(each.value) | ||
} | ||
|
||
resource "aws_instance" "template_file" { | ||
for_each = { for f in local.template_files : f.name => f.file } | ||
ami = "ami-674cbc1e" | ||
instance_type = jsondecode(templatefile(each.value, {})).instance_type | ||
} |
3 changes: 3 additions & 0 deletions
3
cmd/infracost/testdata/breakdown_terraform_file_funcs/modules/test/instance.json
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 @@ | ||
{ | ||
"instance_type": "m5.2xlarge" | ||
} |
21 changes: 21 additions & 0 deletions
21
cmd/infracost/testdata/breakdown_terraform_file_funcs/modules/test/main.tf
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,21 @@ | ||
locals { | ||
files = [ | ||
{ name = "cd", file = "${path.module}/instance.json", }, | ||
{ name = "rootcd", file = "${path.module}/../../instance.json", }, | ||
{ name = "pd", file = "${path.module}/../../../../testdata/instance.json", }, | ||
] | ||
} | ||
|
||
resource "aws_instance" "file" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
|
||
ami = "ami-674cbc1e" | ||
instance_type = jsondecode(file(each.value)).instance_type | ||
} | ||
|
||
resource "aws_instance" "fileexists" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
|
||
ami = "ami-674cbc1e" | ||
instance_type = fileexists(each.value) ? "e" : "ne" | ||
} |
1 change: 1 addition & 0 deletions
1
cmd/infracost/testdata/breakdown_terraform_file_funcs/sym-instance.json
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 @@ | ||
../../../testdata/instance.json |
3 changes: 3 additions & 0 deletions
3
cmd/infracost/testdata/breakdown_terraform_file_funcs/templ.tftpl
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 @@ | ||
${jsonencode({ | ||
"instance_type": "t2.micro", | ||
})} |
190 changes: 190 additions & 0 deletions
190
...infracost/testdata/breakdown_terragrunt_file_funcs/breakdown_terragrunt_file_funcs.golden
Large diffs are not rendered by default.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/instance.json
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 @@ | ||
{ | ||
"instance_type": "m5.large" | ||
} |
70 changes: 70 additions & 0 deletions
70
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/main.tf
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,70 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
skip_credentials_validation = true | ||
skip_requesting_account_id = true | ||
access_key = "mock_access_key" | ||
secret_key = "mock_secret_key" | ||
} | ||
|
||
locals { | ||
files = [ | ||
{ name = "cd", file = "instance.json", }, | ||
{ name = "sym", file = "sym-instance.json", }, | ||
{ name = "pd", file = "../../../testdata/instance.json", }, | ||
{ | ||
name = "abs", | ||
file = "/home/runner/work/infracost/infracost/cmd/infracost/testdata/breakdown_terraform_file_funcs/instance.json", | ||
}, | ||
{ name = "pdabs", file = "/home/runner/work/infracost/infracost/cmd/testdata/instance.json", }, | ||
] | ||
dirs = [ | ||
{ name = "cd", dir = "." }, | ||
{ name = "pd", dir = "../../../testdata" }, | ||
{ name = "abs", dir = "/home/runner/work/infracost/infracost/cmd/infracost/testdata/breakdown_terraform_file_funcs/" }, | ||
{ name = "pdabs", dir = "/home/runner/work/infracost/infracost/cmd/testdata/" }, | ||
|
||
] | ||
template_files = [ | ||
{ name = "cd", file = "templ.tftpl", }, | ||
{ name = "pd", file = "../../../testdata/templ.tftpl", }, | ||
{ | ||
name = "abs", file = "/home/runner/work/infracost/infracost/cmd/infracost/testdata/breakdown_terraform_file_funcs/templ.tftpl", | ||
}, | ||
{ name = "pdabs", file = "/home/runner/work/infracost/infracost/cmd/testdata/templ.tftpl", } | ||
] | ||
} | ||
|
||
resource "aws_instance" "file" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
|
||
ami = "ami-674cbc1e" | ||
instance_type = jsondecode(file(each.value)).instance_type | ||
} | ||
|
||
module "mod_files" { | ||
source = "./modules/test" | ||
} | ||
|
||
resource "aws_instance" "fileexists" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
ami = "ami-674cbc1e" | ||
instance_type = fileexists(each.value) ? "e" : "ne" | ||
} | ||
|
||
resource "aws_instance" "fileset" { | ||
for_each = { for f in local.dirs : f.name => f.dir } | ||
ami = "ami-674cbc1e" | ||
instance_type = length(fileset(each.value, "*.json")) | ||
} | ||
|
||
resource "aws_instance" "filemd5" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
ami = "ami-674cbc1e" | ||
instance_type = filemd5(each.value) | ||
} | ||
|
||
resource "aws_instance" "template_file" { | ||
for_each = { for f in local.template_files : f.name => f.file } | ||
ami = "ami-674cbc1e" | ||
instance_type = jsondecode(templatefile(each.value, {})).instance_type | ||
} |
3 changes: 3 additions & 0 deletions
3
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/modules/test/instance.json
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 @@ | ||
{ | ||
"instance_type": "m5.2xlarge" | ||
} |
21 changes: 21 additions & 0 deletions
21
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/modules/test/main.tf
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,21 @@ | ||
locals { | ||
files = [ | ||
{ name = "cd", file = "${path.module}/instance.json", }, | ||
{ name = "rootcd", file = "${path.module}/../../instance.json", }, | ||
{ name = "pd", file = "${path.module}/../../../../testdata/instance.json", }, | ||
] | ||
} | ||
|
||
resource "aws_instance" "file" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
|
||
ami = "ami-674cbc1e" | ||
instance_type = jsondecode(file(each.value)).instance_type | ||
} | ||
|
||
resource "aws_instance" "fileexists" { | ||
for_each = { for f in local.files : f.name => f.file } | ||
|
||
ami = "ami-674cbc1e" | ||
instance_type = fileexists(each.value) ? "e" : "ne" | ||
} |
1 change: 1 addition & 0 deletions
1
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/sym-instance.json
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 @@ | ||
../../../testdata/instance.json |
3 changes: 3 additions & 0 deletions
3
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/templ.tftpl
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 @@ | ||
${jsonencode({ | ||
"instance_type": "t2.micro", | ||
})} |
5 changes: 5 additions & 0 deletions
5
cmd/infracost/testdata/breakdown_terragrunt_file_funcs/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,5 @@ | ||
inputs = { | ||
get_aws_account_id = get_aws_account_id() | ||
get_aws_caller_identity_arn = get_aws_caller_identity_arn() | ||
get_aws_caller_identity_user_id = get_aws_caller_identity_user_id() | ||
} |
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 @@ | ||
{ | ||
"instance_type": "m5.8xlarge" | ||
} |
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 @@ | ||
${jsonencode({ | ||
"instance_type": "m5.12xlarge", | ||
})} |
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
Oops, something went wrong.