目的:尝试在terraform中的Null提供程序资源定义中运行多个AZcli命令。尝试列出所有私有端点,然后循环查找状态为"pending"
的所有私有端点,然后批准这些端点。
我的当前编码:
resource "null_resource" "endpoint_approval" {
depends_on = [azurerm_synapse_managed_private_endpoint.mpe_adls_blob]
provisioner "local-exec" {
command = <<EOT
pending_endpoints=$(az network private-endpoint-connection list --id "${var.syn_adls_id}" --query "[?properties.privateLinkServiceConnectionState.status=='Pending'].id" -o tsv)
for each_endpoint in $pending_endpoints
do
az network private-endpoint-connection approve --id "$each_endpoint" --description "Approved in Terraform"
done
EOT
interpreter = ["/bin/bash", "-c"]
}
}
我得到的错误:
': exit status 2. Output: /bin/sh: syntax error: unexpected end of file (expecting "done")
我已经逐行验证了缩进,似乎没有问题,并且在执行之前还使用了terraform fmt
命令对其进行格式化,但我不知道为什么会出现此错误。有人能给我指路吗?先谢谢你了
1条答案
按热度按时间cpjpxq1n1#
我尝试使用下面的代码来解决语法问题,并得到了没有任何错误的输出:
我的main.tf编码:-
我引用了这个official Terraform document中的代码,并用空资源块和我的变量修改了它。
输出:-
https://i.imgur.com/xZFxvDv.png
https://i.imgur.com/dR7FFOq.png