0

因此,我在 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'.

任何人都可以阐明这里可能发生的事情吗?

4

2 回答 2

0

现在突然开始工作了,所以我怀疑这是 Azure API 的一个事件。

于 2021-12-21T15:45:52.590 回答
0

我测试了你的代码并且它工作正常。但如果问题仍然存在,请将 azurerm 提供程序升级到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           = []
}

输出:

在此处输入图像描述

于 2021-12-21T16:25:56.053 回答