Возможность пропустить повторные объявления одного и того же значения для многих ресурсов - PullRequest
0 голосов
/ 26 июня 2019

Мне приходится много раз повторять одно и то же значение параметра в моих файлах terraform.Можно ли объявить некоторую переменную, которая будет автоматически устанавливать эти параметры для всех ресурсов текущего файла, где есть параметр с таким именем?

Это то, что я сейчас пишу:

resource "azurerm_resource_group" "rg" {
  name     = "${var.resourceGroupName}"
  location = "${var.location}"
  tags     = "${var.tags}"
}

resource "azurerm_storage_account" "storage" {
  name                     = "myuniquestorageaccount"
  resource_group_name      = "${azurerm_resource_group.rg.name}"
  tags                     = "${azurerm_resource_group.rg.tags}"
  location                 = "${azurerm_resource_group.rg.location}"
  account_tier             = "Standard"
  account_kind             = "StorageV2"
  account_replication_type = "GRS"
}

resource "azurerm_storage_queue" "queue" {
  name                 = "events"
  storage_account_name = "${azurerm_storage_account.storage.name}"
  resource_group_name  = "${azurerm_resource_group.rg.name}"
}

resource "azurerm_storage_table" "sessions" {
  name                 = "sessions"
  storage_account_name = "${azurerm_storage_account.storage.name}"
  resource_group_name  = "${azurerm_resource_group.rg.name}"
}

resource "azurerm_storage_table" "streams" {
  name                 = "streams"
  storage_account_name = "${azurerm_storage_account.storage.name}"
  resource_group_name  = "${azurerm_resource_group.rg.name}"
}

Обратите внимание, как resource_group_name, tags и location должны применяться много раз, всегда с одним и тем же значением.

Я хотел бы написать такой код:

autoparameter {
  resource_group_name  = "${azurerm_resource_group.rg.name}"
  storage_account_name = "${azurerm_storage_account.storage.name}"
  tags                 = "${var.tags}"
  location             = "${var.location}"
}


resource "azurerm_resource_group" "rg" {
  name = "${var.resourceGroupName}"
}

resource "azurerm_storage_account" "storage" {
  name                     = "myuniquestorageaccount"
  account_tier             = "Standard"
  account_kind             = "StorageV2"
  account_replication_type = "GRS"
}

resource "azurerm_storage_queue" "queue" {
  name = "events"
}

resource "azurerm_storage_table" "sessions" {
  name = "sessions"
}

resource "azurerm_storage_table" "streams" {
  name = "streams"
}
...