Terraform 的 Azure DevOps Pipelines 在 arm_xxx 参数上失败

Azure DevOps Pipelines with Terraform failing on arm_xxx parameters

我们在 Azure-Devops 中有几个管道执行 Terraform init-plan-apply。到现在为止工作正常。 但是突然之间,我们在 Init 阶段遇到了这些错误。

Initializing the backend...
╷
│ Error: Invalid backend configuration argument
│ 
│ The backend configuration argument "arm_subscription_id" given on the command line is not expected for the selected backend type.
╵ Error: Invalid backend configuration argument
│ 
│ The backend configuration argument "arm_tenant_id" .....
│ The backend configuration argument "arm_client_id" .....
│ The backend configuration argument "arm_client_secret" ....

在 hasicorp 网站上,我发现了关于此 https://www.terraform.io/upgrade-guides/0-15.html 的评论。 但是 init 命令的生成完全由 DevOps 完成,没有地方可以将 arm_client_id 更改为 client_id(和其他)。

任何人都见过这种行为并能够解决它。

我今天在这个问题上花了大约2个小时,发现我必须执行以下操作。

  1. 我不得不安装 Terraform 0.14.11,因为新的 0.15.1 失败了

  2. 在您的 Terraform init 任务中,将 -reconfigure 添加到 Additional command arguments

  3. 尽管我的 terraform 代码在我的 PC 上运行良好,但我遇到了与您相同的错误。在我的 main.tf 文件中,我删除了对后端的所有引用,因为它们已经在初始化任务中定义

    terraform {
      required_providers {
        azurerm = {
          source  = "hashicorp/azurerm"
          version = "=2.48.0"
        }
      }
    }
    
    provider "azurerm" {
      features {}
    }
    
    terraform {
      backend "azurerm" {
      }
    }