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

标签 azure terraform terraform-provider-azure azure-container-apps

对于 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/

相关文章:

azure - 如何在 Azure Functions 中使用 OWIN?

c# - 如何通过代码启用EnableSqlCommandTextInstrumentation?

amazon-web-services - AWS CodePipeline 角色无权在阶段的 "action" block 中对角色执行 AssumeRole

amazon-web-services - 启动配置更新 terraform 后实例未刷新

azure - 如何在adls2中找到容器的 super 用户

azure - 如何使用 ARM 部署具有托管 SSL 证书的应用服务

amazon-web-services - Terraform 数据结构 : object and list of object issue

terraform - 如何使用 Terraform >= 0.12 在资源 block 中包含/排除可选属性

azure - 如何在 map 中输出 map 中的特定属性,同时将属性子字符串作为 terraform 中的条件?

azure - Terraform 映射并将值传递给模块