Skip to content
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

feat(terragrunt): add support for tfr prefix #26209

Merged
merged 17 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/1.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#real
terraform {
extra_arguments "common_vars" {
commands = ["plan", "apply"]

arguments = [
"-var-file=../../common.tfvars",
"-var-file=../region.tfvars"
]
}

before_hook "before_hook" {
commands = ["apply", "plan"]
execute = ["echo", "Running Terraform"]
}

source = "tfr:///myuser/myrepo//folder/modules/moduleone?ref=v0.0.9"

after_hook "after_hook" {
commands = ["apply", "plan"]
execute = ["echo", "Finished running Terraform"]
run_on_error = true
}
}

#submodule
terraform {
source = "tfr:///terraform-google-modules/kubernetes-engine/google//modules/private-cluster?version=1.2.3"
}

#bar
terraform {
source = "tfr:///terraform-aws-modules/vpc/aws?version=3.3.0"
}

#missing third backslash
terraform {
source = "tfr://terraform-aws-modules/vpc/aws?version=3.3.0"
}
26 changes: 26 additions & 0 deletions lib/modules/manager/terragrunt/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ describe('modules/manager/terragrunt/extract', () => {
expect(extractPackageFile('nothing here')).toBeNull();
});

it('extracts terragrunt sources using tfr protocol', () => {
const res = extractPackageFile(Fixtures.get('1.hcl'));
expect(res).toEqual({
deps: [
{
datasource: 'terraform-module',
depName: 'myuser/myrepo',
depType: 'terragrunt',
},
{
datasource: 'terraform-module',
depName: 'terraform-google-modules/kubernetes-engine/google',
depType: 'terragrunt',
},
{
datasource: 'terraform-module',
depName: 'terraform-aws-modules/vpc/aws',
depType: 'terragrunt',
},
{},
],
});
expect(res?.deps).toHaveLength(4);
expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(0);
ps-occrp marked this conversation as resolved.
Show resolved Hide resolved
});

it('extracts terragrunt sources', () => {
const res = extractPackageFile(Fixtures.get('2.hcl'));
expect(res).toEqual({
Expand Down
4 changes: 4 additions & 0 deletions lib/modules/manager/terragrunt/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export function analyseTerragruntModule(
const moduleParts = source.split('//')[0].split('/');
if (moduleParts[0] === '..') {
dep.skipReason = 'local';
} else if (source.startsWith('tfr:///')) {
dep.depType = 'terragrunt';
dep.depName = source.split('//')[1].split('?')[0].replace('/', '');
dep.datasource = TerraformModuleDatasource.id;
} else if (moduleParts.length >= 3) {
const hostnameMatch = hostnameMatchRegex.exec(source);
if (hostnameMatch?.groups) {
Expand Down