azure-devops - Azure Devops - Terraform 任务失败并出现错误

我打算在我的天蓝色 Devops 管道上运行 Terraform。我正在使用 MicrosoftDevLabs 从市场上获得的 terraform 扩展版本 0.1.8 我的任务如下所示:

task: TerraformTaskV1@0
displayName: 'Terraform - Init'
inputs:
provider: 'azurerm'
command: 'init'
commandOptions: '-input=false'
backendServiceArm: 'service-connection'
backendAzureRmResourceGroupName: 'Project-RG'
backendAzureRmStorageAccountName: 'projectsa'
backendAzureRmContainerName: 'tfstate'
backendAzureRmKey: 'terraform.tfstate'
workingDirectory: terraform

它尝试执行的命令是

`/opt/hostedtoolcache/terraform/0.13.5/x64/terraform init -backend-config=storage_account_name=projectsa -backend-config=container_name=tfstate -backend-config=key=terraform.tfstate -backend-config=resource_group_name=Project-RG -backend-config=arm_subscription_id=xxxx-xxxx-xxxx -backend-config=arm_tenant_id=*** -backend-config=arm_client_id=*** -backend-config=arm_client_secret=***’

错误信息是:

Initializing the backend...  
Error: Invalid backend configuration argument
The backend configuration argument "storage_account_name" given on the command line is not expected for the selected backend type.   
Error: Invalid backend configuration argument  
The backend configuration argument "container_name" given on the command line is not expected for the selected backend type.   
Error: Invalid backend configuration argument  
The backend configuration argument "key" given on the command line is not expected for the selected backend type.

最佳答案

我遇到了类似的错误,发现在我的管道 yml 中使用任务 TerraformTaskV2@2 而不是旧的 TerraformTaskV1@0 解决了这个问题。这个较新的任务也适用于非常新的 Terraform 版本,例如 1.1.4。

  # Install Terraform on Agent
  - task: TerraformInstaller@0
    displayName: 'install'
    inputs:
      terraformVersion: '1.1.4'

  # Initialize Terraform
  - task: TerraformTaskV2@2
    displayName: 'init'
    inputs:
      provider: 'azurerm'
      command: 'init'
      backendAzureRmResourceGroupName: 'prodbackendstf'
      backendAzureRmStorageAccountName: 'productiontfstate'
      backendAzureRmContainerName: 'tfstate'
      backendAzureRmKey: 'tf.state'
      backendServiceArm: 'IaC SPn'
      workingDirectory: '$(System.DefaultWorkingDirectory)/terraform'

关于azure-devops - Azure Devops - Terraform 任务失败并出现错误 : Invalid backend configuration argument,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65136431/

相关文章:

java - Config Client 在 Spring boot 中不工作

python - For循环遍历Python中的列表

scala - scala中以下两种模式匹配案例有什么区别

asp.net-core - 415 ASP.NET Core Web API 中不支持的媒体类型

node.js - docker-compose npm install && npm start

wordpress - Disqus iframe 透明度不适用于 Chrome 87

kubernetes - 如何使用 HELM 强制重新部署

python - 删除txt中的特定字符

r - 使用向量和定义的标量在 R 中生成金字塔

c - 打印函数,C语言的hello world