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

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 80 additions & 0 deletions lib/modules/manager/terraform/lockfile/index.spec.ts
Expand Up @@ -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',
Expand Down
14 changes: 14 additions & 0 deletions lib/modules/manager/terraform/lockfile/index.ts
Expand Up @@ -177,6 +177,20 @@ export async function updateArtifacts({
if (!updateLock) {
continue;
}
if (dep.isLockfileUpdate) {
secustor marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down