Last active
January 22, 2024 14:03
-
-
Save rlevchenko/358ad95cc5641bc26d2a5705c2c8dbfd to your computer and use it in GitHub Desktop.
Terraform: count and for_each examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example with for_each | |
resource "aws_route53_record" "acm" { | |
for_each = { | |
for dvo in aws_acm_certificate.default.domain_validation_options : dvo.domain_name => { | |
name = dvo.resource_record_name | |
record = dvo.resource_record_value | |
type = dvo.resource_record_type | |
} | |
} | |
allow_overwrite = true | |
name = each.value.name | |
records = [each.value.record] | |
ttl = 60 | |
type = each.value.type | |
zone_id = data.aws_route53_zone.default.zone_id | |
} | |
# Example with count | |
resource "azurerm_servicebus_namespace" "rlmvp-svc-svb" { | |
count = var.servicebus != "false" ? 1 : 0 | |
name = "${var.prefix}-sbns" | |
resource_group_name = azurerm_resource_group.az_rg.name | |
location = var.az_region | |
sku = var.az_sb_sku | |
zone_redundant = (var.az_sb_sku != "Premium" ? "false" : "true") | |
capacity = (var.az_sb_sku != "Premium" ? 0 : var.az_sb_capacity) | |
tags = var.az_tags | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source: https://rlevchenko.com/2020/09/15/deploy-azure-data-services-with-terraform/