amazon-web-servicesamazon-vpcterraform-aws-modulesaws-transfer-family

Terraform - exporting output into variable issue


I am trying to get elastic_ip ID created in vpc module and pass it to trasnfer family module to deploy AWS trasnfer family server in VPC with internet facing.

So I am creating two elastic IP, one of each subnet. (There are two subnets)

resource "aws_vpc_endpoint" "aws_trasnfer_server" {
  vpc_id = aws_vpc.shared_services_vpc.id
  service_name = "com.amazonaws.${var.aws_region}.transfer.server"
  subnet_ids = ["${aws_subnet.public_subnet_2a.id}", "${aws_subnet.public_subnet_2b.id}"]
  security_group_ids = ["${aws_default_security_group.default.id}"]
  vpc_endpoint_type = "Interface"
}

locals {
  network_interfaces = aws_vpc_endpoint.aws_trasnfer_server.network_interface_ids
  # private_id = aws_vpc_endpoint.aws_trasnfer_server.network_interface_ids
}

resource "aws_eip" "subnet_eips_one" {
  for_each = local.network_interfaces
  vpc = true
}

Above code is working fine but I am not able export elastic_ip IDs and pass to trasnfer module. Here is output.tf of vpc module

output "elastic_ips" {
  value = toset(values(aws_eip.subnet_eips_one[*].id))
  # aws_security_group.example.*.id
} 

While running the script, getting below error

╷
│ Error: Unsupported attribute
│ 
│   on vpc/outputs.tf line 19, in output "elastic_ips":
│   19:   value = toset(values(aws_eip.subnet_eips_one[*].id))
│ 
│ This object does not have an attribute named "id".

I could see output of

toset(values(aws_eip.subnet_eips_one))

as below and error.

elastic_ips                  = [
      - "eni-012334567899",
      - "eni-023568765465",
      + {
          + address                   = null
          + allocation_id             = "eipalloc-0aaaaaaaaaaaa"
          + associate_with_private_ip = null
          + association_id            = ""
          + carrier_ip                = ""
          + customer_owned_ip         = ""
          + customer_owned_ipv4_pool  = ""
          + domain                    = "vpc"
          + id                        = "eipalloc-0aaabbbbbbbb"
          + instance                  = ""
          + network_border_group      = "us-west-2"
          + network_interface         = ""
          + private_dns               = null
          + private_ip                = ""
          + public_dns                = "ec2-00-00-00.00.us-west-2.compute.amazonaws.com"
          + public_ip                 = ""
          + public_ipv4_pool          = "amazon"
          + tags                      = {}
          + tags_all                  = {}
          + timeouts                  = null
          + vpc                       = true
        },
      + {
          + address                   = null
          + allocation_id             = "eipalloc-ccccc"
          + associate_with_private_ip = null
          + association_id            = ""
          + carrier_ip                = ""
          + customer_owned_ip         = ""
          + customer_owned_ipv4_pool  = ""
          + domain                    = "vpc"
          + id                        = "eipalloc-dddddddd"
          + instance                  = ""
          + network_border_group      = "us-west-2"
          + network_interface         = ""
          + private_dns               = null
          + private_ip                = ""
          + public_dns                = "ec2-00-00-00-00.us-west-2.compute.amazonaws.com"
          + public_ip                 = "00.0.0.0"
          + public_ipv4_pool          = "amazon"
          + tags                      = {}
          + tags_all                  = {}
          + timeouts                  = null
          + vpc                       = true
        },
    ]


│ Error: Incorrect attribute value type
│ 
│   on awstransfer/main.tf line 22, in resource "aws_transfer_server" "filetransfer_server":
│   22:     address_allocation_ids = var.elastic_ips
│     ├────────────────
│     │ var.elastic_ips is set of object with 2 elements
│ 
│ Inappropriate value for attribute "address_allocation_ids": incorrect set element type: string required.

I have tried multiple options but not able get ids exactly and pass it to output variable.

am I missing anything? Thanks in advance for your help.

Thanks.


Solution

  • One of your ) is in the wrong position. Also you do not really need toset. So it should be:

    value = values(aws_eip.subnet_eips_one)[*].id