-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
130 lines (114 loc) · 3.54 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
terraform {
backend "atlas" {
name = "shiftwise-amn/terraform-test"
}
}
provider "aws" {
region = "us-west-2"
}
variable git_token { default = "" }
resource "aws_iam_role" "ci_lambda_role" {
name = "CiLambdaRole"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_lambda_function" "ci_update" {
filename = "ci_update/ci_update.zip"
description = "Updates CI VPC with latest tags from Develop"
function_name = "CI_Update"
role = "${aws_iam_role.ci_lambda_role.arn}"
handler = "index.handler"
source_code_hash = "${base64sha256(file("ci_update/ci_update.zip"))}"
runtime = "nodejs6.10"
memory_size = "512"
timeout = "5"
publish = "true"
environment {
variables = {
GitHub_Token = "${var.git_token}"
}
}
}
resource "aws_lambda_function" "ci_intervals" {
filename = "ci_intervals/ci_intervals.zip"
description = "Kicks off CI functional tests"
function_name = "CI_Intervals"
role = "${aws_iam_role.ci_lambda_role.arn}"
handler = "index.handler"
source_code_hash = "${base64sha256(file("ci_intervals/ci_intervals.zip"))}"
runtime = "nodejs6.10"
memory_size = "512"
timeout = "10"
publish = "true"
environment {
variables = {
BRANCH = "develop"
REPO = "continuous-integration"
GITHUB = "${var.git_token}"
TARGET_ENVIRONMENT = "ci"
}
}
}
resource "aws_lambda_function" "rc_intervals" {
filename = "ci_intervals/ci_intervals.zip"
description = "Kicks off RC functional tests"
function_name = "RC_Intervals"
role = "${aws_iam_role.ci_lambda_role.arn}"
handler = "index.handler"
source_code_hash = "${base64sha256(file("ci_intervals/ci_intervals.zip"))}"
runtime = "nodejs6.10"
memory_size = "512"
timeout = "10"
publish = "true"
environment {
variables = {
BRANCH = "master"
REPO = "continuous-integration"
GITHUB = "${var.git_token}"
TARGET_ENVIRONMENT = "rc"
}
}
}
resource "aws_cloudwatch_event_rule" "CI_Intervals" {
name = "CI_Intervals"
description = "Start CI Test Run"
schedule_expression = "cron(0 3/6 ? * MON-FRI *)"
}
resource "aws_cloudwatch_event_rule" "CI_Update" {
name = "CI_Update"
description = "Update the CI environment"
schedule_expression = "cron(0 2/6 ? * MON-FRI *)"
}
resource "aws_cloudwatch_event_rule" "RC_Intervals" {
name = "RC_Intervals"
description = "Start RC Test Run"
schedule_expression = "cron(0 3/6 ? * MON-FRI *)"
}
resource "aws_cloudwatch_event_target" "ci_update_target" {
rule = "${aws_cloudwatch_event_rule.CI_Update.name}"
arn = "${aws_lambda_function.ci_update.arn}"
target_id = "CI_Update"
}
resource "aws_cloudwatch_event_target" "ci_intervals_target" {
rule = "${aws_cloudwatch_event_rule.CI_Intervals.name}"
arn = "${aws_lambda_function.ci_intervals.arn}"
target_id = "CI_Intervals"
}
resource "aws_cloudwatch_event_target" "rc_intervals_target" {
rule = "${aws_cloudwatch_event_rule.RC_Intervals.name}"
arn = "${aws_lambda_function.rc_intervals.arn}"
target_id = "RC_Intervals"
}