azure - Terraform with Azure - 强制资源的唯一名称的问题

标签 azure terraform azure-pipelines

我正在使用 Terraform 在 Azure 中创建资源,并附加当前时间戳以在 .tf 文件中为存储帐户、 key 保管库等资源强制执行唯一名称。

问题是,对于现有资源,当您期望 Terraform apply 不执行任何操作时,这些资源将被销毁并重新创建,因为时间戳在上次执行和当前执行之间发生了更改!

想知道动态强制唯一性的最佳策略是什么。

这些资源的初始文本来自 Azure Pipeline 变量,我附加当前时间戳以增加唯一性。

最佳答案

根据云采用框架,您可以定义如下所示的约定。

enter image description here

地形示例

name = "${local.prefix}-${var.location}-app-plan"

https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming

我还建议您查看命名 azure 插件,它可以帮助您跨资源创建唯一的名称

https://registry.terraform.io/modules/Azure/naming/azurerm/latest

关于azure - Terraform with Azure - 强制资源的唯一名称的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73082009/

相关文章:

git - Azure Devops Repos - 恢复到以前的提交,就像最近的提交从未存在过一样

azure - Terraform 开始适用于 Azure 中已有的 100 多个资源

azure - 从 Jenkins 触发 azure devops 管道

azure - 在 Azure ARM 模板变量中转义美元 $ 符号

azure - CosmosClient 能否给出由于限制而发生的重试次数(http 429)?

azure - 使用 Azure 流分析保留最后的值

amazon-web-services - Terraform_Remote_State 错误 : This object has no argument, 嵌套 block ,或名为 "vpc_id"的导出属性

terraform - Template.tf 和 user_data.yaml.tpl- 通过 list 类型的变量循环

asp.net-core - 使用 VSTS 的 ASP.NET Core 2.1 CI/CD 构建错误

caching - 无法让 Azure 缓存正常工作。 "There is a temporary failure. Please retry later."