Skip to content
Snippets Groups Projects
Unverified Commit f74ece18 authored by Maxime Brunet's avatar Maxime Brunet Committed by GitHub
Browse files

fix(terraform): skip lockfile update when version is pinned (#27404)

parent 03a28208
Branches
Tags
No related merge requests found
......@@ -188,6 +188,86 @@ describe('modules/manager/terraform/lockfile/index', () => {
]);
});
it('does not update dependency with exact constraint during lockfile update', async () => {
fs.readLocalFile.mockResolvedValueOnce(codeBlock`
provider "registry.terraform.io/hashicorp/aws" {
version = "3.0.0"
constraints = "3.0.0"
hashes = [
"aaa",
"bbb",
"ccc",
]
}
`);
fs.findLocalSiblingOrParent.mockResolvedValueOnce('.terraform.lock.hcl');
mockHash.mockResolvedValueOnce([
'h1:lDsKRxDRXPEzA4AxkK4t+lJd3IQIP2UoaplJGjQSp2s=',
'h1:6zB2hX7YIOW26OrKsLJn0uLMnjqbPNxcz9RhlWEuuSY=',
]);
const result = await updateArtifacts({
packageFileName: 'main.tf',
updatedDeps: [
{
depName: 'hashicorp/aws',
packageName: 'hashicorp/aws',
depType: 'required_provider',
currentVersion: '3.0.0',
currentValue: '3.0.0',
newVersion: '3.36.0',
newValue: '3.36.0',
isLockfileUpdate: true,
},
],
newPackageFileContent: '',
config,
});
expect(result).toBeNull();
});
it('does not update dependency with exact constraint within multiple during lockfile update', async () => {
fs.readLocalFile.mockResolvedValueOnce(codeBlock`
provider "registry.terraform.io/hashicorp/aws" {
version = "3.0.0"
constraints = "~> 3.0, 3.0.0"
hashes = [
"aaa",
"bbb",
"ccc",
]
}
`);
fs.findLocalSiblingOrParent.mockResolvedValueOnce('.terraform.lock.hcl');
mockHash.mockResolvedValueOnce([
'h1:lDsKRxDRXPEzA4AxkK4t+lJd3IQIP2UoaplJGjQSp2s=',
'h1:6zB2hX7YIOW26OrKsLJn0uLMnjqbPNxcz9RhlWEuuSY=',
]);
const result = await updateArtifacts({
packageFileName: 'main.tf',
updatedDeps: [
{
depName: 'hashicorp/aws',
packageName: 'hashicorp/aws',
depType: 'required_provider',
currentVersion: '3.0.0',
currentValue: '3.0.0',
newVersion: '3.36.0',
newValue: '3.36.0',
isLockfileUpdate: true,
},
],
newPackageFileContent: '',
config,
});
expect(result).toBeNull();
});
it('do not update dependency with depType module', async () => {
const result = await updateArtifacts({
packageFileName: 'main.tf',
......
......@@ -177,6 +177,20 @@ export async function updateArtifacts({
if (!updateLock) {
continue;
}
if (dep.isLockfileUpdate) {
const versioning = getVersioning(dep.versioning);
const satisfyingVersion = versioning.getSatisfyingVersion(
[dep.newVersion!],
updateLock.constraints,
);
if (!satisfyingVersion) {
logger.debug(
`Skipping. Lockfile update with "${newVersion}" does not statisfy constraints "${updateLock.constraints}" for "${packageName}"`,
);
continue;
}
}
const newConstraint = getNewConstraint(dep, updateLock.constraints);
const update: ProviderLockUpdate = {
// TODO #22198
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment