Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11357

Using count to enable/disable resources in terraform 0.12 leads to odd code patterns

$
0
0

@dgmora wrote:

Hi, up until now in terraform 0.11 we were using things similar to this:

resource "aws_db_subnet_group" "main" {
  count = "${var.db_count}"
}

resource "aws_db_instance" "rds_instance" {
  # . . .
  count = "${var.db_count}"
  db_subnet_group_name = "${aws_db_subnet_group.main.name}"
}

We used count to easily disable/enable resources or whole modules, depending on certain situations. This with terraform 0.12 is not directly possible, and you have to change db_subnet_group_name to

  db_subnet_group_name = "${aws_db_subnet_group.main[count.index].name}" 

In terraform 0.11 this wasn’t necessary if count was 1. We use count to enable/disable resources, so upgrading to terraform 0.12 will mean loads of [count.index] added in order to be able to have enable/disable.

I see that it can make sense that count works like that, from the perspective of enabling and disabling things it is cumbersome. Is there another recommended way to enable or disable resources instead of using count?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 11357

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>