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/lockfile): use registryURL defined in lockfile #28886

Merged
merged 2 commits into from
May 7, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/modules/manager/terraform/lockfile/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('modules/manager/terraform/lockfile/index', () => {

it('update single dependency with exact constraint and depType provider', async () => {
fs.readLocalFile.mockResolvedValueOnce(codeBlock`
provider "registry.terraform.io/hashicorp/aws" {
provider "registry.opentofu.org/hashicorp/aws" {
version = "3.0.0"
constraints = "3.0.0"
hashes = [
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('modules/manager/terraform/lockfile/index', () => {
{
file: {
contents: codeBlock`
provider "registry.terraform.io/hashicorp/aws" {
provider "registry.opentofu.org/hashicorp/aws" {
version = "3.36.0"
constraints = "3.36.0"
hashes = [
Expand All @@ -126,7 +126,7 @@ describe('modules/manager/terraform/lockfile/index', () => {
},
]);
expect(mockHash.mock.calls).toEqual([
['https://registry.terraform.io', 'hashicorp/aws', '3.36.0'],
['https://registry.opentofu.org', 'hashicorp/aws', '3.36.0'],
]);
});

Expand Down
8 changes: 4 additions & 4 deletions lib/modules/manager/terraform/lockfile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { logger } from '../../../../logger';
import * as p from '../../../../util/promises';
import { escapeRegExp, regEx } from '../../../../util/regex';
import { GetPkgReleasesConfig, getPkgReleases } from '../../../datasource';
import { TerraformProviderDatasource } from '../../../datasource/terraform-provider';
import { get as getVersioning } from '../../../versioning';
import type {
UpdateArtifact,
Expand Down Expand Up @@ -167,9 +166,6 @@ export async function updateArtifacts({
massageProviderLookupName(dep);
const { registryUrls, newVersion, packageName } = dep;

const registryUrl = registryUrls
? registryUrls[0]
: TerraformProviderDatasource.defaultRegistryUrls[0];
const updateLock = locks.find(
(value) => value.packageName === packageName,
);
Expand All @@ -191,6 +187,10 @@ export async function updateArtifacts({
continue;
}
}

// use registryURL defined in the update and fall back to the one defined in the lockfile
const registryUrl = registryUrls?.[0] ?? updateLock.registryUrl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should read it on extract, so no user intervention is required .

the datasource is always filling registry url, so you fallback will probably never used at runtime

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should detect Terraform vs OpenTofu during extract, though this is not possible if there is no lock file. At least I'm not aware there is a reliable way.

This is picked up as expected, I have tested / debugged it against a real repo.


const newConstraint = getNewConstraint(dep, updateLock.constraints);
const update: ProviderLockUpdate = {
// TODO #22198
Expand Down
17 changes: 17 additions & 0 deletions lib/modules/manager/terraform/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
### Terraform vs OpenTofu

There is no way for Renovate to differentiate, if a user is a Terraform user or has already adopted OpenTofu.
Therefore, Renovate defaults currently to interpret providers without a registry definition to be located at `registry.terraform.io`.
This behaviour can be modified using `packageRules`:

```json title="Prefer releases from OpenTofu"
{
"packageRules": [
{
"matchDatasources": ["terraform-provider"],
"registryUrl": "https://registry.opentofu.org"
}
]
}
```

### Supported dependencies

Renovate supports updating the Terraform dependencies listed below.
Expand Down