hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io
Other
42.76k stars 9.56k forks source link

Make terraform init cancellable #23647

Open radeksimko opened 4 years ago

radeksimko commented 4 years ago

Terraform Version

v0.12.18

Terraform Configuration Files

provider "aws" {
  region = "eu-west-1"
}

Expected Behavior

Discovery of providers should be cancelled when SIGINT is received.

Actual Behavior

Discovery continues.

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "aws" (hashicorp/aws) 2.41.0...
^C^C^C^C^C^C^C^C^C^C^C^C^C^C^C
The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.aws: version = "~> 2.41"

Terraform has been successfully initialized!

Steps to Reproduce

terraform init

References

https://github.com/hashicorp/terraform-plugin-sdk/issues/141

apparentlymart commented 4 years ago

I've merged #26405 which makes the provider installation part of terraform init respond to SIGINT. The phrasing of this issue seems more general than just the provider installation part, and so I've not closed it because the backend initialization and module installation parts are still not cancelable.

stigok commented 3 years ago

It would make sense to make the plan phase of plan and apply also be cancellable, I think.

radeksimko commented 3 years ago

@stigok It may be better to discuss and track that in a separate thread, because there is already many operations which run as part of init and there is likely even more in plan and especially apply and cancellation ability of every operation may differ, so this would need to be considered.

Relatedly it's possible that making apply/plan/destroy reliably cancellable would involve some SDK and provider work and unlike init likely can't be just implemented in core alone.

radeksimko commented 3 years ago

@apparentlymart I think downloading would usually take the most time, so that helps a lot, but it would still be useful to make the initial discovery cancellable too - for example to tackle DNS or proxy issues when the first request just hangs and eventually times out.