Terraform - 长时间运行Azure部署错误

时间:2018-03-06 02:23:13

标签: azure azure-web-sites terraform terraform-provider-azure terraform-template-file

我们正在使用从Bash窗口通过shell脚本执行的Terraform来部署App Service Environment。部署App Service Environment需要1到2个小时才能完成。

Terraform部署在1小时后超时,并显示错误:

azurerm_template_deployment.ase: Error creating deployment: azure#WaitForCompletion: context has been cancelled: StatusCode=200 -- Original Error: context deadline exceeded

部署实际上并没有停止并最终成功。如果在完成后(如Azure门户中所示)我们重新运行Terraform部署,则部署成功完成。

Terraform日志文件:

https://gist.github.com/Phydeauxman/0f9aa3d1c1379c36e2f8f420d0ae345e

Terraform配置文件:

provider "azurerm" {
  subscription_id = "${var.sub_id}"
}

data "terraform_remote_state" "rg" {
  backend = "azurerm"

  config {
    storage_account_name = "${var.tfstate_storage_account}"
    container_name       = "${var.tfstate_container}"
    key                  = "${var.tfstate_rgstate_file}"
    access_key           = "${var.tfstate_access_key}"
  }
}

resource "azurerm_resource_group" "ase_rg" {
  name     = "${var.ilbase_rg_name}"
  location = "${data.terraform_remote_state.rg.rglocation}"
}

resource "azurerm_template_deployment" "ase" {
  name                = "ILBASE_ARM_template"
  resource_group_name = "${azurerm_resource_group.ase_rg.name}"

  template_body = <<DEPLOY

  {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "ilbase_name": {
        "type": "string"
      },
      "ilbase_domain_name": {
        "type": "string"
      },
      "ilbase_subnet_name": {
        "type": "string"
      },
      "ilbase_rglocation": {
        "defaultValue": "East US",
        "type": "string"
      },
      "vnet_id": {
        "type": "string"
      }
    },
    "variables": {
    },
    "resources": [
      {
        "apiVersion": "2016-09-01",
        "type": "Microsoft.Web/hostingEnvironments",
        "name": "[parameters('ilbase_name')]",
        "kind": "ASEV2",
        "location": "[parameters('ilbase_rglocation')]",
        "properties": {
          "name": "[parameters('ilbase_name')]",
          "location": "[parameters('ilbase_rglocation')]",
          "virtualNetwork": {
            "Id": "[parameters('vnet_id')]",
            "Subnet": "[parameters('ilbase_subnet_name')]"
          },
          "internalLoadBalancingMode": "Web, Publishing",
          "multiSize": "Standard_D1_V2",
          "multiRoleCount": 2,
          "workerPools": null,
          "ipsslAddressCount": 0,
          "dnsSuffix": "[parameters('ilbase_domain_name')]",
          "networkAccessControlList": [],
          "frontEndScaleFactor": 15,
          "apiManagementAccountId": null,
          "suspended": false,
          "dynamicCacheEnabled": null,
          "clusterSettings": null
        }
      }
    ],
    "outputs": {
    }
  }

  DEPLOY

  # these key-value pairs are passed into the ARM Template's `parameters` block
  parameters {
    "vnet_id"            = "${data.terraform_remote_state.rg.vnetid}"
    "ilbase_subnet_name" = "${data.terraform_remote_state.rg.sn2name}"
    "ilbase_name"        = "${var.ilbase_name}"
    "ilbase_domain_name" = "${var.ilbase_domain_name}"
  }

  deployment_mode = "Incremental"
}

#output "storageAccountName" {
#  value = "${azurerm_template_deployment.test.outputs["storageAccountName"]}"
#}

1 个答案:

答案 0 :(得分:0)

似乎没有一个具体的问题,但是从AzureRM 2.0提供者开始,现在可以添加自定义超时。其次,在地形中不存在资源类型的情况下,仅使用azurerm_template_deployment被认为是最佳实践。 App service是一流的资源