如何使用Terraform仅为prod创建多节点红移群集

时间:2017-11-08 23:42:34

标签: amazon-redshift terraform

我有2个redshift cluster prod和dev,我正在使用相同的terraform模块。 我怎样才能为prod集群提供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

1 个答案:

答案 0 :(得分: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 }"
}