对于 terraform azuread v 3.0.1 azuread_application_app_role 资源,role_id 是必需的,而不是自动生成的。 因此,计划或模块必须生成这个 id(这看起来确实非常错误)-资源和版本的文档。
因此,我需要生成一个我喜欢的随机 uuid
azuread_application_app_role
role_idesource "random_uuid" "admin_role" {}
resource "random_uuid" "user_role" {}
resource "azuread_application" "app" {
display_name = var.app_name
identifier_uris = [local.app_identifier_uri]
}
...
resource "azuread_application_app_role" "admin_role" {
role_id = random_uuid.admin_role.result
application_id = azuread_application.app.id
allowed_member_types = ["User"]
description = "Admins can manage ${var.app_name}"
display_name = "Admin-${var.app_name}"
value = "Admin-${var.app_name}"
}
resource "azuread_application_app_role" "user_role" {
role_id = random_uuid.user_role.result
application_id = azuread_application.app.id
allowed_member_types = ["User"]
description = "User of ${var.app_name} application"
display_name = "User-${var.app_name}"
value = "User-${var.app_name}"
}
我有背面的远程状态设置。 在每次初始化、计划、应用时,我都会得到一组新的 uuid,导致每个计划看起来都发生了漂移。 我想制作一次 UUID 并将其存储起来以便可以使用。
我该怎么做? 我尝试过使用空资源
这不起作用。 我继续看到同样的问题
resource "random_uuid" "example_administrator" {}
resource "null_resource" "initialize_uuid" {
triggers = {
uuid = random_uuid.example_administrator.id
}
}
resource "azuread_application_app_role" "example" {
role_id = null_resource.initialize_uuid.triggers["uuid"]
...
}
我还没有测试这个选项
provider "time" {}
resource "time_static" "admin_role" {
triggers = {
# Any attribute here will generate the UUID only once
role = "admin"
}
}
resource "time_static" "user_role" {
triggers = {
# Any attribute here will generate the UUID only once
role = "user"
}
}
将 keeper 设置为常量字符串可确保 uuid 生成一次且仅一次。
resource "random_uuid" "admin_role" {
keepers = {
# ensure that uuid is made one time only
const = "persistent-uuid"
}
}
resource "random_uuid" "user_role" {
keepers = {
# ensure that uuid is made one time only
const = "persistent-uuid"
}
}
resource "azuread_application" "app" {
display_name = var.app_name
identifier_uris = [local.app_identifier_uri]
}
...
resource "azuread_application_app_role" "admin_role" {
role_id = random_uuid.admin_role.id
application_id = azuread_application.app.id
allowed_member_types = ["User"]
description = "Admins can manage ${var.app_name}"
display_name = "Admin-${var.app_name}"
value = "Admin-${var.app_name}"
}
resource "azuread_application_app_role" "user_role" {
role_id = random_uuid.user_role.id
application_id = azuread_application.app.id
allowed_member_types = ["User"]
description = "User of ${var.app_name} application"
display_name = "User-${var.app_name}"
value = "User-${var.app_name}"
}