【问题标题】:Conditionally execute nested block restore_to_point_in_time有条件地执行嵌套块 restore_to_point_in_time
【发布时间】:2021-11-21 04:59:58
【问题描述】:

我想根据标志 restore 设置为 true 或 false 有条件地执行 restore_to_point_in_time 块。

  • 问题 1:我怎样才能做到这一点?我尝试将 for_each 与动态一起使用,但没有用。
  • 问题 2:在使用 restore_time 参数时,我收到错误作为意外参数。
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
  }
}

【问题讨论】:

    标签: amazon-web-services terraform terraform-provider-aws


    【解决方案1】:

    dynamic blocks 是这样做的方法:

    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
        }
      }
    }
    
    

    【讨论】:

    • 感谢 Marcin,它可以工作了 :)
    猜你喜欢
    • 1970-01-01
    • 2012-05-19
    • 1970-01-01
    • 2020-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    相关资源
    最近更新 更多