terraform 0.12 issue: Error: Reference to "count" in non-counted context

1,142 views
Skip to first unread message

Thomas Krautzberger

unread,
May 28, 2019, 1:44:21 AM5/28/19
to Terraform


C:\Testinfo\AWS_Dathub_Vora\AWS-EKS-cluster-Setup-master\AWS-EKS-cluster-Setup-master\EKS_Cluster>terraform plan

Error: Reference to "count" in non-counted context

  on eks_cluster_cloudform_stack.tf line 24, in resource "aws_cloudformation_stack" "eks-worker-nodes":
  24:     Subnets                             = aws_subnet.terraform[count.index].id

The "count" object can be used only in "resource" and "data" blocks, and only
when the "count" argument is set.


Im calling in my tf an AWS cloudformation template and fill it with the necessary parameters, wher one of them is this subnet stuff:

resource "aws_cloudformation_stack" "eks-worker-nodes" {
name = "${var.eks_cluster_name}-worker-node"
capabilities = ["CAPABILITY_IAM"]
depends_on = [aws_eks_cluster.terraform]

#Assigning tags to worker nodes

tags = {
instance_group_01 = var.instance_group_01
pqp_testnumber = var.pqp_testnumber
}

parameters = {
KeyName = var.key_name
NodeInstanceType = var.instance_type_EKS_worker
NodeAutoScalingGroupMinSize = "1"
NodeAutoScalingGroupMaxSize = "10"
NodeAutoScalingGroupDesiredCapacity = var.worker_node_capacity
NodeVolumeSize = var.EKS_worker_space_GB
NodeGroupName = var.eks_cluster_name
ClusterName = var.eks_cluster_name
ClusterControlPlaneSecurityGroup = aws_security_group.terraform_eks_sg.id
Subnets = aws_subnet.terraform[count.index].id
}

}


But looking at the upgrade guide https://www.terraform.io/upgrade-guides/0-12.html it looks like for me that Subnets = aws_subnet.terraform[count.index].id
is the correct syntax.

Any ideas?

Thanks,
Thomas

Stuart Clark

unread,
May 28, 2019, 6:46:15 AM5/28/19
to terrafo...@googlegroups.com, Thomas Krautzberger
On 28/05/2019 06:44, Thomas Krautzberger wrote:


C:\Testinfo\AWS_Dathub_Vora\AWS-EKS-cluster-Setup-master\AWS-EKS-cluster-Setup-master\EKS_Cluster>terraform plan

Error: Reference to "count" in non-counted context

  on eks_cluster_cloudform_stack.tf line 24, in resource "aws_cloudformation_stack" "eks-worker-nodes":
  24:     Subnets                             = aws_subnet.terraform[count.index].id

The "count" object can be used only in "resource" and "data" blocks, and only
when the "count" argument is set.


As the error says, you can only use count.index if the resource/data block you are in has a "count" element, which your example does not.

Are you just wanting the first subnet to be passed to the parameter? If so replace it with [0] instead of [count.index]

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/792925a9-4a2d-4187-a3bd-8c5df844fe5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
Stuart Clark
Reply all
Reply to author
Forward
0 new messages