Pallab
Pallab

Reputation: 2335

Terraform Plan stuck at Terraform:Plan task in ADO pipeline

enter image description hereI am trying to follow the below link to deploy an App Service using Terraform via Azure Dev Ops Pipeline

AzureDevOpsLabs

My terraform files are given below :

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" {}

The actual values are given in the pipeline variables

I have deployed the same app service directly using open source terraform and it worked fine.

But the "Terraform:Plan" step is stuck in the Release Pipeline as shown in the screenshot. Any idea why this is happening and the plan is not finishing properly

enter image description here

I have disabled Terraform Init and enabled debugging. But it still fails at Terraform Apply and i see the below logs. The task never finishes

Terraform Apply Task

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:

Upvotes: 2

Views: 5579

Answers (1)

Glue Ops
Glue Ops

Reputation: 698

When running Terraform from within a non-interactive pipeline you must add the flag -input=false , otherwise Terraform will hang expecting user input.

See documentation here: https://www.terraform.io/cli/commands/plan#input-false

Upvotes: 6

Related Questions