Skip to content

Commit 50f696f

Browse files
initial module commit (#1)
* initial module commit * Auto Format * skip_final_snapshot by default * Auto Format * IAM roles list respected, removed trailing dots for variables descriptions * Auto Format Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com>
1 parent 081c82e commit 50f696f

14 files changed

+737
-158
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*.tfstate.*
77
.terraform
88
.terraform.tfstate.lock.info
9+
**/.terraform.lock.hcl
910

1011
**/.idea
1112
**/*.iml

README.md

+81-24
Large diffs are not rendered by default.

docs/terraform.md

+81-24
Large diffs are not rendered by default.
+10-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
enabled = true
2+
13
region = "us-east-2"
24

3-
namespace = "eg"
5+
availability_zones = ["us-east-2a", "us-east-2b"]
46

5-
environment = "ue2"
7+
namespace = "eg"
68

79
stage = "test"
810

9-
name = "example"
11+
name = "redshift-cluster"
12+
13+
port = 5439
14+
15+
admin_user = "admin"
1016

17+
admin_password = "Admin_Password_1"

examples/complete/main.tf

+57-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,62 @@
1-
module "example" {
1+
provider "aws" {
2+
region = var.region
3+
}
4+
5+
module "vpc" {
6+
source = "cloudposse/vpc/aws"
7+
version = "0.21.1"
8+
9+
cidr_block = "172.19.0.0/16"
10+
11+
context = module.this.context
12+
}
13+
14+
module "subnet" {
15+
source = "cloudposse/dynamic-subnets/aws"
16+
version = "0.38.1"
17+
18+
availability_zones = var.availability_zones
19+
vpc_id = module.vpc.vpc_id
20+
igw_id = module.vpc.igw_id
21+
cidr_block = module.vpc.vpc_cidr_block
22+
nat_gateway_enabled = false
23+
nat_instance_enabled = false
24+
25+
context = module.this.context
26+
}
27+
28+
module "security_group" {
29+
source = "cloudposse/security-group/aws"
30+
version = "0.1.4"
31+
32+
vpc_id = module.vpc.vpc_id
33+
rules = [
34+
{
35+
type = "ingress"
36+
from_port = var.port
37+
to_port = var.port
38+
protocol = "all"
39+
cidr_blocks = ["0.0.0.0/0"]
40+
},
41+
{
42+
type = "egress"
43+
from_port = 0
44+
to_port = 0
45+
protocol = "all"
46+
cidr_blocks = ["0.0.0.0/0"]
47+
}
48+
]
49+
context = module.this.context
50+
}
51+
52+
module "redshift_cluster" {
253
source = "../.."
354

4-
example = var.example
55+
subnet_ids = module.subnet.private_subnet_ids
56+
vpc_security_groups = [module.vpc.vpc_default_security_group_id, module.security_group.id]
57+
58+
admin_user = var.admin_user
59+
admin_password = var.admin_password
560

661
context = module.this.context
762
}

examples/complete/outputs.tf

+98-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,104 @@
11
output "id" {
2-
description = "ID of the created example"
3-
value = module.example.id
2+
description = "The Redshift Cluster ID"
3+
value = module.redshift_cluster.id
44
}
55

6-
output "example" {
7-
description = "Output \"example\" from example module"
8-
value = module.example.example
6+
output "arn" {
7+
description = "Amazon Resource Name (ARN) of cluster"
8+
value = module.redshift_cluster.arn
99
}
1010

11-
output "random" {
12-
description = "Output \"random\" from example module"
13-
value = module.example.random
11+
output "cluster_identifier" {
12+
description = "The Cluster Identifier"
13+
value = module.redshift_cluster.cluster_identifier
14+
}
15+
16+
output "cluster_revision_number" {
17+
description = "The specific revision number of the database in the cluster"
18+
value = module.redshift_cluster.cluster_revision_number
19+
}
20+
21+
output "cluster_subnet_group_name" {
22+
description = "The name of a cluster subnet group to be associated with this cluster"
23+
value = module.redshift_cluster.cluster_subnet_group_name
24+
}
25+
26+
output "cluster_parameter_group_name" {
27+
description = "The name of the parameter group to be associated with this cluster"
28+
value = module.redshift_cluster.cluster_parameter_group_name
29+
}
30+
31+
output "port" {
32+
description = "The Port the cluster responds on"
33+
value = module.redshift_cluster.port
34+
}
35+
36+
output "dns_name" {
37+
description = "The DNS name of the cluster"
38+
value = module.redshift_cluster.dns_name
39+
}
40+
41+
output "vpc_security_group_ids" {
42+
description = "The VPC security group Ids associated with the cluster"
43+
value = module.redshift_cluster.vpc_security_group_ids
44+
}
45+
46+
output "cluster_security_groups" {
47+
description = "The security groups associated with the cluster"
48+
value = module.redshift_cluster.cluster_security_groups
49+
}
50+
51+
output "endpoint" {
52+
description = "The connection endpoint"
53+
value = module.redshift_cluster.endpoint
54+
}
55+
56+
output "database_name" {
57+
description = "The name of the default database in the Cluster"
58+
value = module.redshift_cluster.database_name
59+
}
60+
61+
output "node_type" {
62+
description = "The type of nodes in the cluster"
63+
value = module.redshift_cluster.node_type
64+
}
65+
66+
output "cluster_type" {
67+
description = "The cluster type"
68+
value = module.redshift_cluster.cluster_type
69+
}
70+
71+
output "redshift_subnet_group_arn" {
72+
description = "Amazon Resource Name (ARN) of the Redshift Subnet group name"
73+
value = module.redshift_cluster.redshift_subnet_group_arn
74+
}
75+
76+
output "redshift_subnet_group_id" {
77+
description = "The Redshift Subnet group name ID"
78+
value = module.redshift_cluster.redshift_subnet_group_id
79+
}
80+
81+
output "redshift_parameter_group_arn" {
82+
description = "Amazon Resource Name (ARN) of the Redshift parameter group"
83+
value = module.redshift_cluster.redshift_parameter_group_arn
84+
}
85+
86+
output "redshift_parameter_group_id" {
87+
description = "The Redshift parameter group name"
88+
value = module.redshift_cluster.redshift_parameter_group_id
89+
}
90+
91+
output "vpc_cidr" {
92+
value = module.vpc.vpc_cidr_block
93+
description = "VPC CIDR"
94+
}
95+
96+
output "public_subnet_cidrs" {
97+
value = module.subnet.public_subnet_cidrs
98+
description = "Public subnet CIDR blocks"
99+
}
100+
101+
output "private_subnet_cidrs" {
102+
value = module.subnet.private_subnet_cidrs
103+
description = "Private subnet CIDR blocks"
14104
}

examples/complete/variables.tf

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
variable "example" {
1+
variable "region" {
22
type = string
3-
description = "The value which will be passed to the example module"
3+
description = "AWS region"
4+
}
5+
6+
variable "port" {
7+
type = number
8+
default = 5439
9+
description = "The port number on which the cluster accepts incoming connections"
10+
}
11+
12+
variable "availability_zones" {
13+
type = list(string)
14+
}
15+
16+
variable "admin_user" {
17+
type = string
18+
default = "admin"
19+
description = "(Required unless a snapshot_identifier is provided) Username for the master DB user"
20+
}
21+
22+
variable "admin_password" {
23+
type = string
24+
description = "(Required unless a snapshot_identifier is provided) Password for the master DB user"
425
}

examples/complete/versions.tf

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ terraform {
22
required_version = ">= 0.12.26"
33

44
required_providers {
5-
local = {
6-
source = "hashicorp/local"
7-
version = ">= 1.2"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 2.0"
8+
}
9+
null = {
10+
source = "hashicorp/null"
11+
version = ">= 2.0"
812
}
913
}
1014
}

main.tf

+60-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
1-
resource "random_integer" "example" {
2-
count = module.this.enabled ? 1 : 0
1+
resource "aws_redshift_cluster" "default" {
2+
count = module.this.enabled ? 1 : 0
3+
cluster_identifier = var.cluster_identifier == "" ? module.this.id : var.cluster_identifier
4+
database_name = var.database_name
5+
master_username = var.admin_user
6+
master_password = var.admin_password
7+
node_type = var.node_type
8+
cluster_type = var.cluster_type
39

4-
min = 1
5-
max = 50000
6-
keepers = {
7-
example = var.example
10+
vpc_security_group_ids = var.vpc_security_groups
11+
cluster_subnet_group_name = join("", aws_redshift_subnet_group.default.*.id)
12+
availability_zone = var.availability_zone
13+
preferred_maintenance_window = var.preferred_maintenance_window
14+
15+
cluster_parameter_group_name = join("", aws_redshift_parameter_group.default.*.id)
16+
automated_snapshot_retention_period = var.automated_snapshot_retention_period
17+
port = var.port
18+
cluster_version = var.engine_version
19+
number_of_nodes = var.nodes
20+
publicly_accessible = var.publicly_accessible
21+
encrypted = var.encrypted
22+
enhanced_vpc_routing = var.enhanced_vpc_routing
23+
kms_key_id = var.kms_key_arn
24+
elastic_ip = var.elastic_ip
25+
skip_final_snapshot = var.skip_final_snapshot
26+
final_snapshot_identifier = var.final_snapshot_identifier
27+
snapshot_identifier = var.snapshot_identifier
28+
snapshot_cluster_identifier = var.snapshot_cluster_identifier
29+
owner_account = var.owner_account
30+
iam_roles = var.iam_roles
31+
32+
depends_on = [
33+
aws_redshift_subnet_group.default,
34+
aws_redshift_parameter_group.default
35+
]
36+
37+
logging {
38+
enable = var.logging
39+
bucket_name = var.logging_bucket_name
40+
s3_key_prefix = var.logging_s3_key_prefix
841
}
42+
43+
tags = module.this.tags
944
}
1045

11-
locals {
12-
example = format("%v %v", var.example, join("", random_integer.example[*].result))
46+
resource "aws_redshift_subnet_group" "default" {
47+
count = module.this.enabled ? 1 : 0
48+
name = module.this.id
49+
subnet_ids = var.subnet_ids
50+
description = "Allowed subnets for Redshift Subnet group"
51+
tags = module.this.tags
52+
}
53+
54+
resource "aws_redshift_parameter_group" "default" {
55+
name = module.this.id
56+
family = "redshift-1.0"
57+
58+
dynamic "parameter" {
59+
for_each = var.cluster_parameters
60+
content {
61+
name = parameter.value.name
62+
value = parameter.value.value
63+
}
64+
}
1365
}

0 commit comments

Comments
 (0)