使用 terraform(无效的 UUID)创建 Azure AD 应用程序
Create Azure AD Application using terraform(Invalid UUID)
我正在使用 terraform 创建 Azure AD 应用程序,我已经尝试了 terraform 示例中的默认示例 https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application 我还根据我手动创建的代码自定义了下面的代码(基本上,我已经创建在 AD 中手动创建一个应用程序,并使用 terraform 为创建的应用程序从数据资源中获取详细信息)。两个代码都抛出相同的错误
Error: Value must be a valid UUID │ │ with
azuread_application.example, │ on adapp.tf line 3, in resource
"azuread_application" "example": │ 3: resource
"azuread_application" "example" {
这是我根据原始示例自定义的代码
data "azuread_client_config" "current" {}
resource "azuread_application" "example" {
display_name = "example"
identifier_uris = ["api://example-app"]
owners = [data.azuread_client_config.current.object_id]
sign_in_audience = "AzureADMultipleOrgs"
required_resource_access {
resource_app_id = "00000003-0000-0000-c000-000000000000"
resource_access {
id = "..."
type = "Scope"
}
}
web {
redirect_uris = ["https://app.example.net/account"]
implicit_grant {
access_token_issuance_enabled = false
}
}
}
我已经验证了“data.azuread_client_config.current.object_id”,它不为空并且它产生了值。
地形配置:
Terraform v0.15.4 on windows_amd64
- provider registry.terraform.io/hashicorp/azuread v1.6.0
由于您正在使用 "Microsoft Graph"
(00000003-0000-0000-c000-000000000000) 的资源应用程序 ID,因此您必须提供应用程序在 Microsoft Graph 中所需的委托权限,例如User.read等
一些 CLI 命令将帮助您获取 Microsoft Graph 资源应用程序 ID 和委派权限 ID:
- az ad sp list --display-name "Microsoft Graph" --query
'[].{appDisplayName:appDisplayName, appId:appId}'
--output table
- az ad sp show --id 00000003-0000-0000-c000-000000000000 --query
"oauth2Permissions[].{Value:value, Id:id}" --output table
因此,由于您已经在使用默认的 Microsoft Graph 应用程序 ID,我们需要获取委托权限 ID 以在资源访问 ID 中提供。
那么您的地形代码将如下所示:
data "azuread_client_config" "current" {}
resource "azuread_application" "example" {
display_name = "example"
identifier_uris = ["api://example-app"]
owners = [data.azuread_client_config.current.object_id]
sign_in_audience = "AzureADMultipleOrgs"
required_resource_access {
resource_app_id = "00000003-0000-0000-c000-000000000000"# resourceid of microsoft graph
resource_access {
id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" # User.Read
type = "Scope"
}
}
web {
redirect_uris = ["https://app.example.net/account"]
implicit_grant {
access_token_issuance_enabled = false
}
}
}
正在做一个地形规划:
注意: 默认 Microsoft Graph 应用程序 ID 为 "00000003-0000-0000-c000-000000000000"
,默认 Windows Active Directory 应用程序 ID (Azure AD Graph) 为 "00000002-0000-0000-c000-000000000000"
.根据您的要求,您可以使用 Microsoft Graph 或 Azure AD Graph。
我正在使用 terraform 创建 Azure AD 应用程序,我已经尝试了 terraform 示例中的默认示例 https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application 我还根据我手动创建的代码自定义了下面的代码(基本上,我已经创建在 AD 中手动创建一个应用程序,并使用 terraform 为创建的应用程序从数据资源中获取详细信息)。两个代码都抛出相同的错误
Error: Value must be a valid UUID │ │ with azuread_application.example, │ on adapp.tf line 3, in resource "azuread_application" "example": │ 3: resource "azuread_application" "example" {
这是我根据原始示例自定义的代码
data "azuread_client_config" "current" {}
resource "azuread_application" "example" {
display_name = "example"
identifier_uris = ["api://example-app"]
owners = [data.azuread_client_config.current.object_id]
sign_in_audience = "AzureADMultipleOrgs"
required_resource_access {
resource_app_id = "00000003-0000-0000-c000-000000000000"
resource_access {
id = "..."
type = "Scope"
}
}
web {
redirect_uris = ["https://app.example.net/account"]
implicit_grant {
access_token_issuance_enabled = false
}
}
}
我已经验证了“data.azuread_client_config.current.object_id”,它不为空并且它产生了值。
地形配置:
Terraform v0.15.4 on windows_amd64
- provider registry.terraform.io/hashicorp/azuread v1.6.0
由于您正在使用 "Microsoft Graph"
(00000003-0000-0000-c000-000000000000) 的资源应用程序 ID,因此您必须提供应用程序在 Microsoft Graph 中所需的委托权限,例如User.read等
一些 CLI 命令将帮助您获取 Microsoft Graph 资源应用程序 ID 和委派权限 ID:
- az ad sp list --display-name "Microsoft Graph" --query
'[].{appDisplayName:appDisplayName, appId:appId}'
--output table
- az ad sp show --id 00000003-0000-0000-c000-000000000000 --query
"oauth2Permissions[].{Value:value, Id:id}" --output table
因此,由于您已经在使用默认的 Microsoft Graph 应用程序 ID,我们需要获取委托权限 ID 以在资源访问 ID 中提供。
那么您的地形代码将如下所示:
data "azuread_client_config" "current" {}
resource "azuread_application" "example" {
display_name = "example"
identifier_uris = ["api://example-app"]
owners = [data.azuread_client_config.current.object_id]
sign_in_audience = "AzureADMultipleOrgs"
required_resource_access {
resource_app_id = "00000003-0000-0000-c000-000000000000"# resourceid of microsoft graph
resource_access {
id = "e1fe6dd8-ba31-4d61-89e7-88639da4683d" # User.Read
type = "Scope"
}
}
web {
redirect_uris = ["https://app.example.net/account"]
implicit_grant {
access_token_issuance_enabled = false
}
}
}
正在做一个地形规划:
注意: 默认 Microsoft Graph 应用程序 ID 为 "00000003-0000-0000-c000-000000000000"
,默认 Windows Active Directory 应用程序 ID (Azure AD Graph) 为 "00000002-0000-0000-c000-000000000000"
.根据您的要求,您可以使用 Microsoft Graph 或 Azure AD Graph。