【发布时间】:2021-01-03 22:02:15
【问题描述】:
如果定义的变量为空或为空,是否有任何方法可以跳过 terraform 块/文件。而不是抛出错误。
我已经为 azure 创建了两个 terraform 脚本。
- 用于 Azure 自动化创建、运行手册创建。
- 用于创建事件网格。
在执行第一步之后,我必须手动生成一个 webhook URL(对于 webhook 生成没有这样的自动化支持)。生成 webhook URL 后,我需要在第二个资源中定义它。如果我定义了空/null 或无效的 URL,那么 terraform 会抛出错误。
下面是 terraform 代码。
data "local_file" "runbook_script" {
filename = "${path.module}/envent-grid-runbook.ps1"
}
resource "azurerm_automation_runbook" "runbook" {
name = "event-gird-notification"
location = var.location
resource_group_name = var.resource_group_name
automation_account_name = azurerm_automation_account.CreateAutomation.name
log_verbose = true
log_progress = true
description = "This runbook is creted for event grid notification"
runbook_type = "PowerShell"
content = data.local_file.runbook_script.content
publish_content_link {
uri = ""
}
}
resource "azurerm_eventgrid_event_subscription" "key-vault" {
name = "test"
scope = "/subscriptions/xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx/name"
topic_name = "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/xxxxxx/vault"
webhook_endpoint {
url = var.webhook_url
}
included_event_types = [
"Microsoft.KeyVault.SecretNewVersionCreated",
"Microsoft.KeyVault.SecretNearExpiry",
"Microsoft.KeyVault.SecretExpired"
]
event_delivery_schema = "EventGridSchema"
}
如果我为 webhook ULR 变量定义了 null/empty var。然后低于错误。
Error: "webhook_endpoint.0.url": required field is not set
我创建了一个 Jenkins 作业,所有 terraform 代码都在一个作业中运行。如果代码失败,那么整个工作都会失败。这就是为什么在 var 为空或 null 时寻找跳过特定块/文件的解决方案的原因。
【问题讨论】:
标签: azure terraform devops terraform-provider-azure