if statement - Est-il possible de désactiver le bloc access_logs via la variable environment_name

Mots clés : if-statementconditional-statementsterraformif-statement

meilleur 4 Réponses if statement - Est-il possible de désactiver le bloc access_logs via la variable environment_name

vote vote

93

dynamic "access_logs" {   for_each = var.environment_name == "production" ? [var.environment_name] : []   content {     bucket  = "my-bucket"     prefix  = "${var.environment_name}-alb"   } } 
vote vote

83

access_logs {     bucket  = "my-bucket"     prefix  = "${var.environment_name}-alb"     enabled = "${var.environment_name == "production" ? true : false }" } 
vote vote

72

locals {   isProd = var.environment_name == "production" ? [1] : []    // Not necessary, but just illustrating that the reverse is possible   isNotProd = var.environment_name == "production" ? [] : [1] }  dynamic "access_logs" {   for_each = local.isProd   content {     bucket  = "my-bucket"     prefix  = "${var.environment_name}-alb"   } } 
vote vote

70

dynamic "access_logs" {   for_each = range(var.environment_name == "production" ? 1 : 0)    contents {     bucket  = "my-bucket"     prefix  = "${var.environment_name}-alb"   } } 

Questions similaires