Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform 0.12 + vpc module v2.2 (Inappropriate value for attribute "subnet_ids": element 0: string required.) #271

Closed
marcincuber opened this issue May 29, 2019 · 20 comments

Comments

@marcincuber
Copy link

I am trying to upgrade my terraform but I am stuck at the following;

resource "aws_eks_cluster" "cluster" {
  enabled_cluster_log_types = ["api", "audit", "authenticator", "controllerManager", "scheduler"]
  name                      = "${var.cluster_name}-${var.environment}"
  role_arn                  = aws_iam_role.cluster.arn
  version                   = var.eks_version

  vpc_config {
    subnet_ids              = [module.vpc.public_subnets, module.vpc.private_subnets]
    security_group_ids      = [aws_security_group.cluster.id]
    endpoint_private_access = "true"
    endpoint_public_access  = "true"
  }
}

I am getting the error Inappropriate value for attribute "subnet_ids": element 0: string required.

Could someone advise what is the current way of referencing all subnets and passing them into subnet_ids variable?

Thanks

@marcincuber
Copy link
Author

Found the solution to be subnet_ids = flatten([module.vpc.public_subnets, module.vpc.private_subnets]).

@marcincuber marcincuber changed the title Terraform 0.12 + vpc module v2.2 Terraform 0.12 + vpc module v2.2 (Inappropriate value for attribute "subnet_ids": element 0: string required.) Jun 13, 2019
@saravana-code
Copy link

We are facing the same issue, is it related to any particular terraform version or the OS of the system where we run the "terraform plan/apply"?

@antonbabenko
Copy link
Member

It can be also like this - subnet_ids = concat(module.vpc.public_subnets, module.vpc.private_subnets)

@sonianara
Copy link

I'm getting the same error doing something like this:

subnet_ids = ["${aws_subnet.priv_subnet.*.id}"]

Anyone have any idea how to resolve this?

@antonbabenko
Copy link
Member

@sonianara You can always unwrap value between [ and ] to make it like this:

subnet_ids = "${aws_subnet.priv_subnet.*.id}"

@ammartaj53
Copy link

@antonbabenko it worked like a charm

@ozgiat
Copy link

ozgiat commented Nov 6, 2019

@antonbabenko You saved me hours...
Can you explain whats the difference with [] and without ?

@antonbabenko
Copy link
Member

[] - this adds a wrapping type list, so the type of the produced variable becomes list of lists.

@JPalmerGithub
Copy link

--- antonbabenko commented Nov 8, 2019
--- [] - this adds a wrapping type list, so the type of the produced variable becomes list of lists.
One big Thank You from here too, Sir

@AdeOpe
Copy link

AdeOpe commented Nov 20, 2019

OMG! i cannot say thank you enough for this page!

@demisx
Copy link

demisx commented May 9, 2020

Should the docs be updated? I was running into the same error trying to create a NLB: https://www.terraform.io/docs/providers/aws/r/lb.html

This worked:

resource "aws_lb" "node_port" {
  ...
  subnets = data.aws_subnet_ids.private.ids
  ...

@sikemullivan
Copy link

I needed a combination of the answers above.

subnet_ids = concat("${aws_subnet.private.*.id}", "${aws_subnet.public.*.id}")

@vaibhavjpr
Copy link

I'm getting the same error doing something like this:

subnet_ids = ["${aws_subnet.priv_subnet.*.id}"]

Anyone have any idea how to resolve this?

I tried like this.

resource "aws_db_subnet_group" "dbsubnet" {
name = "testcluster"
subnet_ids = flatten(["${aws_subnet.private.*.id}"]) -- this one
tags = {
Name = "My DB subnet group"
}
}

@antonbabenko
Copy link
Member

Try this syntax: subnet_ids = aws_subnet.priv_subnet.*.id

@alxsbn
Copy link

alxsbn commented Feb 4, 2021

Error still prevalent in v0.14.5 with aws_vpc_endpoint

@andrewrotherham
Copy link

andrewrotherham commented Feb 26, 2021

Removing the brackets has done the trick, but I'm still wondering why one is a list here but the other is a string. Shouldn't they both be stings? This code does work...but why does security_group_ids need the square brackets but subnet_ids doesn't?
vpc_config {
security_group_ids = ["${aws_security_group.demo-cluster.id}"]
subnet_ids = "${aws_subnet.demo.*.id}"

@Jonas-Noh
Copy link

i really want to found this problem, thank a lot.

@pete198016
Copy link

pete198016 commented Sep 7, 2021

Hello,

#terraform provider 3.55.0

resource "aws_vpc_endpoint" "example" {
service_name = aws_vpc_endpoint_service.example.service_name
#subnet_ids = [module.vpc.natgwsub_subnets.*.id]
subnet_ids = module.vpc.natgwsub_subnets
vpc_endpoint_type = aws_vpc_endpoint_service.example.service_type
vpc_id = module.vpc.vpc_id
}

With subnet_ids i need to choose one subnet only - gateway load balancer requirement.
Tried many ways and i can't choose just one.

Example error:

Error: Incorrect attribute value type
on hub-eu/asg.hub-eu.tf line 117, in resource "aws_vpc_endpoint" "example":
subnet_ids = module.vpc.natgwsub_subnets[0]
Inappropriate value for attribute "subnet_ids": set of string required.

Anyone can help ?

@mkatajah
Copy link

mkatajah commented Sep 9, 2021

Hello,

#terraform provider 3.55.0

resource "aws_vpc_endpoint" "example" {
service_name = aws_vpc_endpoint_service.example.service_name
#subnet_ids = [module.vpc.natgwsub_subnets.*.id]
subnet_ids = module.vpc.natgwsub_subnets
vpc_endpoint_type = aws_vpc_endpoint_service.example.service_type
vpc_id = module.vpc.vpc_id
}

With subnet_ids i need to choose one subnet only - gateway load balancer requirement.
Tried many ways and i can't choose just one.

Example error:

Error: Incorrect attribute value type
on hub-eu/asg.hub-eu.tf line 117, in resource "aws_vpc_endpoint" "example":
subnet_ids = module.vpc.natgwsub_subnets[0]
Inappropriate value for attribute "subnet_ids": set of string required.

Anyone can help ?

I encountered similar issue. You can try this: subnet_ids = toset([element(module.vpc.natgwsub_subnets.*.id,0)])

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests