`enabled` parameter to avoid logical statements in `count`
Terraform v0.12.2 ### Use-cases We often use `count` to disable a resource (above all in modules) from a boolean var, with statements like `count = var.enabled ? 1 : 0` or `count = var.enabled ? 1 : length([some list of resources or datasources])` Here are among others some code snippets from `terraform-aws-vpc` module : ``` resource "aws_subnet" "private" { count = var.create_vpc && length(var.private_subnets) > 0 ? length(var.private_subnets) : 0 vpc_id = local.vpc_id cidr_block = var.private_subnets[count.index] availability_zone = element(var.azs, count.index) tags = merge( { "Name" = format( "%s-${var.private_subnet_suffix}-%s", var.name, element(var.azs, count.index), ) }, var.tags, var.private_subnet_tags, ) } resource "aws_network_acl" "public" { count = var.create_vpc && var.public_dedicated_network_acl && length(var.public_subnets) > 0 ? 1 : 0 vpc_id = element(concat(aws_vpc.this.*.id, [""]), 0) subnet_ids = aws_subnet.public.*.id tags = merge( { "Name" = format("%s-${var.public_subnet_suffix}", var.name) }, var.tags, var.public_acl_tags, ) } resource "aws_network_acl_rule" "public_inbound" { count = var.create_vpc && var.public_dedicated_network_acl && length(var.public_subnets) > 0 ? length(var.public_inbound_acl_rules) : 0 network_acl_id = aws_network_acl.public[0].id egress = false rule_number = var.public_inbound_acl_r
Posted by romachalm on Jul 2, 2019, 8:16 AM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
`enabled` parameter to avoid logical statements in `count`
Terraform v0.12.2 ### Use-cases We often use `count` to disable a resource (above all in modules) from a boolean var, with statements like `count = var.enabled ? 1 : 0` or `count = var.enabled ? 1 : length([some list of resources or datasources])` Here are among others some code snippets from `terraform-aws-vpc` module : ``` resource "aws_subnet" "private" { count = var.create_vpc && length(var.private_subnets) > 0 ? length(var.private_subnets) : 0 vpc_id = local.vpc_id cidr_block = var.private_subnets[count.index] availability_zone = element(var.azs, count.index) tags = merge( { "Name" = format( "%s-${var.private_subnet_suffix}-%s", var.name, element(var.azs, count.index), ) }, var.tags, var.private_subnet_tags, ) } resource "aws_network_acl" "public" { count = var.create_vpc && var.public_dedicated_network_acl && length(var.public_subnets) > 0 ? 1 : 0 vpc_id = element(concat(aws_vpc.this.*.id, [""]), 0) subnet_ids = aws_subnet.public.*.id tags = merge( { "Name" = format("%s-${var.public_subnet_suffix}", var.name) }, var.tags, var.public_acl_tags, ) } resource "aws_network_acl_rule" "public_inbound" { count = var.create_vpc && var.public_dedicated_network_acl && length(var.public_subnets) > 0 ? length(var.public_inbound_acl_rules) : 0 network_acl_id = aws_network_acl.public[0].id egress = false rule_number = var.public_inbound_acl_r
Comments (0)
No comments yet. Start the discussion.