1

我需要在 Terraform 中执行以下操作,但不知道如何

这是我所拥有的

local {
app_config = {
    test-web = {
      name            = "test-web-${local.environment}"
      websockets      = false
      subnet          = "backend"
      audience_subnet = "frontend"
      url             = "https://test-web-${local.environment}.mydomain.com"
    }
    test-api  = {
      name            = "test-api-${local.environment}"
      websockets      = false
      subnet          = "backend"
      audience_subnet = "frontend"
      url             = "https://test-api-${local.environment}.mydomain.com"
    }
  }


keyvault_secrets = {
    aat = {
        test-api = {
            application_id = "1111"
            client_id = "2222"
            administrator_pass = "3333"
        }
        test-web = {
            application_id = "4444"
            client_id = "5555"
            administrator_pass = "6666"
        }
    }
    Demo = {
        test-api = {
            application_id = "1212"
            client_id = "2323"
            administrator_pass = "3434"
        }
        test-web = {
            application_id = "4545"
            client_id = "5656"
            administrator_pass = "6767"
        }
    }
    Dev = {
        test-api = {
            application_id = "9999"
            client_id = "8888"
            administrator_pass = "7777"
        }
        test-web = {
            application_id = "9898"
            client_id = "8787"
            administrator_pass = "7676"
        }
    }
}

resource "azurerm_key_vault_secret" "app_id" {
  for_each = var.apps_config

  name         = var.apps_config
  value        = each.value.application_id
  key_vault_id = data.azurerm_key_vault.mykv.id
}

resource "azurerm_key_vault_secret" "client_id" {
  for_each = var.apps_config

  name         = var.apps_config
  value        = each.value.client_id
  key_vault_id = data.azurerm_key_vault.mykv.id
}

resource "azurerm_key_vault_secret" "admin_pass" {
  for_each = var.apps_config

  name         = var.apps_config
  value        = each.value.administrator_pass
  key_vault_id = data.azurerm_key_vault.mykv.id
}

我无法解决的是您如何执行以下操作:对于定义的每个 app_config,例如:test-web test-api

Key Vault 机密由运行时定义的环境创建:

Terraform 计划或应用 -var="environment=dev"

我希望它为每个 app_config 创建 3 个秘密

4

0 回答 0