不支持的参数。此处不应使用名为“subnet_id”的参数
Posted
技术标签:
【中文标题】不支持的参数。此处不应使用名为“subnet_id”的参数【英文标题】:Unsupported argument .An argument named “subnet_id” is not expected here 【发布时间】:2021-10-06 15:37:24 【问题描述】:为 terraform 文件中的 aks 添加了应用程序网关入口控制器。添加后显示上述错误。 我在 azure 中的模块如下
集群资源组
resource “azurerm_resource_group” “aks”
name = var.resource_group_name
location = var.location
AKS 集群网络
module “aks_network”
source = “…/modules/aks_network”
subnet_name = var.subnet_name
vnet_name = var.vnet_name
name = azurerm_resource_group.aks.name
subnet_cidr = var.subnet_cidr
location = var.location
address_space = var.address_space
app_gateway_subnet_name = var.app_gateway_subnet_name
app_gateway_subnet_address_prefix = var.app_gateway_subnet_address_prefix
AKS 日志分析
module “log_analytics”
source = “…/modules/log_analytics”
name = azurerm_resource_group.aks.name
log_analytics_workspace_location = var.log_analytics_workspace_location
log_analytics_workspace_name = var.log_analytics_workspace_name
log_analytics_workspace_sku = var.log_analytics_workspace_sku
AKS 集群
module “aks_cluster”
source = “…/modules/aks-cluster”
cluster_name = var.cluster_name
location = var.location
dns_prefix = var.dns_prefix
name = azurerm_resource_group.aks.name
kubernetes_version = var.kubernetes_version
node_count = var.node_count
min_count = var.min_count
max_count = var.max_count
vm_size = var.vm_size
service_cidr = var.service_cidr
network_plugin = var.network_plugin
vnet_subnet_id = module.aks_network.aks_subnet_id
client_id = var.client_id
client_secret = var.client_secret
environment = var.environment
subnet_id = module.aks_network.subnet_app_gateway_id
及以下是上述模块的变量文件
变量.tf
variable “client_id”
description = “Azure Service Principal id (client id)”
variable “client_secret”
description = “Azure client Service Principal secret (client secret)”
variable resource_group_name
description = “Resource Group name”
variable “node_count”
description = “number of nodes to deploy”
variable “dns_prefix”
description = “DNS Suffix”
variable cluster_name
description = “AKS cluster name”
variable location
description = “azure location to deploy resources”
variable log_analytics_workspace_name
description = “azure name to deploy log analytics workspace”
variable log_analytics_workspace_location
description = “azure location to deploy log analytics workspace”
variable log_analytics_workspace_sku
description = “azure sku to deploy log analytics workspace”
variable subnet_name
description = “subnet id where the nodes will be deployed”
variable vnet_name
description = “vnet id where the nodes will be deployed”
variable subnet_cidr
description = “the subnet cidr range”
variable kubernetes_version
description = “version of the kubernetes cluster”
variable “vm_size”
description = “size/type of VM to use for nodes”
variable “service_cidr”
description = “size/type of VM to use for nodes”
variable “network_plugin”
description = “size/type of VM to use for nodes”
variable “address_space”
description = “The address space that is used the virtual network”
variable “min_count”
description = “Minimum Node Count”
variable “max_count”
description = “Maximum Node Count”
variable “environment”
description = “Environment”
variable “app_gateway_subnet_name”
description = “App Gateway Subnet Name”
variable “app_gateway_subnet_address_prefix”
description = “App Gateway Subnet Address Prefix”
aks_network
main.tf 如下
resource “azurerm_virtual_network” “aks_vnet”
name = var.vnet_name
address_space = [var.address_space]
resource_group_name = var.name
location = var.location
resource “azurerm_subnet” “aks_subnet”
name = var.subnet_name
resource_group_name = var.name
virtual_network_name = azurerm_virtual_network.aks_vnet.name
address_prefix = var.subnet_cidr
resource “azurerm_subnet” “subnet_app_gateway”
resource_group_name = var.name
virtual_network_name = azurerm_virtual_network.aks_vnet.name
name = var.app_gateway_subnet_name
address_prefix = var.app_gateway_subnet_address_prefix
变量.tf
variable “subnet_name”
description = “name to give the subnet”
variable “name”
description = “resource group that the vnet resides in”
variable “vnet_name”
description = “name of the vnet that this subnet will belong to”
variable “subnet_cidr”
description = “the subnet cidr range”
variable “location”
description = “the cluster location”
variable “address_space”
description = “Network address space”
variable “app_gateway_subnet_name”
description = “App Gateway Subnet Name.”
default = “agw-subnet”
variable “app_gateway_subnet_address_prefix”
description = “Containers DNS server IP address.”
default = “10.100.0.0/24”
aks-集群 main.tf
resource “azurerm_kubernetes_cluster” “cluster”
name = var.cluster_name
location = var.location
resource_group_name = var.name
dns_prefix = var.dns_prefix
kubernetes_version = var.kubernetes_version
default_node_pool
name = var.default_pool_name
node_count = var.node_count
vm_size = var.vm_size
vnet_subnet_id = var.vnet_subnet_id
type = var.default_pool_type
enable_auto_scaling = true
min_count = var.min_count
max_count = var.max_count
addon_profile
azure_policy
enabled = true
ingress_application_gateway
enabled = true
subnet_id = resource.azurerm_subnet.subnet_app_gateway.id
role_based_access_control
enabled = true
network_profile
network_plugin = var.network_plugin
network_policy = "azure"
service_cidr = var.service_cidr
dns_service_ip = "10.0.0.10"
docker_bridge_cidr = "172.17.0.1/16"
service_principal
client_id = var.client_id
client_secret = var.client_secret
tags =
Environment = var.environment
变量.tf
variable “dns_prefix”
description = “DNS prefix”
variable “location”
description = “azure location to deploy resources”
variable “cluster_name”
description = “AKS cluster name”
variable “name”
description = “name of the resource group to deploy AKS cluster in”
variable “kubernetes_version”
description = “version of the kubernetes cluster”
variable “agent_pool_name”
description = “name for the agent pool profile”
default = “agentpool”
variable “agent_pool_type”
description = “type of the agent pool (AvailabilitySet and VirtualMachineScaleSets)”
default = “VirtualMachineScaleSets”
variable “node_count”
description = “number of nodes to deploy”
variable “vm_size”
description = “size/type of VM to use for nodes”
variable “vnet_subnet_id”
description = “vnet id where the nodes will be deployed”
variable “network_plugin”
description = “network plugin for kubenretes network overlay (azure or calico)”
variable “service_cidr”
description = “kubernetes internal service cidr range”
variable “client_id”
description = “Service principle Client Id”
variable “client_secret”
description = “Service principle Client Secret”
variable “min_count”
description = “Minimum Node Count”
variable “max_count”
description = “Maximum Node Count”
variable “default_pool_name”
description = “name for the agent pool profile”
default = “agentpool”
variable “default_pool_type”
description = “type of the agent pool (AvailabilitySet and VirtualMachineScaleSets)”
default = “VirtualMachineScaleSets”
variable “environment”
description = “Environment”
aks-cluster 模块中没有这样的变量“subnet_id”,因此在删除显示以下错误后删除了 aks_cluster 中的子网id
其中的 aks-cluster 文件夹 main.tf 中的块类型不受支持 此处不应出现 ingress_application_gateway 类型的块。
【问题讨论】:
【参考方案1】:以防其他人在搜索此错误消息时进入此页面。我们通过将 terraform 提供程序 azurerm 从版本 2.43 升级到 2.73 修复了错误“这里不需要 ingress_application_gateway 类型的块”
terraform
required_providers
azurerm =
source = "hashicorp/azurerm"
version = "~>2.73.0"
【讨论】:
以上是关于不支持的参数。此处不应使用名为“subnet_id”的参数的主要内容,如果未能解决你的问题,请参考以下文章
通过 terraform 创建 Azure App 服务时抛出错误此处不应出现名为“zone_redundant”的参数
此处不应出现“azure_blob_fs_location”类型的块
Eclipse打开时“发现了以元素'd:skin'”开头的无效内容。此处不应含有子元素的解决方法