@@ -6,14 +6,94 @@ resource "aws_kms_key" "scheduler" {
66 deletion_window_in_days = 7
77}
88
9+ resource "aws_vpc" "redshift_vpc" {
10+ cidr_block = " 10.0.0.0/16"
11+ tags = {
12+ Name = " redshift-vpc-${ random_pet . suffix . id } "
13+ }
14+ }
15+
16+ resource "aws_internet_gateway" "redshift_igw" {
17+ vpc_id = aws_vpc. redshift_vpc . id
18+ tags = {
19+ Name = " redshift-igw-${ random_pet . suffix . id } "
20+ }
21+ }
22+
23+ resource "aws_route_table" "redshift_route_table" {
24+ vpc_id = aws_vpc. redshift_vpc . id
25+
26+ route {
27+ cidr_block = " 0.0.0.0/0"
28+ gateway_id = aws_internet_gateway. redshift_igw . id
29+ }
30+
31+ tags = {
32+ Name = " redshift-rt-${ random_pet . suffix . id } "
33+ }
34+ }
35+
36+ resource "aws_route_table_association" "redshift_rt_assoc_1" {
37+ subnet_id = aws_subnet. redshift_subnet_1 . id
38+ route_table_id = aws_route_table. redshift_route_table . id
39+ }
40+
41+ resource "aws_route_table_association" "redshift_rt_assoc_2" {
42+ subnet_id = aws_subnet. redshift_subnet_2 . id
43+ route_table_id = aws_route_table. redshift_route_table . id
44+ }
45+
46+ resource "aws_subnet" "redshift_subnet_1" {
47+ vpc_id = aws_vpc. redshift_vpc . id
48+ cidr_block = " 10.0.1.0/24"
49+ availability_zone = " eu-west-1a"
50+ map_public_ip_on_launch = true
51+ }
52+
53+ resource "aws_subnet" "redshift_subnet_2" {
54+ vpc_id = aws_vpc. redshift_vpc . id
55+ cidr_block = " 10.0.2.0/24"
56+ availability_zone = " eu-west-1b"
57+ map_public_ip_on_launch = true
58+ }
59+
60+ resource "aws_redshift_subnet_group" "redshift_subnet_group" {
61+ name = " redshift-subnet-group-${ random_pet . suffix . id } "
62+ subnet_ids = [aws_subnet . redshift_subnet_1 . id , aws_subnet . redshift_subnet_2 . id ]
63+ }
64+
65+ resource "aws_security_group" "redshift_sg" {
66+ name = " redshift-sg-${ random_pet . suffix . id } "
67+ description = " Security group for Redshift clusters"
68+ vpc_id = aws_vpc. redshift_vpc . id
69+
70+ ingress {
71+ from_port = 5439
72+ to_port = 5439
73+ protocol = " tcp"
74+ cidr_blocks = [" 0.0.0.0/0" ]
75+ description = " Allow Redshift access"
76+ }
77+
78+ egress {
79+ from_port = 0
80+ to_port = 0
81+ protocol = " -1"
82+ cidr_blocks = [" 0.0.0.0/0" ]
83+ }
84+ }
85+
986resource "aws_redshift_cluster" "scheduled" {
10- cluster_identifier = " test-to-stop-${ random_pet . suffix . id } "
11- database_name = " mydb"
12- master_username = " exampleuser"
13- master_password = " Mustbe8characters"
14- node_type = " dc2.large"
15- cluster_type = " single-node"
16- skip_final_snapshot = true
87+ cluster_identifier = " test-to-stop-${ random_pet . suffix . id } "
88+ database_name = " mydb"
89+ master_username = " exampleuser"
90+ master_password = " Mustbe8characters"
91+ node_type = " dc2.large"
92+ cluster_type = " single-node"
93+ publicly_accessible = false
94+ skip_final_snapshot = true
95+ cluster_subnet_group_name = aws_redshift_subnet_group. redshift_subnet_group . name
96+ vpc_security_group_ids = [aws_security_group . redshift_sg . id ]
1797
1898 tags = {
1999 tostop = " true"
@@ -26,13 +106,16 @@ resource "aws_redshift_cluster_snapshot" "scheduled" {
26106}
27107
28108resource "aws_redshift_cluster" "not_scheduled" {
29- cluster_identifier = " test-not-to-stop-${ random_pet . suffix . id } "
30- database_name = " mydb"
31- master_username = " exampleuser"
32- master_password = " Mustbe8characters"
33- node_type = " dc2.large"
34- cluster_type = " single-node"
35- skip_final_snapshot = true
109+ cluster_identifier = " test-not-to-stop-${ random_pet . suffix . id } "
110+ database_name = " mydb"
111+ master_username = " exampleuser"
112+ master_password = " Mustbe8characters"
113+ node_type = " dc2.large"
114+ cluster_type = " single-node"
115+ publicly_accessible = false
116+ skip_final_snapshot = true
117+ cluster_subnet_group_name = aws_redshift_subnet_group. redshift_subnet_group . name
118+ vpc_security_group_ids = [aws_security_group . redshift_sg . id ]
36119
37120 tags = {
38121 tostop = " false"
@@ -71,3 +154,12 @@ module "redshift-start-monday" {
71154 value = " true"
72155 }
73156}
157+
158+ module "test-execution" {
159+ count = var. test_mode ? 1 : 0
160+ source = " ./test-execution"
161+
162+ lambda_stop_name = module. redshift-stop-friday . scheduler_lambda_name
163+ redshift_cluster_to_scheduled_name = aws_redshift_cluster. scheduled . cluster_identifier
164+ redshift_cluster_not_scheduled_name = aws_redshift_cluster. not_scheduled . cluster_identifier
165+ }
0 commit comments