command: Make provider installation interruptible #26405
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In earlier commits we started to make the installation codepath context-aware so that it could be canceled in the event of a
SIGINT
, but we didn't complete wiring that through the API of thegetproviders
package.Here we make the
getproviders.Source
interface methods, along with some other functions that can make network requests, take acontext.Context
argument and act appropriately if that context is canceled.The main
providercache.Installer.EnsureProviderVersions
method now also has some context-awareness so that it can abort its work early if its context reports any sort of error. That avoids waiting for the process to wind through all of the remaining iterations of the various loops, logging each request failure separately, and instead returns just a single aggregate "canceled" error.We can then set things up in the
terraform init
andterraform providers mirror
commands so that the context will becancelled if we get an interrupt signal, allowing provider installation to abort early while still atomically completing any local side-effects that may have started.
This fixes #18474, and partially addresses #23647 (because the other operations in
terraform init
are still not interruptible yet.)This PR also bundles in the removal of the
terraform 0.13upgrade
command, which was due to happen before Terraform 0.14 anyway, primarily because it includes calls into thegetproviders
package that I would otherwise have need to update to pass in a context. Reviewing the two commits separately might be easier.