-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
60 lines (54 loc) · 1.63 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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.55.0"
}
}
required_version = ">=1.0.4"
}
provider "aws" {
region = var.aws_region
profile = var.aws_profile
}
resource "aws_iam_role" "redshift_role" {
name = "redshift_role"
assume_role_policy = jsonencode({
"Statement" : [{
"Action" : "sts:AssumeRole",
"Effect" : "Allow",
"Principal" : { "Service" : "redshift.amazonaws.com" }
}],
"Version" : "2012-10-17"
})
}
resource "aws_iam_role_policy_attachment" "attach_s3_redshift_role" {
role = aws_iam_role.redshift_role.name
policy_arn = "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
}
resource "aws_redshift_cluster" "default" {
cluster_identifier = var.rs_cluster_identifier
database_name = var.rs_database_name
master_username = var.rs_master_username
master_password = var.rs_master_password
node_type = var.rs_nodetype
number_of_nodes = var.rs_number_of_nodes
cluster_type = var.rs_number_of_nodes > 1 ? "multi-node" : "single-node"
skip_final_snapshot = true
iam_roles = [aws_iam_role.redshift_role.arn]
publicly_accessible = var.rs_publicly_accessible
port = var.rs_port
}
resource "aws_vpc" "redshift_vpc" {
cidr_block = var.vpc_cidr
instance_tenancy = "default"
}
resource "aws_default_security_group" "redshift_security_group" {
vpc_id = aws_vpc.redshift_vpc.id
ingress {
from_port = var.rs_port
to_port = var.rs_port
protocol = "tcp"
cidr_blocks = [for ip, pem in var.ip_permission_group_map : "${ip}/${pem}"]
}
}