You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Terraform AWS无法输出VPC端点:不支持属性问题排查

问题:Terraform VPC端点模块输出报错:对象无"endpoints"属性

问题详情

执行terragrunt validate时出现如下错误:

Error: Unsupported attribute

   on outputs.tf line 4, in output "vpc-endpoints-oregon":
    4:   value       = module.vpc-endpoints-oregon.endpoints
      module.vpc-endpoints-oregon is a object

 This object does not have an attribute named "endpoints".

ERRO[0002] Terraform invocation failed in path-to/vpc_endpoints
ERRO[0002] 1 error occurred:
        * exit status 1

相关模块文件内容如下:

modules/vpc_endpoints/main.tf

module "vpc_endpoints" {
  source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
  version = "3.16.0"

  vpc_id             = var.vpc_id
  security_group_ids = [data.aws_security_group.default.id]

  endpoints = {
    s3 = {
      service = "s3"
      tags    = { Name = "s3-vpc-endpoint" }
    },
    dynamodb = {
      service         = "dynamodb"
      service_type    = "Gateway"
      route_table_ids = flatten([var.intra_route_table_ids,
                                 var.private_route_table_ids,
                                 var.public_route_table_ids])

      policy          = data.aws_iam_policy_document.dynamodb_endpoint_policy.json
      tags            = { Name = "dynamodb-vpc-endpoint" }
    },
    lambda = {
      service             = "lambda"
      private_dns_enabled = true
      subnet_ids          = var.private_subnets
      tags                = { Name = "lambda-vpc-endpoint" }
    },
  }
}

modules/vpc_endpoints/outputs.tf

# VPC endpoints
output "vpc_endpoints" {
  description = "Array containing the full resource object and attributes for all endpoints created"
  value       = module.vpc_endpoints.endpoints
}

vpc_endpoints目录下的main.tf

module "vpc-endpoints-oregon" {
  source = "../../modules/vpc_endpoints"
  #version = "3.16.0"

  cluster_name            = var.cluster_name
  environment             = var.environment

  vpc_id                  = var.vpc_id
  intra_route_table_ids   = var.intra_route_table_ids
  private_route_table_ids = var.private_route_table_ids
  public_route_table_ids  = var.public_route_table_ids
  private_subnets         = var.private_subnets
  vpc_cidr_block          = var.vpc_cidr_block

  name_prefix             = "vpc_tls"
}

vpc_endpoints目录下的outputs.tf

output "vpc-endpoints-oregon" {
  description = "Array containing the full resource object and attributes for all endpoints created"
  value       = module.vpc-endpoints-oregon.endpoints
}

错误原因

你的自定义模块modules/vpc_endpoints对外暴露的输出属性名为vpc_endpoints,但在调用该模块的vpc_endpoints目录下,你试图访问的是module.vpc-endpoints-oregon.endpoints——这个属性根本不存在,自然会报错。

简单说:自定义模块输出的是vpc_endpoints,你却要访问endpoints,属性名不匹配。

解决方案

修改vpc_endpoints目录下的outputs.tf,将访问的属性名改为vpc_endpoints:

output "vpc-endpoints-oregon" {
  description = "Array containing the full resource object and attributes for all endpoints created"
  value       = module.vpc-endpoints-oregon.vpc_endpoints
}

内容的提问来源于stack exchange,提问作者user20208419

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:41:31