Skip to content
This repository was archived by the owner on Apr 18, 2020. It is now read-only.

Commit 0440470

Browse files
committed
Restructured project into submodules
1 parent c182604 commit 0440470

File tree

15 files changed

+467
-200
lines changed

15 files changed

+467
-200
lines changed

aws-cloudwatch/main.tf

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Copyright (c) 2017 Martin Donath <martin.donath@squidfunk.com>
2+
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to
5+
# deal in the Software without restriction, including without limitation the
6+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
# sell copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
# IN THE SOFTWARE.
20+
21+
# -----------------------------------------------------------------------------
22+
# Data: IAM
23+
# -----------------------------------------------------------------------------
24+
25+
# data.template_file.lambda_iam_policy.rendered
26+
data "template_file" "lambda_iam_policy" {
27+
template = "${file("${path.root}/aws-iam/policies/lambda.json")}"
28+
29+
vars {
30+
bucket = "${var.bucket}"
31+
}
32+
}
33+
34+
# -----------------------------------------------------------------------------
35+
# Resources: IAM
36+
# -----------------------------------------------------------------------------
37+
38+
# aws_iam_role.lambda
39+
resource "aws_iam_role" "lambda" {
40+
name = "${var.namespace}-lambda-cloudwatch"
41+
path = "/${var.namespace}/lambda/"
42+
43+
assume_role_policy = "${
44+
file("${path.root}/aws-iam/policies/assume-role/lambda.json")
45+
}"
46+
}
47+
48+
# aws_iam_policy.lambda
49+
resource "aws_iam_policy" "lambda" {
50+
name = "${var.namespace}-lambda-cloudwatch"
51+
path = "/${var.namespace}/lambda/"
52+
53+
policy = "${data.template_file.lambda_iam_policy.rendered}"
54+
}
55+
56+
# aws_iam_policy_attachment.lambda
57+
resource "aws_iam_policy_attachment" "lambda" {
58+
name = "${var.namespace}-lambda-cloudwatch"
59+
60+
policy_arn = "${aws_iam_policy.lambda.arn}"
61+
roles = ["${aws_iam_role.lambda.id}"]
62+
}
63+
64+
# -----------------------------------------------------------------------------
65+
# Resources: CloudWatch
66+
# -----------------------------------------------------------------------------
67+
68+
# aws_cloudwatch_event_rule.status
69+
resource "aws_cloudwatch_event_rule" "status" {
70+
name = "${var.namespace}-webhook-status"
71+
72+
event_pattern = "${
73+
file("${path.root}/aws-cloudwatch/rules/codebuild.json")
74+
}"
75+
}
76+
77+
# aws_cloudwatch_event_target.status
78+
resource "aws_cloudwatch_event_target" "status" {
79+
rule = "${aws_cloudwatch_event_rule.status.name}"
80+
arn = "${aws_lambda_function.status.arn}"
81+
}
82+
83+
# -----------------------------------------------------------------------------
84+
# Resources: Lambda
85+
# -----------------------------------------------------------------------------
86+
87+
# aws_lambda_function.status
88+
resource "aws_lambda_function" "status" {
89+
function_name = "${var.namespace}-webhook-status"
90+
role = "${aws_iam_role.lambda.arn}"
91+
runtime = "nodejs6.10"
92+
filename = "${path.root}/aws-lambda/dist/status.zip"
93+
handler = "index.default"
94+
timeout = 10
95+
96+
source_code_hash = "${
97+
base64sha256(file("${path.root}/aws-lambda/dist/status.zip"))
98+
}"
99+
100+
environment {
101+
variables = {
102+
GITHUB_OAUTH_TOKEN = "${var.github_oauth_token}"
103+
GITHUB_REPORTER = "${var.github_reporter}"
104+
CODEBUILD_BUCKET = "${var.bucket}"
105+
}
106+
}
107+
}
108+
109+
# aws_lambda_permission.status
110+
resource "aws_lambda_permission" "status" {
111+
statement_id = "AllowExecutionFromCloudWatch"
112+
action = "lambda:InvokeFunction"
113+
function_name = "${aws_lambda_function.status.arn}"
114+
principal = "events.amazonaws.com"
115+
source_arn = "${aws_cloudwatch_event_rule.status.arn}"
116+
}
File renamed without changes.

aws-cloudwatch/variables.tf

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright (c) 2017 Martin Donath <martin.donath@squidfunk.com>
2+
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to
5+
# deal in the Software without restriction, including without limitation the
6+
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7+
# sell copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19+
# IN THE SOFTWARE.
20+
21+
# -----------------------------------------------------------------------------
22+
# Variables: General
23+
# -----------------------------------------------------------------------------
24+
25+
# var.namespace
26+
variable "namespace" {
27+
description = "AWS resource namespace/prefix"
28+
}
29+
30+
# -----------------------------------------------------------------------------
31+
# Variables: GitHub
32+
# -----------------------------------------------------------------------------
33+
34+
# var.github_owner
35+
variable "github_owner" {
36+
description = "GitHub repository owner"
37+
}
38+
39+
# var.github_repository
40+
variable "github_repository" {
41+
description = "GitHub repository name"
42+
}
43+
44+
# var.github_oauth_token
45+
variable "github_oauth_token" {
46+
description = "GitHub OAuth token for repository access"
47+
}
48+
49+
# var.github_reporter
50+
variable "github_reporter" {
51+
description = "GitHub commit status reporter"
52+
}
53+
54+
# -----------------------------------------------------------------------------
55+
# Variables: S3
56+
# -----------------------------------------------------------------------------
57+
58+
# var.bucket
59+
variable "bucket" {
60+
description = "S3 bucket"
61+
}
File renamed without changes.

aws-lambda/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ node_modules:
3434

3535
# Build library for distribution
3636
dist: $(shell find src) .babelrc webpack.config.js
37-
$(shell npm bin)/cross-env NODE_ENV=production \
38-
$(shell npm bin)/webpack
37+
$(shell npm bin)/webpack --env.prod
3938

4039
# -----------------------------------------------------------------------------
4140
# Rules

aws-lambda/dist/push.zip

0 Bytes
Binary file not shown.

aws-lambda/dist/status.zip

0 Bytes
Binary file not shown.

aws-lambda/package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
{
2-
"name": "terraform-aws-github-ci",
2+
"name": "terraform-aws-github-ci-aws-lambda",
33
"version": "0.0.0",
4-
"description": "GitHub CI server using AWS CodeBuild",
5-
"keywords": [
6-
"aws",
7-
"codepipeline",
8-
"github",
9-
"terraform",
10-
"webhook"
11-
],
4+
"description": "A GitHub CI server using AWS CodeBuild",
5+
"keywords": [],
126
"homepage": "https://github.com/squidfunk/terraform-aws-github-ci/",
137
"bugs": {
148
"url": "https://github.com/squidfunk/terraform-aws-github-ci/",

aws-lambda/src/push.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const codebuild = new AWS.CodeBuild({ apiVersion: "2016-10-06" })
3737
/**
3838
* GitHub client
3939
*
40-
* @type {AWS.GitHub}
40+
* @type {GitHub}
4141
*/
4242
const github = new GitHub()
4343
if (process.env.GITHUB_OAUTH_TOKEN)

0 commit comments

Comments
 (0)