我们正在尝试让一些服务主体应用程序和 terraform 中的对象 ID 传递。 在 powershell 中执行
az ad sp list --display-name ima_sp_user -o json
我们得到 json 输出:
{
"accountEnabled": true,
"addIns": [],
"alternativeNames": [],
"appDescription": null,
"appDisplayName": "ima_sp_user",
"appId": "123_fake_appid", <----- appid
"appMetadata": null,
"id": "123_fake_object_id", <----- object_id
"info": { //blah blah blah more stuff
很棒,但是当添加到 terraform 时:
data "external" "sp1_user_information" {
program = ["az", "ad", "sp", "list", "--display-name", "ima_sp_user", "-o", "json" ]
query = {
id = "oid"
appid = "appId"
}
}
我们遇到 Terraform 应用错误:
Error: Unexpected External Program Results
The data source received unexpected results after executing the program.
Program output must be a JSON encoded map of string keys and string values.
有人有什么想法吗?
更新: 最终调用 PowerShell 脚本来替换括号
param( [string] $ServicePrincipal )
return $( ( az ad sp list --display-name $ServicePrincipal --query "[].{appId:appId,oid:id}" -o json ) -replace '[[\]]','' ).Trim( )
TF文件:
data "external" "adosp_account_info" {
program = ["powershell.exe", "-noprofile", "-file","..\\tf-helpers\\get-sp-information.ps1", "-ServicePrincipal", "ima_sp_user"]
query = {
id = "oid"
appid = "appId"
}
}
无论如何感谢!有用的评论和反对票