首页 > 解决方案 > 关于 terraform 脚本行为

问题描述

我正在使用 Terraform 脚本创建天蓝色服务,我对 Terraform 有一些疑问,

1) If I have one environment let say dev in azure having some azure resources how can I copy all the resources to new environment lest say prod using terraform script.

2)what are the impact of re-run the terraform file with additional azure resources, what it will do.

3)What if I want to create an app service with the same name from Terraform script that already present in the azure will it update the resource or do nothing after terraform execution completed. 

请随时回答问题,这将是很大的帮助。

标签: azureterraformterraform-provider-azure

解决方案


要回答您的问题:

  1. 您可以使用terraform workspace new创建一个新工作区,并将所有配置文件 ( .tf) 复制到新环境,然后运行 ​​terraform init、plan、apply。
  2. terraform 会将您当前状态文件中的内容与您的配置文件进行比较,然后更新新属性或创建新资源,而不是重新创建现有资源。
  3. 您可以运行terraform import将现有基础设施导入 Terraform。要引用门户中的现有资源,您可以使用数据源

推荐阅读