【问题标题】:check if azure-resourcegroup is already exists via terraform script通过 terraform 脚本检查 azure-resourcegroup 是否已经存在
【发布时间】:2020-07-02 10:44:50
【问题描述】:

如何通过 azure 中的 Terra-form 脚本检查 azure 资源组是否已经存在,如果不存在则创建 Terra-form 应该创建它?

通过 terraform 脚本检查 azure-resourcegroup 是否已经存在

【问题讨论】:

  • Terraform 是声明式的,而不是命令式的。使用 Terraform 时,您不需要检查现有资源,因为您正在创建一组具有相同生命周期的资源。您通常不会将资源添加到“可能”现有的资源组中。

标签: azure visual-studio-code azure-devops terraform terraform-provider-azure


【解决方案1】:

这是默认行为。您可能已经知道,您有

terraform plan - used to validate your tf script

terraform apply - to apply the tf script changes

如果您在申请之前使用了 terraform plan,并且您正在尝试创建一个已经存在的资源组,您将收到以下消息

没有变化。基础设施是最新的。

这意味着 Terraform 没有检测到您的 配置和实际存在的物理资源。结果,没有 需要执行的操作。

如果您直接使用 terraform apply,您将看到以下消息

申请完成!资源:添加 0 个,更改 0 个,销毁 0 个。

但是,您的资源不会有任何变化。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 2016-03-11
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多