【问题标题】:Terraform pipeline times out and stops when deploying Azure Management Group, but management group does get deployedTerraform 管道在部署 Azure 管理组时超时并停止,但管理组确实已部署
【发布时间】:2022-01-22 23:56:10
【问题描述】:

所以我在 Azure DevOps 中使用 .yaml 管道,它利用服务主体来创建我的开发环境的管理部分。以前,它工作得很好。我更改了代码,以便管理组使用 UUID,这样我的租户中就不会出现任何重复的名称。但是,现在它无法正确部署管理组。相反,它在应用阶段超时并且管道失败。但是,当我检查 Azure 门户时,我可以看到管理组已部署,其名称与我在据称超时的创建尝试期间看到的完全相同的 UUID。

然后我将我的代码恢复到之前的迭代,现在我在之前工作的旧代码上遇到了同样的错误!我检查了管理组的数量是否有限制,但我们的租户肯定没有达到 10,000 个管理组的限制。我想知道权限是否发生了变化(我看不到任何权限),或者这是否是 Terraform 中的错误(或者可能是 Azure API)。我试图创建一个 UUID 并将其分配为管理组的名称,而不是让管理组自己创建一个 UUID,而不是简单地为资源提供名称/id。

这是代码的问题部分:

terraform {
  required_version = ">= 0.13, <= 1.10.0"
  backend "azurerm" {}
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=2.57.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "random_uuid" "UUID_org" {

}

output "UUID_org" {
  value       = random_uuid.UUID_org.result
  description = "The UUID serving as the management_group_name of the org management group"
}

resource "azurerm_management_group" "management_group_org" {
  
  display_name               = format("%s-%s", local.prefix_management_group, local.company_name)
  name                       = random_uuid.UUID_org.result
  parent_management_group_id = "/providers/Microsoft.Management/managementGroups/${local.root_management_group}"
  subscription_ids           = null
}

resource "random_uuid" "UUID_platform" {

}

output "UUID_platform" {
  value       = random_uuid.UUID_platform.result
  description = "The UUID serving as the management_group_name of the platform management group"
}

resource "azurerm_management_group" "management_group_platform" {
  
  display_name               = "platform"
  name                       = random_uuid.UUID_platform.result
  parent_management_group_id = azurerm_management_group.management_group_org.id #random_uuid.UUID_org.result
  subscription_ids           = []
}

为保密起见,省略了当地人。

这是管道在失败时退出的错误消息:

module.management_groups_org.azurerm_management_group.management_group_assignments["default-name-org"]: Still creating... [3m40s elapsed]
╷
│ Error: failed when waiting for creation of Management Group "default-name-org": Future#WaitForCompletion: the number of retries has been exceeded: StatusCode=404 -- Original Error: Code="InProgress" Message="The async operation failed." AdditionalInfo=[{"id":"/providers/Microsoft.Management/managementGroups/default-name-org","name":"default-name-org","status":"NotStarted","type":"/providers/Microsoft.Management/managementGroups"}]
│ 
│   with module.management_groups_org.azurerm_management_group.management_group_assignments["default-name-org"],
│   on ../../../../modules/azurerm-managementgroups/main.tf line 10, in resource "azurerm_management_group" "management_group_assignments":
│   10: resource "azurerm_management_group" "management_group_assignments" {
│ 
╵
##[debug]Exit code 1 received from tool '/azp/_work/_tool/terraform/0.15.1/x64/terraform'
##[debug]STDIO streams have closed for tool '/azp/_work/_tool/terraform/0.15.1/x64/terraform'
##[debug]allowTelemetryCollection=true
##[error]Terraform command 'apply' failed with exit code '1'.

谁能解释一下这里可能发生的事情?

【问题讨论】:

    标签: azure azure-devops terraform pipeline azure-management-groups


    【解决方案1】:

    现在突然开始工作了,所以我怀疑这是 Azure API 的问题。

    【讨论】:

      【解决方案2】:

      我测试了你的代码并且它工作正常。但如果问题仍然存在,请将 azurerm 提供程序 升级到 latest version i.e. v2.90.0 以便它使用 最新的 Azure API

      terraform {
        required_version = ">= 0.13, <= 1.10.0"
        required_providers {
          azurerm = {
            source  = "hashicorp/azurerm"
            version = "=2.90.0"
          }
        }
      }
      
      provider "azurerm" {
        features {}
      }
      
      resource "random_uuid" "UUID_org" {}
      
      output "UUID_org" {
        value       = random_uuid.UUID_org.result
        description = "The UUID serving as the management_group_name of the org management group"
      }
      
      resource "azurerm_management_group" "management_group_org" {
        
        display_name               = format("%s-%s", local.prefix_management_group, local.company_name)
        name                       = random_uuid.UUID_org.result
        parent_management_group_id = "/providers/Microsoft.Management/managementGroups/${local.root_management_group}"
        subscription_ids           = null
      }
      
      resource "random_uuid" "UUID_platform" {}
      
      output "UUID_platform" {
        value       = random_uuid.UUID_platform.result
        description = "The UUID serving as the management_group_name of the platform management group"
      }
      
      resource "azurerm_management_group" "management_group_platform" {
        
        display_name               = "platform"
        name                       = random_uuid.UUID_platform.result
        parent_management_group_id = azurerm_management_group.management_group_org.id #random_uuid.UUID_org.result
        subscription_ids           = []
      }
      

      输出:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-01-29
        • 1970-01-01
        • 1970-01-01
        • 2023-03-20
        • 1970-01-01
        • 2021-11-14
        • 1970-01-01
        相关资源
        最近更新 更多