【问题标题】:how to create a multi-node redshift cluster only for prod using Terraform如何使用 Terraform 仅为 prod 创建多节点 redshift 集群
【发布时间】:2017-11-12 01:16:26
【问题描述】:

我有 2 个 redshift 集群 prod 和 dev ,我正在使用相同的 terraform 模块。 我如何才能有 2 个节点仅用于生产集群。请让我知道我应该使用什么插值语法

variable "node_type" {
  default = "dc1.large"
}

resource "aws_redshift_cluster" "****" {
  cluster_identifier           = "abc-${var.env}"
  node_type                    = "${var.node_type}"
  cluster_type                 = "single-node" ==> multi node
  number_of_nodes              = 2 ==> only for prod

【问题讨论】:

    标签: amazon-redshift terraform


    【解决方案1】:

    使用map type

    variable "node_type" {
      default = "dc1.large"
    }
    
    variable "env" {
      default = "development"
    }
    
    variable "redshift_cluster_type" {
        type = "map"
    
      default = {
        development = "single-node"
        production  = "multi-node"
      }
    }
    
    variable "redshift_node" {
        type = "map"
    
      default = {
        development = "1"
        production  = "2"
      }
    }    
    
    resource "aws_redshift_cluster" "****" {
      cluster_identifier           = "abc-${var.env}"
      node_type                    = "${var.node_type}"
      cluster_type                 = "${var.redshift_cluster_type[var.env]}"
      number_of_nodes              = "${var.redshift_node[var.env]}"
    }
    

    有时我很懒,就这样做

    resource "aws_redshift_cluster" "****" {
      cluster_identifier           = "abc-${var.env}"
      node_type                    = "${var.node_type}"
      cluster_type                 = "${var.env == "production" ? "multi_node" : "single_node" }"
      number_of_nodes              = "${var.env == "production" ? 2 : 1 }"
    }
    

    【讨论】:

    • 我们可以使用空值吗?例如 - 我们只希望为 prod 和 dev 提供一个空集群 snapshot_identifier = "${var.env == "production" ? "xxxx" : " " }" @BMW
    • 是的,这是可能的,您必须将 null 作为您的条件中的值:snapshot_identifier = var.env == "production" ? “xxxx”:空
    猜你喜欢
    • 2020-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多