Home > Software engineering >  Terraform AWS: Cannot output VPC endpoints. Unsupported attribute
Terraform AWS: Cannot output VPC endpoints. Unsupported attribute

Time:11-15

I cannot output vpc endpoints. I got

module.vpc-endpoints-oregon is an object. This object does not have an attribute named "endpoints".

In the modules/vpc_endpoints folder, there are three files,

main.tf outputs.tf variables.tf

cat 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" }
    },
  }
}

cat modules/vpc_endpoints/outputs.tf

cat 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
}

In the vpc_endpoints folder, there are three files, main.tf outputs.tf variables.tf

cat 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"
}

cat 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
}

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

Why does it claim This object does not have an attribute named "endpoints"?

CodePudding user response:

The output is called vpc_endpoints, not endpoints. So it should be:

value       = module.vpc-endpoints-oregon.vpc_endpoints
  • Related