forked from terraform-aws-modules/terraform-aws-redshift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
74 lines (57 loc) · 2.7 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
locals {
redshift_subnet_group_name = "${coalesce(var.redshift_subnet_group_name, element(concat(aws_redshift_subnet_group.this.*.name, list("")), 0))}"
enable_create_redshift_subnet_group = "${var.redshift_subnet_group_name == "" ? 1 : 0}"
parameter_group_name = "${coalesce(var.parameter_group_name, element(concat(aws_redshift_parameter_group.this.*.id, list("")), 0))}"
enable_create_redshift_parameter_group = "${var.parameter_group_name == "" ? 0 : 1}"
}
resource "aws_redshift_cluster" "this" {
cluster_identifier = "${var.cluster_identifier}"
cluster_version = "${var.cluster_version}"
node_type = "${var.cluster_node_type}"
number_of_nodes = "${var.cluster_number_of_nodes}"
cluster_type = "${var.cluster_number_of_nodes > 1 ? "multi-node" : "single-node" }"
database_name = "${var.cluster_database_name}"
master_username = "${var.cluster_master_username}"
master_password = "${var.cluster_master_password}"
port = "${var.cluster_port}"
vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
cluster_subnet_group_name = "${local.redshift_subnet_group_name}"
cluster_parameter_group_name = "${local.parameter_group_name}"
publicly_accessible = "${var.publicly_accessible}"
# Snapshots and backups
final_snapshot_identifier = "${var.final_snapshot_identifier}"
skip_final_snapshot = "${var.skip_final_snapshot}"
automated_snapshot_retention_period = "${var.automated_snapshot_retention_period }"
preferred_maintenance_window = "${var.preferred_maintenance_window}"
allow_version_upgrade = "${var.allow_version_upgrade}"
# IAM Roles
iam_roles = ["${var.cluster_iam_roles}"]
# Encryption
encrypted = "${var.encrypted}"
kms_key_id = "${var.kms_key_id}"
# Enhanced VPC routing
enhanced_vpc_routing = "${var.enhanced_vpc_routing}"
# Logging
logging {
enable = "${var.enable_logging}"
bucket_name = "${var.logging_bucket_name}"
s3_key_prefix = "${var.logging_s3_key_prefix}"
}
tags = "${var.tags}"
}
resource "aws_redshift_parameter_group" "this" {
count = "${local.enable_create_redshift_parameter_group}"
name = "${var.cluster_identifier}-${replace(var.cluster_parameter_group, ".", "-")}-custom-params"
family = "${var.cluster_parameter_group}"
parameter {
name = "wlm_json_configuration"
value = "${var.wlm_json_configuration}"
}
}
resource "aws_redshift_subnet_group" "this" {
count = "${local.enable_create_redshift_subnet_group}"
name = "${var.cluster_identifier}"
description = "Redshift subnet group of ${var.cluster_identifier}"
subnet_ids = ["${var.subnets}"]
tags = "${var.tags}"
}