如何在 azure devops 管道中应用 terraform.tfvars

How to apply terraform.tfvars in azure devops pipeline

尝试使用 azure devops 管道通过 terraform 构建 AKS,我希望我可以从 prod_terraform.tfvars 文件传递​​变量值 我想 运行“terraform plan -var-file = prod_terraform.tfvars”

这里是yaml代码

      - task: TerraformCLI@0
        displayName: Terraform Plan
        inputs:
          command: 'plan'
          workingDirectory: '$(System.DefaultWorkingDirectory)/terraform-manifests'
          commandOptions: '-out aks_cluster.tfplan'
          allowTelemetryCollection: false

错误如下


/opt/hostedtoolcache/terraform/1.0.8/x64/terraform plan -out aks_cluster.tfplan
Acquiring state lock. This may take a few moments...
var.acr_demo
  Enter a value: 
##[error]The operation was canceled.
Finishing: Terraform Plan

Terraform 将自动从变量定义文件中加载变量值,如果它被命名为 terraform.tfvars 或以 .auto.tvfars 结尾并与其他配置文件放在同一目录中,如下所示:

development
└── server
    └── main.tf
    └── variables.tf
    └── terraform.tfvars

我重命名了文件并且它起作用了