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(manager/terragrunt): support lockFileMaintenance #20833

Merged
merged 47 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
480678e
terragrunt configurations sometimes have no tf files, but do have ter…
spilliams Mar 9, 2023
8ff17c5
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 10, 2023
2281410
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 13, 2023
a064d66
maintain code coverage
spilliams Mar 13, 2023
2fa4c02
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 13, 2023
c8bbff4
Merge branch 'main' into feat/13393-terragrunt-lockfiles
rarkins Mar 14, 2023
0fc3a75
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 14, 2023
ee132c9
terragrunt should update lockfiles whenever terraform would
spilliams Mar 14, 2023
88abfd2
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 16, 2023
6ae7859
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 17, 2023
81e7f7f
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 20, 2023
7d17369
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 20, 2023
5fa3787
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 24, 2023
f04450b
Revert "terragrunt should update lockfiles whenever terraform would"
spilliams Mar 29, 2023
126cda5
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 29, 2023
95a472c
manager should log when it takes no action
spilliams Mar 30, 2023
66ff0ad
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 30, 2023
00e2865
linter must pass
spilliams Mar 30, 2023
1c259c7
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 30, 2023
8aa9523
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Mar 30, 2023
db89e91
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 5, 2023
1f834c1
match other managers
spilliams Apr 5, 2023
a0db415
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 11, 2023
a039dcf
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 12, 2023
03b74b0
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 13, 2023
2b6b1c3
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 14, 2023
41caaeb
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 17, 2023
6379cc3
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 19, 2023
f9f0077
limitations should be clear
spilliams Apr 20, 2023
d00e607
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 20, 2023
f7a55f3
Update lib/modules/manager/terragrunt/readme.md
rarkins Apr 21, 2023
c7d570b
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 21, 2023
65aec85
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 27, 2023
b58efcf
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 28, 2023
47df737
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams Apr 28, 2023
eb274e9
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams May 1, 2023
3951e12
incorrect statement
spilliams May 1, 2023
66cb6fd
better use of table-driven testing
spilliams May 1, 2023
b755e91
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams May 2, 2023
61de108
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams May 3, 2023
50d7d80
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams May 15, 2023
f6a221b
this does nothing without dynamic imports
spilliams May 15, 2023
a6d1cbc
this does nothing: we don't set any explicit mocks
spilliams May 15, 2023
5fa3ef0
keep mocks closer to the actual test, for clarity
spilliams May 15, 2023
380d7df
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams May 15, 2023
5245c69
Merge branch 'main' into feat/13393-terragrunt-lockfiles
spilliams May 16, 2023
9eb098e
Merge branch 'main' into feat/13393-terragrunt-lockfiles
rarkins May 18, 2023
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
71 changes: 71 additions & 0 deletions lib/modules/manager/terragrunt/artifacts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { join } from 'upath';
import { GlobalConfig } from '../../../config/global';
import type { UpdateType } from '../../../config/types';
import * as terraformLockfile from '../terraform/lockfile';
import type { UpdateArtifactsConfig } from '../types';
import { updateArtifacts } from './artifacts';

jest.mock('../terraform/lockfile');

const config = {
constraints: {},
};

const adminConfig = {
// `join` fixes Windows CI
localDir: join('/tmp/github/some/repo'),
cacheDir: join('/tmp/renovate/cache'),
containerbaseDir: join('/tmp/renovate/cache/containerbase'),
};

describe('modules/manager/terragrunt/artifacts', () => {
const updateTypes: UpdateType[] = [
'digest',
'pin',
'rollback',
'patch',
'minor',
'major',
'replacement',
'pinDigest',
'lockfileUpdate',
'bump',
];

beforeEach(() => {
GlobalConfig.set(adminConfig);
});

it('calls terraform updateArtifacts if the update type is lockfileMaintenance', async () => {
const localConfig: UpdateArtifactsConfig = {
updateType: 'lockFileMaintenance',
...config,
};

await updateArtifacts({
packageFileName: '',
updatedDeps: [],
newPackageFileContent: '',
config: localConfig,
});
expect(terraformLockfile.updateArtifacts).toHaveBeenCalledOnce();
});

it.each(updateTypes)(
'does not call terraform updateArtifacts if the update type is %s',
async (updateType) => {
const localConfig: UpdateArtifactsConfig = {
updateType,
...config,
};

await updateArtifacts({
packageFileName: '',
updatedDeps: [],
newPackageFileContent: '',
config: localConfig,
});
expect(terraformLockfile.updateArtifacts).not.toHaveBeenCalled();
}
);
});
18 changes: 18 additions & 0 deletions lib/modules/manager/terragrunt/artifacts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { logger } from '../../../logger';
import { updateArtifacts as updateTerraformArtifacts } from '../terraform/lockfile/index';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';

export async function updateArtifacts(
artifact: UpdateArtifact
): Promise<UpdateArtifactsResult[] | null> {
if (artifact.config.updateType !== 'lockFileMaintenance') {
logger.debug(
`UpdateType ${
artifact.config.updateType as string
} is not supported for terragrunt`
);
return null;
}

return await updateTerraformArtifacts(artifact);
}
2 changes: 2 additions & 0 deletions lib/modules/manager/terragrunt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GitTagsDatasource } from '../../datasource/git-tags';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { TerraformModuleDatasource } from '../../datasource/terraform-module';

export { updateArtifacts } from './artifacts';
export { extractPackageFile } from './extract';

export const supportedDatasources = [
Expand All @@ -10,6 +11,7 @@ export const supportedDatasources = [
TerraformModuleDatasource.id,
];

export const supportsLockFileMaintenance = true;
export const defaultConfig = {
commitMessageTopic: 'Terragrunt dependency {{depName}}',
fileMatch: ['(^|/)terragrunt\\.hcl$'],
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/manager/terragrunt/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ terraform {
source = "github.com/hashicorp/example?ref=v1.0.0"
}
```

### Terraform lockfiles

The Terragrunt manager supports [lock file maintenance](https://docs.renovatebot.com/configuration-options/#lockfilemaintenance) for `.terraform.lock.hcl` artifacts.
These artifacts will be updated if and only if the update type is `lockFileMaintenance`.