phy*_*man 5 terraform terraform-template-file terraform-provider-azure
我正在 Azure 中的 bash cloud shell 中使用 Terraform。我正在尝试将外部数据源添加到我的 Terraform 配置文件中,该文件将用于az cli
查询virtualip
模板部署的 Microsoft.Web/hostingEnvironment 上的对象。
AZ CLI 命令行:
az resource show --ids /subscriptions/<subscription Id>/resourceGroups/my-ilbase-rg/providers/Microsoft.Web/hos
tingEnvironments/my-ilbase/capacities/virtualip
从命令行运行时的输出:
{
"additionalProperties": {
"internalIpAddress": "10.10.1.11",
"outboundIpAddresses": [
"52.224.70.119"
],
"serviceIpAddress": "52.224.70.119",
"vipMappings": []
},
"id": null,
"identity": null,
"kind": null,
"location": null,
"managedBy": null,
"name": null,
"plan": null,
"properties": null,
"sku": null,
"tags": null,
"type": null
}
Run Code Online (Sandbox Code Playgroud)
在我的 Terraform 配置中,我为--ids
值创建一个变量:
variable ilbase_resourceId {
default = "/subscriptions/<subscription Id>/resourceGroups/my-ilbase-rg/providers/Microsoft.Web/hostingEnvironments/my-ilbase/capacities/virtualip"
}
Run Code Online (Sandbox Code Playgroud)
然后我以这种方式构建数据源:
data "external" "aseVip" {
program = ["az", "resource", "show", "--ids", "${var.ilbase_resourceId}"]
}
Run Code Online (Sandbox Code Playgroud)
当我执行配置时,出现以下错误:
data.external.aseVip: data.external.aseVip: command "az" produced invalid JSON: json: cannot unmarshal object into Go value of type string
Run Code Online (Sandbox Code Playgroud)
有什么想法我做错了吗?
我发现问题是 Terraform 外部数据源尚无法处理命令返回的复杂结构。我可以通过在用于部署应用程序网关的脚本开头添加 AZ CLI 命令块来解决此问题,该脚本获取 IP 地址并将其作为变量传递到 Terraform 配置中。下面是我正在使用的脚本块:
ilbase_virtual_ip=$(
az resource show \
--ids "/subscriptions/$subscription_id/resourceGroups/$ilbase_rg_name/providers/Microsoft.Web/hostingEnvironments/$ilbase_name/capacities/virtualip" \
--query "additionalProperties.internalIpAddress"
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8666 次 |
最近记录: |