Terraform Module Error

Hi I’m creating AWS Network Interface terraform module and getting below error -

Error: Unsupported attribute

│ on aws-nt-locals.tf line 11, in locals:
│ 11: id = module.test1-eni.id
│ ├────────────────
│ │ module.test1-eni is object with 1 attribute “plan-sg”

│ This object does not have an attribute named “id”.

Below is the tf code


resource "aws_network_interface" "eni" {
  subnet_id       = var.subnet_id
  security_groups = var.security_groups

locals {
  instances = [
      name                        = "xxxxxx"
      associate_public_ip_address = true
      instance_type               = "t3.medium"
      ami_id                      = local.ami_images.ubuntu2204
      availability_zone           = "ap-southeast-1a"
      ebs_block_device = {
        volume_size = 50
        volume_type = "gp2"
        throughput  = 250
      network_interface = {
        id           = module.test1-eni.id
        device_index = 0

module "test1-eni" {
  for_each        = { for index, sg in local.test_sg : sg.name => sg }
  source          = "../../../../modules/aws/aws-network-interface"
  subnet_id       = module.vpc-xproject.public_subnet_id["ap-southeast-1a"]
  security_groups = [module.xproject-sg[each.key].id]
  location        = var.location
  environment     = var.environment

Appreciated the answers. Thanks

1 Like

Terraform has identified an error in your code. You should fix the error, or provide further details about what you are looking for help with.

I have provided the related code above. Let me know what you need

The error involves a module you have not provided the code for:

Also you haven’t acted upon Welcome to the forum - please reformat your message

Oh, I see, you’ve concatenated the module code and the calling code with no visible separator, making it rather non-obvious that there are two separate code snippets there.

is invalid since you haven’t declared any output within the module, have a read of Output Values - Configuration Language | Terraform | HashiCorp Developer

Hi mate thanks for the heads up. Have read the welcome message and reacted. Updated the post according to the welcome message. you can view the code snippet in proper way now.
So i need to reference the child module id in parent output ??
Kindly let me know. Thanks

Your copy/pasted code is still confusing, as there is still no indication which bits come from which files and directories. You should break it up into separate blocks for each file, and clearly state the directory path to each file above each block.

I do not understand what you mean when you say

but it doesn’t sound correct to me.

The problem is simple:

  • You have written a reference to a module output (module.test1-eni.id).
  • You have not defined any such output (output "id" { ... }) in that module, so you get an error.

Please refer to the documentation link I provided above which documents these matters.

This is the first time you’ve disclosed that this part of the configuration exists. That has wasted a lot of time, as it pretty much invalidates the entire conversation up to this point.

Thank you for the new, better formatted, complete code post. From that, I can see the real problem is something entirely different:

This part of your configuration is incorrect:

because you have used for_each here:

meaning that module.test1-eni is not a single module, but a collection of multiple module instances.

You must decide which of those you are trying to look up the id attribute from:


Hi Max thanks for the reply. So is the below works ???


I’m sorry, I have to give up helping in this thread at this point, I don’t know how to communicate any more clearly than I already have.