gpt4 book ai didi

azure - 使用 Azure Terraform AzApi 提供程序为容器应用程序环境启用内部负载平衡模式

转载 作者:行者123 更新时间:2023-12-03 06:12:02 28 4
gpt4 key购买 nike

对于 ACA 环境,如何使用 AzApi Terraform 提供程序启用内部平衡器模式。这是当前配置:

resource "azapi_resource" "aca_env" {
for_each = { for aca_env in var.aca_envs : aca_env.name => aca_env}
type = "Microsoft.App/managedEnvironments@2022-11-01-preview"
name = each.value.name
parent_id = azurerm_resource_group.rg.id
location = each.value.location

body = jsonencode({
properties = {
appLogsConfiguration = {
destination = "log-analytics"
logAnalyticsConfiguration = {
customerId = azurerm_log_analytics_workspace.law["${each.value.name}-law"].workspace_id
sharedKey = azurerm_log_analytics_workspace.law["${each.value.name}-law"].primary_shared_key
}
}
vnetConfiguration = {
"internal" = true
"infrastructureSubnetId" = data.azurerm_subnet.subnets[each.value.subnet_id].id
}
workloadProfiles = [
{
name = "Consumption"
workloadProfileType = "Consumption"
}
]
}
})
}

我知道 azurermazurerm_container_app_environment 为此公开了属性 internal_load_balancer_enabled。但是如何使用 AzAPI 提供程序执行此操作?

最佳答案

要使用 internalLoadBalancer 创建容器应用环境,如果您使用的是Azure Terraform AzApi Provider,则可以使用“internal = true”

我已使用 Azure Terraform AzApi Provider 通过 internalLoadBalancer 创建了容器应用环境

terraform {
required_providers {
azapi = {
source = "azure/azapi"
}
}
}
provider "azapi" {}
provider "azurerm" {
features {}
}

resource "azurerm_virtual_network" "venkatnetwork" {
name = "acceptanceTestVirtualNetwork1test"
address_space = ["10.0.0.0/16"]
location = "eastus"
resource_group_name = "venkattests-resources"
}

resource "azurerm_subnet" "venkatsub" {
name = "testsubnet1"
resource_group_name = "venkattests-resources"
virtual_network_name =azurerm_virtual_network.venkatnetwork.name
address_prefixes = ["10.0.1.0/24"]
delegation {
name = "acctestdelegation"
service_delegation {
name = "Microsoft.App/environments"
actions = ["Microsoft.Network/virtualNetworks/subnets/join/action", "Microsoft.Network/virtualNetworks/subnets/prepareNetworkPolicies/action"]
}
}
}

resource "azapi_resource" "aca_env" {
type = "Microsoft.App/managedEnvironments@2022-11-01-preview"
name = "my-aca-env-name"
parent_id = "/subscriptions/xxxxxx-7f0905ec6833/resourceGroups/venkattests-resources"
location = "eastus"
body = jsonencode({
properties = {
vnetConfiguration = {
"internal" = true
"infrastructureSubnetId" = azurerm_subnet.venkatsub.id
}
workloadProfiles = [
{
name = "Consumption"
workloadProfileType = "Consumption"
}
]
}
})
}

Terraform 应用:

enter image description here

如果您在 terraform 代码的 Vnet 配置部分中设置 internal = true,则内部环境将使用虚拟 IP 进行部署,内部端点为 Azure internal load balancer IP 地址是从自定义 VNet 的私有(private) IP 地址列表中发出的。

enter image description here

如果我尝试从门户创建带有负载均衡器的容器应用环境进行测试,输出是否与Terraform部署相同。

我在虚拟 IP 部分下选择了内部

enter image description here

具有负载均衡器(虚拟IP)的容器应用。

enter image description here

关于azure - 使用 Azure Terraform AzApi 提供程序为容器应用程序环境启用内部负载平衡模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76667392/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com