【问题标题】:Why does terraform init happen every time I run plan or apply?为什么每次运行计划或申请时都会发生 terraform init?
【发布时间】:2022-08-04 00:31:26
【问题描述】:

每次我运行 terraform 命令时,它都会首先自动运行init。我在 Azure 存储帐户中使用远程状态。这似乎是在几个月没有接触该项目后随机开始的。

否则一切正常,但它很烦人并且减慢了我们的速度。

有什么方法可以调试为什么会发生这种情况以便我可以修复它?

myhost$ terraform plan

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/azuread from the dependency lock file
- Reusing previous version of hashicorp/random from the dependency lock file
- Reusing previous version of azure/azapi from the dependency lock file
- Reusing previous version of hashicorp/azurerm from the dependency lock file
- Using previously-installed hashicorp/azuread v2.26.1
- Using previously-installed hashicorp/random v3.1.3
- Using previously-installed azure/azapi v0.4.0
- Using previously-installed hashicorp/azurerm v3.14.0

Terraform has been successfully initialized!

版本信息:

Terraform v1.2.4
on windows_amd64
+ provider registry.terraform.io/azure/azapi v0.4.0
+ provider registry.terraform.io/hashicorp/azuread v2.26.1
+ provider registry.terraform.io/hashicorp/azurerm v3.14.0
+ provider registry.terraform.io/hashicorp/random v3.1.3
  • 这不是默认行为,甚至不是内在行为,因此这里必须发生某种包装器、别名、环境覆盖等。
  • @MattSchuchard 谢谢你,这很有帮助,我现在看到 terraform 别名为 terragrunt 所以我猜这是罪魁祸首
  • 刚刚在一个新租户上使用了同样的 TF 项目,它表现出同样的问题。已升级 terragrunt 和提供程序无济于事。

标签: terraform terraform-provider-azure


【解决方案1】:

这是由 Terragrunt 的 Auto-Init feature 引起的,由于某些未确定的原因,这似乎在我的项目中行为不端。

您可以使用--terragrunt-no-auto-init 选项或将TERRAGRUNT_AUTO_INIT 环境变量设置为false 来禁用该功能。当你这样做时,它会给出一个警告,但无论如何都会继续。不理想,但至少它加快了我的工作流程。

$ terragrunt plan --terragrunt-no-auto-init
WARN[0002] Detected that init is needed, but Auto-Init is disabled. Continuing with further actions, but subsequent terraform commands may fail.  prefix=[/home/kstumpf/ken/Code/gh-ih-tf-portal/environments/dev]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2021-02-11
    • 2019-09-30
    • 1970-01-01
    • 2021-06-23
    相关资源
    最近更新 更多