azure - Terraform 计划卡在 Terraform :Plan task in ADO pipeline

标签 azure azure-devops azure-web-app-service azure-pipelines terraform-provider-azure

enter image description here我尝试按照以下链接通过 Azure Dev Ops Pipeline 使用 Terraform 部署应用程序服务

AzureDevOpsLabs

我的 terraform 文件如下:

webapp.tf

terraform {
  required_version = "~> 1.0" 
  backend "azurerm" {
    storage_account_name = "__terraformstorageaccount__"
    container_name       = "terraform"
    key                  = "terraform.tfstate"
    }
}

provider "azurerm" {
  tenant_id       = var.tenant_id
  client_id       = var.client_id
  client_secret   = var.client_secret
  subscription_id = var.subscription_id
  features {}
}

resource "azurerm_resource_group" "dev" {
  name     = var.resource_group_name
  location = var.resource_group_location
}

resource "azurerm_app_service_plan" "dev" {
  name                = var.appserviceplan
  location            = var.resource_group_location
  resource_group_name = var.resource_group_name

  sku {
    tier = "Free"
    size = "F1"
  }
  depends_on = [
    azurerm_resource_group.dev
  ]
}

resource "azurerm_app_service" "dev" {
  name                = var.appservicename
  location            = azurerm_app_service_plan.dev.location 
  resource_group_name = azurerm_app_service_plan.dev.location
  app_service_plan_id = azurerm_app_service_plan.dev.id
}

var.tf

variable "client_id" {}

variable "client_secret" {}

variable "tenant_id" {}

variable "subscription_id" {}

variable "appserviceplan" {}

variable "appservicename" {}

variable "resource_group_name" {}

variable "resource_group_location" {}

实际值在管道变量中给出

我直接使用开源 terraform 部署了相同的应用程序服务,并且运行良好。

但是“Terraform:Plan”步骤卡在发布管道中,如屏幕截图所示。 知道为什么会发生这种情况并且计划没有正确完成

enter image description here

我已禁用 Terraform Init 并启用调试。但它在 Terraform Apply 时仍然失败,我看到以下日志。任务永远不会完成

Terraform 应用任务

Exit code 0 received from tool 'C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe'
STDIO streams have closed for tool 'C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe'
provider=azurerm
commandOptions=-auto-approve
workingDirectory=C:\hostedtoolcache\windows\terraform
environmentServiceNameAzureRM=a8ee372e-0734-4e50-aa5a-e19d9e5f2a62
which 'terraform'
found: 'C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe'
which 'C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe'
found: 'C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe'
C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe arg: apply
C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe arg: -auto-approve
a8ee372e-0734-4e50-aa5a-e19d9e5f2a62 auth param serviceprincipalid = ***
a8ee372e-0734-4e50-aa5a-e19d9e5f2a62 auth param serviceprincipalkey = ***
a8ee372e-0734-4e50-aa5a-e19d9e5f2a62 data subscriptionid = xxxx-xxxx-xxxx
a8ee372e-0734-4e50-aa5a-e19d9e5f2a62 auth param tenantid = xxxx-xxxxxx
a8ee372e-0734-4e50-aa5a-e19d9e5f2a62 auth param serviceprincipalid = ***
a8ee372e-0734-4e50-aa5a-e19d9e5f2a62 auth param serviceprincipalkey = ***
exec tool: C:\hostedtoolcache\windows\terraform\1.1.5\x64\terraform.exe
arguments:

最佳答案

从非交互式管道中运行 Terraform 时,您必须添加标志 -input=false ,否则 Terraform 将挂起等待用户输入。

请参阅此处的文档:https://www.terraform.io/cli/commands/plan#input-false

关于azure - Terraform 计划卡在 Terraform :Plan task in ADO pipeline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71680143/

相关文章:

azure - 在Azure KQL中划分多个查询的结果

azure - azure 云上的私有(private)和公共(public) IP 地址

tfs - 有没有一种方法可以像 GitHub 那样在 Azure DevOps 上托管二进制文件?

c# - 仅需要通过 INTRANET 访问 Azure Web 服务

node.js - Gulp 4 - Azure 网站

c# - 使用 Python SDK 按 RowKey 和 StartsWith 筛选 Azure 表存储

azure - `az devops login` 和 `az login` 仍然请求个人访问 token

azure - 如何嵌套yaml变量表达式?

c# - Azure DevOps API - 如何创建存储库?

azure - Azure 应用服务中的 .NET5 Blazor 服务器应用返回 "You do not have permission to view this directory or page"