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

Check lock file diagnostics in mirror command #35322

Merged
merged 3 commits into from
Jun 18, 2024
Merged

Conversation

jbardin
Copy link
Member

@jbardin jbardin commented Jun 10, 2024

The lock file diagnostic were not being checked in the mirror command, so an incomplete or broken lock file might cause the cli to crash.

Add -lock-file flag to providers mirror command, so that a user can proceed to create a mirror with an incomplete lock file when running init is not an option.

Fixes #35318

The lock file diagnostic were not being checked in the mirror command,
so an incomplete or broken lock file might cause the cli to crash.
@jbardin jbardin added the 1.9-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged label Jun 10, 2024
@apparentlymart
Copy link
Contributor

This does seem plausible, but since we added support for using the lock file in #32742 it seems like we have created ourselves a bit of a chicken/egg problem that would be exacerbated by this change.

The original goal of terraform providers lock was to be an escape hatch for someone who has configured Terraform CLI to exclusively use a mirror for provider installation, so that they could use this command to update their mirror with new packages taken from their origin registries. Without that extra step, terraform init would fail because the provider isn't yet available in the mirror.

If we were to merge this change it seems like we'd break that use-case, because any newly-added provider would be absent from the lock file, terraform providers mirror would fail telling the user to run terraform init -upgrade, and then terraform init -upgrade would fail because the necessary provider package isn't available in the mirror yet.

#32742 already slightly broke that use-case as we saw in #35318, but the change proposed in this PR seems like it would break it entirely.

I can think of a couple different compromises that we could take from here:

  • Make terraform providers mirror command use the lock file opportunistically when it contains an entry specifically for the provider under consideration, but to treat any problems with the dependency lock file as if the relevant entry in the file wasn't present at all.

  • Do what you proposed in this PR, but also add a new option to terraform providers mirror that restores the pre-bugfix: terraform providers mirror command should honor terraform lock file #32742 behavior of ignoring the lock file entirely so that someone who is using that command with the goal it was originally intended for can use the new option to force it to work. Perhaps terraform providers mirror -upgrade would be a plausible name for it, to match the option of the same name on terraform init that also effectively means "ignore the lock file".

    (If we take this option then we should probably mention it as an option in the error message about the lock file being inconsistent. I'm not sure though whether we should prioritize terraform init -upgrade or terraform providers mirror -upgrade as the primary solution listed first, since of course it depends on what the person was trying to achieve. The latter solution is more suitable for someone using terraform providers mirror for its original intended purpose.)

@jbardin
Copy link
Member Author

jbardin commented Jun 10, 2024

Thanks @apparentlymart, that matches my what I was looking into myself. I was intending this to work like the former of your options, but inspecting more closely it seems that the lock file was not expected to be there or complete.

I don't think this patch makes things any worse, the error it's surfacing would happen regardless, it just guards the panic. I guess you could say it might "work" in that the mirror files would be created, but terraform would still exit with an error. There's not really any good way to deal with a partial lock file however, without making this an explicit option somehow.

@jbardin jbardin marked this pull request as draft June 10, 2024 20:38
@apparentlymart
Copy link
Contributor

Ah yes, I suppose you are right that this is just replacing the panic with an error.

I was imagining that the current code would allow you to change the version constraint for a provider that's already tracked in the lock file and then use terraform providers mirror to update the mirror to contain a package that matches the new version constraint, because the consistency check result was ignored.

But of course that doesn't hold because the subsequent logic would still use the selection from the dependency lock file anyway, so you'd end up just populating the mirror with whatever version was previously selected regardless of what's in the configuration. Although that case would now also be an error, the error isn't actually replacing a useful behavior.

@jbardin
Copy link
Member Author

jbardin commented Jun 11, 2024

I'm kind of inclined to add an option to use the lock file, rather than add an option to ignore it. Seeing how we've had both behaviors in releases already, either change is breaking in some way. I do think we need to add an option of some sort, so I guess it's just a matter of choosing between reverting to the original intended behavior along with something like -use-lock-file, or keeping the current behavior with a -ignore-lock-file flag 🤔

The providers mirror command was updated to inspect the lock file,
however that was not part of the original intent for the command, and
it's possible that the command needs to be run without a lock file.

Since we have been honoring the lock file for the past few releases,
let's keep that consistent and allow disabling the file with
`-lock-file=false`.
@jbardin jbardin requested a review from a team June 11, 2024 20:37
@jbardin
Copy link
Member Author

jbardin commented Jun 11, 2024

OK, proposing that we add a -lock-file flag, which defaults to true in order to maintain the current behavior. This can be now overridden with -lock-file=false. If this looks good, I'll add the docs and help text output to match.

Copy link
Member

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

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

  • Tested this to reproduce the bug, verify that the "diags not panic" change works, and verify that the new flag switches lock behaviors. All looks solid!
  • I approve the new flag name, and I think the default makes sense.

@jbardin jbardin marked this pull request as ready for review June 14, 2024 20:23
@jbardin jbardin requested a review from nfagerlund June 14, 2024 20:24
@jbardin jbardin requested a review from a team June 17, 2024 13:10
@jbardin jbardin merged commit 3ddd97f into main Jun 18, 2024
7 checks passed
@jbardin jbardin deleted the jbardin/mirror-lock branch June 18, 2024 17:11
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1.9-backport If you add this label to a PR before merging, backport-assistant will open a new PR once merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform crashes on mirroring the cloudflare provider
4 participants