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

check if azure-resourcegroup is already exists via terraform script

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

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

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

terraform plan - used to validate your tf script

terraform apply - to apply the tf script changes

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

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your configuration and real physical resources that exist. As a result, no actions need to be performed.

如果你直接使用 terraform apply,你会看到下面的消息

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

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

希望这对您有所帮助。