[英]How Do I Combine Terraform With Azure CLI and REST API?
I have a most of my Azure infrastructure managed with Terraform. 我的大部分Azure基础结构都由Terraform管理。 However, I am quickly finding that a lot of the small details are missing.
但是,我很快发现许多小细节丢失了。
eg client secrets aren't fully supported https://github.com/terraform-providers/terraform-provider-azuread/issues/95 例如,客户机密未得到完全支持https://github.com/terraform-providers/terraform-provider-azuread/issues/95
It doesn't seem possible to add an Active Directory Provider to APIM How Do I Add Active Directory To APIM Using Terraform? 似乎无法向APIM添加Active Directory提供商如何使用Terraform向APIM添加Active Directory?
Creating the APIM leaves demo products on it that can't be removed How Can I Remove Demo Products From APIM Created With Terraform? 创建APIM会留下无法删除的演示产品如何如何从使用Terraform创建的APIM中删除演示产品?
etc, etc. 等等等
Solutions to these seems to be utilising the cli 解决这些问题的方法似乎是利用cli
eg https://docs.microsoft.com/en-us/cli/azure/ad/app/permission?view=azure-cli-latest#az-ad-app-permission-add 例如https://docs.microsoft.com/en-us/cli/azure/ad/app/permission?view=azure-cli-latest#az-ad-app-permission-add
Or falling back to the REST API: eg https://docs.microsoft.com/en-us/rest/api/apimanagement/2019-01-01/apis/delete 或回退到REST API:例如https://docs.microsoft.com/zh-cn/rest/api/apimanagement/2019-01-01/apis/delete
How can I mix terraform with the CLI and REST API? 如何将Terraform与CLI和REST API混合使用?
Can they be embedded in terraform? 它们可以嵌入在地形中吗?
Or do I just run some commands to run them after terraform has finished? 还是在terraform完成后才运行一些命令来运行它们?
Is there a way to do these commands in a cross platform way? 有没有办法以跨平台的方式执行这些命令?
Will running the CLI and REST API after terraform cause the state to be wrong and likely cause problems the next time terraform is run? 在terraform之后运行CLI和REST API是否会导致状态错误并可能在下次运行terraform时引起问题?
How can I mix terraform with the CLI and REST API?
如何将Terraform与CLI和REST API混合使用?
You can use the Terraform provisioner local-exec
or remote-exec
. 您可以使用Terraform设置程序
local-exec
或remote-exec
。 In these ways, you can run the script with CLI commands or the REST API. 通过这些方式,您可以使用CLI命令或REST API运行脚本。 For more details, see
local-exec
and remote-exec
. 有关更多详细信息,请参见
local-exec
和remote-exec
。 But you need to take care of them. 但是您需要照顾好他们。 These two ways just run the scripts and display the output, but they do not have the outputs.
这两种方式仅运行脚本并显示输出,但没有输出。
If you want to use the result of the script in the same Terraform file for other resources, you need to use the Terraform external data source, see the details here . 如果要在同一Terraform文件中的脚本结果用于其他资源,则需要使用Terraform外部数据源,请参见此处的详细信息。
Update: 更新:
Here is an example. 这是一个例子。
Bash script file vmTags.sh
: Bash脚本文件
vmTags.sh
:
#!/bin/bash
az vm show -d -g myGroup -n myVM --query tags
Terraform external data source: Terraform外部数据源:
data "external" "test" {
program = ["/bin/bash", "./vmTags.sh"]
}
output "value" {
value = "${data.external.test.result}"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.