Skip to content

Commit

Permalink
feat(manager/terragrunt): support lockFileMaintenance (#20833)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
  • Loading branch information
3 people authored May 18, 2023
1 parent 7cfd714 commit 2904637
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
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`.

0 comments on commit 2904637

Please sign in to comment.