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(terraform/lock): parse provider hostname onto lock download client #1870

Merged
merged 2 commits into from
Jan 15, 2024

Conversation

mcwarman
Copy link
Member

@mcwarman mcwarman commented Jan 14, 2024

This enables support for opentofu for lock files.

The provider already supported providing full provider names ex: registry.opentofu.org/hashicorp/hcp, but the hostname wasn't parsed onto the lock client (Which defaults to registry.terraform.io). By passing this on it adds support for opentofu with very little changes.

Part of: #1861

Test

To test this pull request, you can run the following commands:

go test ./pkg/plugins/resources/terraform/lock/

Also tested with existing terraform project.

go build -o ./bin/updatecli
cd ../../terraform-project
tofu init  # which updates lock file with registry.opentofu.org
../../bin/updatecli diff

Then adding the hostname to the provider:

targets:
  provider:
    name: 'Bump hashicorp/hcp to {{ source "latestRelease" }}'
    kind: terraform/lock
    sourceid: latestRelease
    spec:
      files:
        - .terraform.lock.hcl
      provider: registry.opentofu.org/hashicorp/hcp
      skipconstraints: true
      platforms:
        - darwin_amd64
        - linux_amd64
        - windows_amd64

Produces the following output:

provider
--------

**Dry Run enabled**

2024/01/14 20:34:18 [DEBUG] providerIndex.createProviderVersion: registry.opentofu.org/hashicorp/hcp, 0.80.0, darwin_amd64
2024/01/14 20:34:18 [DEBUG] Client.ProviderPackageMetadata: GET https://registry.opentofu.org/v1/providers/hashicorp/hcp/0.80.0/download/darwin/amd64
2024/01/14 20:34:18 [DEBUG] ProviderDownloaderClient.download: GET https://github.com/opentofu/terraform-provider-hcp/releases/download/v0.80.0/terraform-provider-hcp_0.80.0_darwin_amd64.zip
2024/01/14 20:34:19 [DEBUG] ProviderDownloaderClient.download: GET https://github.com/opentofu/terraform-provider-hcp/releases/download/v0.80.0/terraform-provider-hcp_0.80.0_SHA256SUMS
2024/01/14 20:34:20 [DEBUG] providerIndex.createProviderVersion: registry.opentofu.org/hashicorp/hcp, 0.80.0, linux_amd64
2024/01/14 20:34:20 [DEBUG] Client.ProviderPackageMetadata: GET https://registry.opentofu.org/v1/providers/hashicorp/hcp/0.80.0/download/linux/amd64
2024/01/14 20:34:20 [DEBUG] ProviderDownloaderClient.download: GET https://github.com/opentofu/terraform-provider-hcp/releases/download/v0.80.0/terraform-provider-hcp_0.80.0_linux_amd64.zip
2024/01/14 20:34:22 [DEBUG] ProviderDownloaderClient.download: GET https://github.com/opentofu/terraform-provider-hcp/releases/download/v0.80.0/terraform-provider-hcp_0.80.0_SHA256SUMS
2024/01/14 20:34:22 [DEBUG] providerIndex.createProviderVersion: registry.opentofu.org/hashicorp/hcp, 0.80.0, windows_amd64
2024/01/14 20:34:22 [DEBUG] Client.ProviderPackageMetadata: GET https://registry.opentofu.org/v1/providers/hashicorp/hcp/0.80.0/download/windows/amd64
2024/01/14 20:34:22 [DEBUG] ProviderDownloaderClient.download: GET https://github.com/opentofu/terraform-provider-hcp/releases/download/v0.80.0/terraform-provider-hcp_0.80.0_windows_amd64.zip
2024/01/14 20:34:23 [DEBUG] ProviderDownloaderClient.download: GET https://github.com/opentofu/terraform-provider-hcp/releases/download/v0.80.0/terraform-provider-hcp_0.80.0_SHA256SUMS
⚠ - "registry.opentofu.org/hashicorp/hcp" updated from "0.79.0" to "0.80.0" in file ".terraform.lock.hcl"

Additional Information

Tradeoff

Potential improvement

Further investigation into differences between opentofu and terraform as they deveop.

Add documentation for opentofu support.

Provider support for opentofu still needs to be added.

@olblak olblak merged commit ab6854d into updatecli:main Jan 15, 2024
6 checks passed
@mcwarman mcwarman deleted the feature/opentofu branch February 16, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request resource-terraform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants