Home > Software engineering >  Conditionally execute nested block restore_to_point_in_time
Conditionally execute nested block restore_to_point_in_time

Time:09-30

I want to execute the restore_to_point_in_time block conditionally depending on the flag restore set as true or false.

  • Question 1: how can i achieve this? I tried using for_each with dynamic, didnt work.
  • Question 2: on using restore_time argument I am getting error as unexpected argument.
resource "aws_rds_cluster" "rds_mysql" {
  .. ....
  
restore_to_point_in_time {
  source_cluster_identifier         = var.source_cluster_identifier
  restore_type                      = var.restore_type
  restore_time                      = var.restore_time
  }
}

CodePudding user response:

dynamic blocks is the way to do it:

resource "aws_rds_cluster" "rds_mysql" {
  .. ....
  
dynamic "restore_to_point_in_time" {

   for_each = var.restore == true ? [1] : []

   content {
    source_cluster_identifier         = var.source_cluster_identifier
    restore_type                      = var.restore_type
    restore_time                      = var.restore_time
    }
  }
}

  • Related