From 288ad1f9bd352c451941102b3d4b979f27f2a1c3 Mon Sep 17 00:00:00 2001 From: Emil Davtyan Date: Tue, 18 Apr 2023 07:01:29 +0200 Subject: [PATCH] feat: support depth URL argument in Terragrunt modules (#21494) Co-authored-by: Sebastian Poxhofer --- .../manager/terragrunt/__fixtures__/2.hcl | 6 +- .../manager/terragrunt/__fixtures__/3.hcl | 166 ++++++ .../manager/terragrunt/__fixtures__/4.hcl | 166 ++++++ .../__snapshots__/extract.spec.ts.snap | 171 ------ .../manager/terragrunt/extract.spec.ts | 494 +++++++++++++++++- lib/modules/manager/terragrunt/modules.ts | 4 +- 6 files changed, 828 insertions(+), 179 deletions(-) create mode 100644 lib/modules/manager/terragrunt/__fixtures__/3.hcl create mode 100644 lib/modules/manager/terragrunt/__fixtures__/4.hcl delete mode 100644 lib/modules/manager/terragrunt/__snapshots__/extract.spec.ts.snap diff --git a/lib/modules/manager/terragrunt/__fixtures__/2.hcl b/lib/modules/manager/terragrunt/__fixtures__/2.hcl index 29d30085460cf2..b99906d626d704 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/2.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/2.hcl @@ -33,9 +33,9 @@ terraform { source = "github.com/hashicorp/example?ref=next" } -#hostname +#IP terraform { - source = "https://104.196.242.174"example?ref=next" + source = "https://104.196.242.174/example?ref=next" } #local hostname @@ -63,7 +63,7 @@ terraform { source = "my.host.local/sources/example?ref=v1.2.1" } -#ip +#hostname terraform { source = "my.host/example?ref=next" } diff --git a/lib/modules/manager/terragrunt/__fixtures__/3.hcl b/lib/modules/manager/terragrunt/__fixtures__/3.hcl new file mode 100644 index 00000000000000..bfb076653db875 --- /dev/null +++ b/lib/modules/manager/terragrunt/__fixtures__/3.hcl @@ -0,0 +1,166 @@ +#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 = "github.com/myuser/myrepo//folder/modules/moduleone?ref=v0.0.9&depth=1" + + after_hook "after_hook" { + commands = ["apply", "plan"] + execute = ["echo", "Finished running Terraform"] + run_on_error = true + } +} + +#foo +terraform { + source = "github.com/hashicorp/example?ref=v1.0.0&depth=1" +} + +#bar +terraform { + source = "github.com/hashicorp/example?ref=next&depth=3" +} + +#IP +terraform { + source = "https://104.196.242.174/example?ref=next&depth=1" +} + +#local hostname +terraform { + source = "my.host.local/example?ref=v1.2.1&depth=1" +} + +#local hostname +terraform { + source = "my.host/modules/test" +} + +#local hostname +terraform { + source = "my.host/modules/test?ref=v1.2.1&depth=1" +} + +#local hostname +terraform { + source = "my.host" +} + +#local hostname +terraform { + source = "my.host.local/sources/example?ref=v1.2.1&depth=1" +} + +#hostname +terraform { + source = "my.host/example?ref=next&depth=1" +} + +#invalid +terraform { + source = "//terraform/module/test?ref=next&depth=1" +} + +#repo-with-non-semver-ref +terraform { + source = "github.com/githubuser/myrepo//terraform/modules/moduleone?ref=tfmodule_one-v0.0.9&depth=1" +} + +#repo-with-dot +terraform { + source = "github.com/hashicorp/example.2.3?ref=v1.0.0&depth=1" +} + +#repo-with-dot-and-git-suffix +terraform { + source = "github.com/hashicorp/example.2.3.git?ref=v1.0.0&depth=1" +} + +#source without pinning +terraform { + source = "hashicorp/consul/aws" +} + +# source with double-slash +terraform { + source = "github.com/tieto-cem/terraform-aws-ecs-task-definition//modules/container-definition?ref=v0.1.0&depth=1" +} + +# regular sources +terraform { + source = "github.com/tieto-cem/terraform-aws-ecs-task-definition?ref=v0.1.0&depth=1" +} + +terraform { + source = "git@github.com:hashicorp/example.git?ref=v2.0.0&depth=1" +} + +terraform { + source = "terraform-aws-modules/security-group/aws//modules/http-80" + +} + +terraform { + source = "terraform-aws-modules/security-group/aws" +} + +terraform { + source = "../../terraforms/fe" +} + +# nosource, ignored by test since it does not have source on the next line +terraform { + foo = "bar" +} + +# foobar +terraform { + source = "https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" +} + +# gittags +terraform { + source = "git::https://bitbucket.com/hashicorp/example?ref=v1.0.0&depth=1" +} + +# gittags_badversion +terraform { + source = "git::https://bitbucket.com/hashicorp/example?ref=next&depth=1" +} + +# gittags_subdir +terraform { + source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.1&depth=1" +} + +# gittags_http +terraform { + source = "git::http://bitbucket.com/hashicorp/example?ref=v1.0.2&depth=1" +} + +# gittags_ssh +terraform { + source = "git::ssh://git@bitbucket.com/hashicorp/example?ref=v1.0.3&depth=1" +} + +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line +terraform { + name = "foo" + dummy = "true" +} diff --git a/lib/modules/manager/terragrunt/__fixtures__/4.hcl b/lib/modules/manager/terragrunt/__fixtures__/4.hcl new file mode 100644 index 00000000000000..72889fb6aed347 --- /dev/null +++ b/lib/modules/manager/terragrunt/__fixtures__/4.hcl @@ -0,0 +1,166 @@ +#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 = "github.com/myuser/myrepo//folder/modules/moduleone?depth=1&ref=v0.0.9" + + after_hook "after_hook" { + commands = ["apply", "plan"] + execute = ["echo", "Finished running Terraform"] + run_on_error = true + } +} + +#foo +terraform { + source = "github.com/hashicorp/example?depth=5&ref=v1.0.0" +} + +#bar +terraform { + source = "github.com/hashicorp/example?depth=1&ref=next" +} + +#IP +terraform { + source = "https://104.196.242.174/example?depth=1&ref=next" +} + +#local hostname +terraform { + source = "my.host.local/example?depth=1&ref=v1.2.1" +} + +#local hostname +terraform { + source = "my.host/modules/test" +} + +#local hostname +terraform { + source = "my.host/modules/test?depth=1&ref=v1.2.1" +} + +#local hostname +terraform { + source = "my.host" +} + +#local hostname +terraform { + source = "my.host.local/sources/example?depth=1&ref=v1.2.1" +} + +#hostname +terraform { + source = "my.host/example?depth=1&ref=next" +} + +#invalid +terraform { + source = "//terraform/module/test?depth=1&ref=next" +} + +#repo-with-non-semver-ref +terraform { + source = "github.com/githubuser/myrepo//terraform/modules/moduleone?depth=1&ref=tfmodule_one-v0.0.9" +} + +#repo-with-dot +terraform { + source = "github.com/hashicorp/example.2.3?depth=1&ref=v1.0.0" +} + +#repo-with-dot-and-git-suffix +terraform { + source = "github.com/hashicorp/example.2.3.git?depth=1&ref=v1.0.0" +} + +#source without pinning +terraform { + source = "hashicorp/consul/aws" +} + +# source with double-slash +terraform { + source = "github.com/tieto-cem/terraform-aws-ecs-task-definition//modules/container-definition?depth=1&ref=v0.1.0" +} + +# regular sources +terraform { + source = "github.com/tieto-cem/terraform-aws-ecs-task-definition?depth=1&ref=v0.1.0" +} + +terraform { + source = "git@github.com:hashicorp/example.git?depth=1&ref=v2.0.0" +} + +terraform { + source = "terraform-aws-modules/security-group/aws//modules/http-80" + +} + +terraform { + source = "terraform-aws-modules/security-group/aws" +} + +terraform { + source = "../../terraforms/fe" +} + +# nosource, ignored by test since it does not have source on the next line +terraform { + foo = "bar" +} + +# foobar +terraform { + source = "https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" +} + +# gittags +terraform { + source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.0" +} + +# gittags_badversion +terraform { + source = "git::https://bitbucket.com/hashicorp/example?depth=1&ref=next" +} + +# gittags_subdir +terraform { + source = "git::https://bitbucket.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.1" +} + +# gittags_http +terraform { + source = "git::http://bitbucket.com/hashicorp/example?depth=1&ref=v1.0.2" +} + +# gittags_ssh +terraform { + source = "git::ssh://git@bitbucket.com/hashicorp/example?depth=1&ref=v1.0.3" +} + +# invalid, ignored by test since it does not have source on the next line +terraform { +} + +# unsupported terragrunt, ignored by test since it does not have source on the next line +terraform { + name = "foo" + dummy = "true" +} diff --git a/lib/modules/manager/terragrunt/__snapshots__/extract.spec.ts.snap b/lib/modules/manager/terragrunt/__snapshots__/extract.spec.ts.snap deleted file mode 100644 index 84d85982b1cb2a..00000000000000 --- a/lib/modules/manager/terragrunt/__snapshots__/extract.spec.ts.snap +++ /dev/null @@ -1,171 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`modules/manager/terragrunt/extract extractPackageFile() extracts terragrunt sources 1`] = ` -{ - "deps": [ - { - "currentValue": "v0.0.9", - "datasource": "github-tags", - "depName": "github.com/myuser/myrepo", - "depType": "github", - "packageName": "myuser/myrepo", - }, - { - "currentValue": "v1.0.0", - "datasource": "github-tags", - "depName": "github.com/hashicorp/example", - "depType": "github", - "packageName": "hashicorp/example", - }, - { - "currentValue": "next", - "datasource": "github-tags", - "depName": "github.com/hashicorp/example", - "depType": "github", - "packageName": "hashicorp/example", - }, - { - "skipReason": "no-source", - }, - {}, - { - "datasource": "terraform-module", - "depName": "my.host/modules/test", - "depType": "terragrunt", - "registryUrls": [ - "https://my.host", - ], - }, - { - "datasource": "terraform-module", - "depName": "my.host/modules/test?ref=v1.2.1", - "depType": "terragrunt", - "registryUrls": [ - "https://my.host", - ], - }, - {}, - { - "datasource": "terraform-module", - "depName": "my.host.local/sources/example?ref=v1.2.1", - "depType": "terragrunt", - "registryUrls": [ - "https://my.host.local", - ], - }, - {}, - {}, - { - "currentValue": "tfmodule_one-v0.0.9", - "datasource": "github-tags", - "depName": "github.com/githubuser/myrepo", - "depType": "github", - "packageName": "githubuser/myrepo", - }, - { - "currentValue": "v1.0.0", - "datasource": "github-tags", - "depName": "github.com/hashicorp/example.2.3", - "depType": "github", - "packageName": "hashicorp/example.2.3", - }, - { - "currentValue": "v1.0.0", - "datasource": "github-tags", - "depName": "github.com/hashicorp/example.2.3", - "depType": "github", - "packageName": "hashicorp/example.2.3", - }, - { - "datasource": "terraform-module", - "depName": "hashicorp/consul/aws", - "depType": "terragrunt", - }, - { - "currentValue": "v0.1.0", - "datasource": "github-tags", - "depName": "github.com/tieto-cem/terraform-aws-ecs-task-definition", - "depType": "github", - "packageName": "tieto-cem/terraform-aws-ecs-task-definition", - }, - { - "currentValue": "v0.1.0", - "datasource": "github-tags", - "depName": "github.com/tieto-cem/terraform-aws-ecs-task-definition", - "depType": "github", - "packageName": "tieto-cem/terraform-aws-ecs-task-definition", - }, - { - "currentValue": "v2.0.0", - "datasource": "github-tags", - "depName": "github.com/hashicorp/example", - "depType": "github", - "packageName": "hashicorp/example", - }, - { - "datasource": "terraform-module", - "depName": "terraform-aws-modules/security-group/aws", - "depType": "terragrunt", - }, - { - "datasource": "terraform-module", - "depName": "terraform-aws-modules/security-group/aws", - "depType": "terragrunt", - }, - { - "skipReason": "local", - }, - { - "skipReason": "no-source", - }, - { - "currentValue": "v1.0.0", - "datasource": "git-tags", - "depName": "bitbucket.com/hashicorp/example", - "depType": "gitTags", - "packageName": "https://bitbucket.com/hashicorp/example", - }, - { - "currentValue": "v1.0.0", - "datasource": "git-tags", - "depName": "bitbucket.com/hashicorp/example", - "depType": "gitTags", - "packageName": "https://bitbucket.com/hashicorp/example", - }, - { - "currentValue": "next", - "datasource": "git-tags", - "depName": "bitbucket.com/hashicorp/example", - "depType": "gitTags", - "packageName": "https://bitbucket.com/hashicorp/example", - }, - { - "currentValue": "v1.0.1", - "datasource": "git-tags", - "depName": "bitbucket.com/hashicorp/example", - "depType": "gitTags", - "packageName": "https://bitbucket.com/hashicorp/example", - }, - { - "currentValue": "v1.0.2", - "datasource": "git-tags", - "depName": "bitbucket.com/hashicorp/example", - "depType": "gitTags", - "packageName": "http://bitbucket.com/hashicorp/example", - }, - { - "currentValue": "v1.0.3", - "datasource": "git-tags", - "depName": "bitbucket.com/hashicorp/example", - "depType": "gitTags", - "packageName": "ssh://git@bitbucket.com/hashicorp/example", - }, - { - "skipReason": "no-source", - }, - { - "skipReason": "no-source", - }, - ], -} -`; diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index 9d9a201e1e9681..d4720df6168e5a 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -8,10 +8,498 @@ describe('modules/manager/terragrunt/extract', () => { }); it('extracts terragrunt sources', () => { - const res = extractPackageFile(Fixtures?.get('2.hcl')); - expect(res).toMatchSnapshot(); + const res = extractPackageFile(Fixtures.get('2.hcl')); + expect(res).toEqual({ + deps: [ + { + currentValue: 'v0.0.9', + datasource: 'github-tags', + depName: 'github.com/myuser/myrepo', + depType: 'github', + packageName: 'myuser/myrepo', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + {}, + {}, + { + datasource: 'terraform-module', + depName: 'my.host/modules/test', + depType: 'terragrunt', + registryUrls: ['https://my.host'], + }, + { + datasource: 'terraform-module', + depName: 'my.host/modules/test?ref=v1.2.1', + depType: 'terragrunt', + registryUrls: ['https://my.host'], + }, + {}, + { + datasource: 'terraform-module', + depName: 'my.host.local/sources/example?ref=v1.2.1', + depType: 'terragrunt', + registryUrls: ['https://my.host.local'], + }, + {}, + {}, + { + currentValue: 'tfmodule_one-v0.0.9', + datasource: 'github-tags', + depName: 'github.com/githubuser/myrepo', + depType: 'github', + packageName: 'githubuser/myrepo', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example.2.3', + depType: 'github', + packageName: 'hashicorp/example.2.3', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example.2.3', + depType: 'github', + packageName: 'hashicorp/example.2.3', + }, + { + datasource: 'terraform-module', + depName: 'hashicorp/consul/aws', + depType: 'terragrunt', + }, + { + currentValue: 'v0.1.0', + datasource: 'github-tags', + depName: 'github.com/tieto-cem/terraform-aws-ecs-task-definition', + depType: 'github', + packageName: 'tieto-cem/terraform-aws-ecs-task-definition', + }, + { + currentValue: 'v0.1.0', + datasource: 'github-tags', + depName: 'github.com/tieto-cem/terraform-aws-ecs-task-definition', + depType: 'github', + packageName: 'tieto-cem/terraform-aws-ecs-task-definition', + }, + { + currentValue: 'v2.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + { + datasource: 'terraform-module', + depName: 'terraform-aws-modules/security-group/aws', + depType: 'terragrunt', + }, + { + datasource: 'terraform-module', + depName: 'terraform-aws-modules/security-group/aws', + depType: 'terragrunt', + }, + { + skipReason: 'local', + }, + { + skipReason: 'no-source', + }, + { + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@bitbucket.com/hashicorp/example', + }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, + ], + }); expect(res?.deps).toHaveLength(30); - expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(5); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); + }); + + it('extracts terragrunt sources with depth specified after the branch', () => { + const res = extractPackageFile(Fixtures.get('3.hcl')); + expect(res).toEqual({ + deps: [ + { + currentValue: 'v0.0.9', + datasource: 'github-tags', + depName: 'github.com/myuser/myrepo', + depType: 'github', + packageName: 'myuser/myrepo', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + {}, + {}, + { + datasource: 'terraform-module', + depName: 'my.host/modules/test', + depType: 'terragrunt', + registryUrls: ['https://my.host'], + }, + { + datasource: 'terraform-module', + depName: 'my.host/modules/test?ref=v1.2.1&depth=1', + depType: 'terragrunt', + registryUrls: ['https://my.host'], + }, + {}, + { + datasource: 'terraform-module', + depName: 'my.host.local/sources/example?ref=v1.2.1&depth=1', + depType: 'terragrunt', + registryUrls: ['https://my.host.local'], + }, + {}, + {}, + { + currentValue: 'tfmodule_one-v0.0.9', + datasource: 'github-tags', + depName: 'github.com/githubuser/myrepo', + depType: 'github', + packageName: 'githubuser/myrepo', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example.2.3', + depType: 'github', + packageName: 'hashicorp/example.2.3', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example.2.3', + depType: 'github', + packageName: 'hashicorp/example.2.3', + }, + { + datasource: 'terraform-module', + depName: 'hashicorp/consul/aws', + depType: 'terragrunt', + }, + { + currentValue: 'v0.1.0', + datasource: 'github-tags', + depName: 'github.com/tieto-cem/terraform-aws-ecs-task-definition', + depType: 'github', + packageName: 'tieto-cem/terraform-aws-ecs-task-definition', + }, + { + currentValue: 'v0.1.0', + datasource: 'github-tags', + depName: 'github.com/tieto-cem/terraform-aws-ecs-task-definition', + depType: 'github', + packageName: 'tieto-cem/terraform-aws-ecs-task-definition', + }, + { + currentValue: 'v2.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + { + datasource: 'terraform-module', + depName: 'terraform-aws-modules/security-group/aws', + depType: 'terragrunt', + }, + { + datasource: 'terraform-module', + depName: 'terraform-aws-modules/security-group/aws', + depType: 'terragrunt', + }, + { + skipReason: 'local', + }, + { + skipReason: 'no-source', + }, + { + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@bitbucket.com/hashicorp/example', + }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, + ], + }); + expect(res?.deps).toHaveLength(30); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); + }); + + it('extracts terragrunt sources with depth specified before the branch', () => { + const res = extractPackageFile(Fixtures.get('4.hcl')); + expect(res).toEqual({ + deps: [ + { + currentValue: 'v0.0.9', + datasource: 'github-tags', + depName: 'github.com/myuser/myrepo', + depType: 'github', + packageName: 'myuser/myrepo', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + {}, + {}, + { + datasource: 'terraform-module', + depName: 'my.host/modules/test', + depType: 'terragrunt', + registryUrls: ['https://my.host'], + }, + { + datasource: 'terraform-module', + depName: 'my.host/modules/test?depth=1&ref=v1.2.1', + depType: 'terragrunt', + registryUrls: ['https://my.host'], + }, + {}, + { + datasource: 'terraform-module', + depName: 'my.host.local/sources/example?depth=1&ref=v1.2.1', + depType: 'terragrunt', + registryUrls: ['https://my.host.local'], + }, + {}, + {}, + { + currentValue: 'tfmodule_one-v0.0.9', + datasource: 'github-tags', + depName: 'github.com/githubuser/myrepo', + depType: 'github', + packageName: 'githubuser/myrepo', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example.2.3', + depType: 'github', + packageName: 'hashicorp/example.2.3', + }, + { + currentValue: 'v1.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example.2.3', + depType: 'github', + packageName: 'hashicorp/example.2.3', + }, + { + datasource: 'terraform-module', + depName: 'hashicorp/consul/aws', + depType: 'terragrunt', + }, + { + currentValue: 'v0.1.0', + datasource: 'github-tags', + depName: 'github.com/tieto-cem/terraform-aws-ecs-task-definition', + depType: 'github', + packageName: 'tieto-cem/terraform-aws-ecs-task-definition', + }, + { + currentValue: 'v0.1.0', + datasource: 'github-tags', + depName: 'github.com/tieto-cem/terraform-aws-ecs-task-definition', + depType: 'github', + packageName: 'tieto-cem/terraform-aws-ecs-task-definition', + }, + { + currentValue: 'v2.0.0', + datasource: 'github-tags', + depName: 'github.com/hashicorp/example', + depType: 'github', + packageName: 'hashicorp/example', + }, + { + datasource: 'terraform-module', + depName: 'terraform-aws-modules/security-group/aws', + depType: 'terragrunt', + }, + { + datasource: 'terraform-module', + depName: 'terraform-aws-modules/security-group/aws', + depType: 'terragrunt', + }, + { + skipReason: 'local', + }, + { + skipReason: 'no-source', + }, + { + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.0', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'next', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.1', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'https://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.2', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'http://bitbucket.com/hashicorp/example', + }, + { + currentValue: 'v1.0.3', + datasource: 'git-tags', + depName: 'bitbucket.com/hashicorp/example', + depType: 'gitTags', + packageName: 'ssh://git@bitbucket.com/hashicorp/example', + }, + { + skipReason: 'no-source', + }, + { + skipReason: 'no-source', + }, + ], + }); + expect(res?.deps).toHaveLength(30); + expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); it('returns null if only local terragrunt deps', () => { diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index e4bd9901a739b9..43a0987735f3ef 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -8,10 +8,10 @@ import { extractTerragruntProvider } from './providers'; import type { ExtractionResult, TerraformManagerData } from './types'; export const githubRefMatchRegex = regEx( - /github\.com([/:])(?[^/]+\/[a-z0-9-_.]+).*\?ref=(?.*)$/i + /github\.com([/:])(?[^/]+\/[a-z0-9-_.]+).*\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/i ); export const gitTagsRefMatchRegex = regEx( - /(?:git::)?(?(?:http|https|ssh):\/\/(?:.*@)?(?.*.*\/(?.*\/.*)))\?ref=(?.*)$/ + /(?:git::)?(?(?:http|https|ssh):\/\/(?:.*@)?(?.*.*\/(?.*\/.*)))\?(depth=\d+&)?ref=(?.*?)(&depth=\d+)?$/ ); const hostnameMatchRegex = regEx(/^(?([\w|\d]+\.)+[\w|\d]+)/);