应用程序服务计划从未在 Terraform 中创建

问题描述 投票:0回答:1

我对 Terraform 还很陌生,所以我可能正在做一些非常愚蠢的事情,但请耐心等待。 我有以下脚本,我运行 Terraform 计划,一切正常,但当我去应用它时,它永远不会结束,因为它永远无法完成创建应用程序服务计划,然后我得到 429 HTTP 状态代码

这是我的 main.tf:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.0"
    }
  }
}
provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "name12a6-rg1"
  location = "westeurope"
}

resource "azurerm_virtual_network" "vnet" {
  name                = "name12a6-vnet1"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "integrationsubnet" {
  name                 = "name12a6-integrationsubnet1"
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vnet.name
  address_prefixes     = ["10.0.1.0/24"]
  delegation {
    name = "delegation"
    service_delegation {
      name = "Microsoft.Web/serverFarms"
    }
  }
}

resource "azurerm_subnet" "backendendpointsubnet" {
  name                                      = "name12a6-backendendpointsubnet1"
  resource_group_name                       = azurerm_resource_group.rg.name
  virtual_network_name                      = azurerm_virtual_network.vnet.name
  address_prefixes                          = ["10.0.2.0/24"]
  private_endpoint_network_policies_enabled = true
}

resource "azurerm_subnet" "databaseendpointsubnet" {
  name                                      = "name12a6-databaseendpointsubnet1"
  resource_group_name                       = azurerm_resource_group.rg.name
  virtual_network_name                      = azurerm_virtual_network.vnet.name
  address_prefixes                          = ["10.0.3.0/24"]
  private_endpoint_network_policies_enabled = true

  delegation {
    name = "dbFlexibleServer"
    service_delegation {
      name    = "Microsoft.DBforMySQL/flexibleServers"
      actions = ["Microsoft.Network/virtualNetworks/subnets/join/action"]
    }
  }
}

resource "azurerm_service_plan" "appserviceplan1" {
  name                = "name12a6-appserviceplan1"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  os_type             = "Linux"
  sku_name            = "B1"
}

resource "azurerm_linux_web_app" "frontwebapp" {
  name                = "frontend-name12a061"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  service_plan_id     = azurerm_service_plan.appserviceplan1.id

  site_config {
    vnet_route_all_enabled = true
  }
  app_settings = {
    "WEBSITE_DNS_SERVER" : "168.63.129.16"
  }
}

resource "azurerm_app_service_virtual_network_swift_connection" "vnetintegrationconnection" {
  app_service_id = azurerm_linux_web_app.frontwebapp.id
  subnet_id      = azurerm_subnet.integrationsubnet.id
}

resource "azurerm_linux_web_app" "backwebapp" {
  name                = "backend-name12a061"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  service_plan_id     = azurerm_service_plan.appserviceplan1.id

  site_config {}
}

resource "azurerm_private_dns_zone" "dnsprivatezone" {
  name                = "privatelink.azurewebsites.net"
  resource_group_name = azurerm_resource_group.rg.name
}

# Confirm
resource "azurerm_private_dns_a_record" "dnsrecord_frontend" {
  name                = "name12a6-dns-frontend1"
  zone_name           = azurerm_private_dns_zone.dnsprivatezone.name
  resource_group_name = azurerm_resource_group.rg.name
  ttl                 = 300
  records             = [azurerm_linux_web_app.frontwebapp.name]
}

# Confirm
resource "azurerm_private_dns_a_record" "dnsrecord_backend" {
  name                = "name12a6-dns-backend1"
  zone_name           = azurerm_private_dns_zone.dnsprivatezone.name
  resource_group_name = azurerm_resource_group.rg.name
  ttl                 = 300
  records             = [azurerm_linux_web_app.backwebapp.name]
}

resource "azurerm_private_dns_zone_virtual_network_link" "dnszonelink" {
  name                  = "name12a6dnszonelink1"
  resource_group_name   = azurerm_resource_group.rg.name
  private_dns_zone_name = azurerm_private_dns_zone.dnsprivatezone.name
  virtual_network_id    = azurerm_virtual_network.vnet.id
}

resource "azurerm_private_endpoint" "privateendpoint" {
  name                = "backwebappprivateendpoint1"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  subnet_id           = azurerm_subnet.backendendpointsubnet.id

  private_dns_zone_group {
    name                 = "privatednszonegroup1"
    private_dns_zone_ids = [azurerm_private_dns_zone.dnsprivatezone.id]
  }

  private_service_connection {
    name                           = "privateendpointconnection1"
    private_connection_resource_id = azurerm_linux_web_app.backwebapp.id
    subresource_names              = ["sites"]
    is_manual_connection           = false
  }
}

# For the database
# 1 - create subnet
# 2 - create private dns zone
# 3 - assign private dns to the vnet
# 4 - create private endpoint to the new vnet

resource "azurerm_private_dns_zone" "dbdnsprivatezone" {
  name                = "dbserver.mysql.database.azure.com"
  resource_group_name = azurerm_resource_group.rg.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "db-dnszonelink" {
  name                  = "dbname12a6dnszonelink.com"
  resource_group_name   = azurerm_resource_group.rg.name
  private_dns_zone_name = azurerm_private_dns_zone.dbdnsprivatezone.name
  virtual_network_id    = azurerm_virtual_network.vnet.id

  depends_on = [azurerm_subnet.databaseendpointsubnet]
}

resource "azurerm_mysql_flexible_server" "serverMysql" {
  name                         = "dbservername12a61"
  location                     = azurerm_resource_group.rg.location
  resource_group_name          = azurerm_resource_group.rg.name
  administrator_login          = "admin1"
  administrator_password       = "adminAdmin1"
  backup_retention_days        = 7
  delegated_subnet_id          = azurerm_subnet.databaseendpointsubnet.id
  geo_redundant_backup_enabled = false
  private_dns_zone_id          = azurerm_private_dns_zone.dbdnsprivatezone.id
  sku_name                     = "GP_Standard_D2ds_v4"
  version                      = "8.0.21"

  high_availability {
    mode = "SameZone"
  }
  maintenance_window {
    day_of_week  = 0
    start_hour   = 8
    start_minute = 0
  }
  storage {
    iops    = 360
    size_gb = 20
  }

  depends_on = [azurerm_private_dns_zone_virtual_network_link.db-dnszonelink]
}

# resource "azurerm_mysql_flexible_database" "databaseMysql" {
#   name                = "databasedbserver"
#   resource_group_name = azurerm_resource_group.rg.name
#   server_name         = azurerm_mysql_flexible_server.serverMysql.name
#   charset             = "utf8mb4"
#   collation           = "utf8mb4_unicode_ci"
# }

# resource "azurerm_private_dns_a_record" "dnsrecord_database" {
#   name                = "database"
#   zone_name           = azurerm_private_dns_zone.dbdnsprivatezone.name
#   resource_group_name = azurerm_resource_group.rg.name
#   ttl                 = 300
#   records             = [azurerm_mysql_flexible_server.serverMysql.name] # has wrong name
# }

这是我得到的错误:

 Error: creating App Service Plan (Subscription: "817c1532-85ce-4a4f-bea2-6ea18491ba01"
│ Resource Group Name: "name12a6-rg1"
│ Server Farm Name: "name12a6-appserviceplan1"): performing CreateOrUpdate: unexpected status 429 (429 Too Many Requests) with response: {"Code":"429","Message":"App Service Plan Create operation is throttled for subscription 817c1532-85ce-4a4f-bea2-6ea18491ba01. Please contact support if issue persists.","Target":null,"Details":[{"Message":"App Service Plan Create operation is throttled for subscription 817c1532-85ce-4a4f-bea2-6ea18491ba01. Please contact support if issue persists."},{"Code":"429"},{"ErrorEntity":{"ExtendedCode":"51025","MessageTemplate":"App Service Plan {0} operation is throttled for subscription {1}. Please contact support if issue persists.","Parameters":["Create","817c1532-85ce-4a4f-bea2-6ea18491ba01"],"Code":"429","Message":"App Service Plan Create operation is throttled for subscription 817c1532-85ce-4a4f-bea2-6ea18491ba01. Please contact support if issue persists."}}],"Innererror":null}   
│
│   with azurerm_service_plan.appserviceplan1,
│   on main.tf line 62, in resource "azurerm_service_plan" "appserviceplan1":
│   62: resource "azurerm_service_plan" "appserviceplan1" {
│
│ creating App Service Plan (Subscription: "817c1532-85ce-4a4f-bea2-6ea18491ba01"
│ Resource Group Name: "name12a6-rg1"
│ Server Farm Name: "name12a6-appserviceplan1"): performing CreateOrUpdate: unexpected status 429 (429 Too Many Requests) with response:
│ {"Code":"429","Message":"App Service Plan Create operation is throttled for subscription 817c1532-85ce-4a4f-bea2-6ea18491ba01. Please contact support if 
│ issue persists.","Target":null,"Details":[{"Message":"App Service Plan Create operation is throttled for subscription
│ 817c1532-85ce-4a4f-bea2-6ea18491ba01. Please contact support if issue
│ persists."},{"Code":"429"},{"ErrorEntity":{"ExtendedCode":"51025","MessageTemplate":"App Service Plan {0} operation is throttled for subscription {1}.   
│ Please contact support if issue persists.","Parameters":["Create","817c1532-85ce-4a4f-bea2-6ea18491ba01"],"Code":"429","Message":"App Service Plan       
│ Create operation is throttled for subscription 817c1532-85ce-4a4f-bea2-6ea18491ba01. Please contact support if issue persists."}}],"Innererror":null}
azure terraform
1个回答
0
投票

“消息”:“订阅 xxxxx 的应用程序服务计划创建操作受到限制:

对于 terraform 部署,上述错误是暂时的。

需要检查以下内容:

  • 检查订阅 API 配额是否足以用于在相应订阅中创建应用服务计划。如果您有所有者访问权限,请增加配额限制,或联系管理员以增加限制。

  • 检查是否有任何用户创建的任何策略可能会阻止创建此类 Azure 资源。

  • 使用

    az provider list
    CLI 命令检查所有必需的资源提供程序是否已在您的环境中注册。如果没有注册,请使用
    az provider register
    进行注册。

  • 基本上,Terraform 会同时创建资源,这可以加速部署,但也会增加速率限制。

    为了避免这种情况,您可以在部署期间使用 TF_variables 中提供的并行环境变量以及

    terraform apply

  • 尝试通过将完整的代码拆分为更小的模块来简化代码,以避免冲突。

完成上述所有操作后,我尝试在我的环境中部署您的代码而不进行任何更改,并成功部署它,如下所示。

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.