简体   繁体   English

如何将Terraform与Azure CLI和REST API相结合?

[英]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-execremote-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-execremote-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.

相关问题 如何使用 api/azure-cli/powershell/terraform 创建 Azure Marketplace SaaS 应用程序? - How can I create an Azure Marketplace SaaS App using api/azure-cli/powershell/terraform? 如何在 Azure API Manager 中通过 Terraform 添加新的 API 版本? - How do I add a new API version via Terraform in Azure API Manager? 如何使用Azure APIM公开我的REST API? - How Do I Expose My REST API With Azure APIM? Azure CLI是否使用Azure Rest API - Does the Azure CLI use the Azure Rest API How do you update the Knownclientapplications in Azure AD app registration either using powershell,Azure CLI or Terraform - How do you update the Knownclientapplications in Azure AD app registration either using powershell,Azure CLI or Terraform 如何在带有terraform的AZure AKS中启用静态加密 - How to enable encryption at rest in AZure AKS with terraform 如何将 Azure AD 服务主体密码导入 Terraform? - How do I import an Azure AD Service Principal Password into Terraform? Terraform - 我如何 map 不同的 azure 环境变量文件? - Terraform - How do I map different azure environment variable files? 如何使 Azure 备份与 Terraform 一起工作? - How do I make the Azure backup work with Terraform? 使用Terraform时如何查询2个不同的Azure目录? - How Do I Query 2 Different Azure Directories When Using Terraform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM