Skip to content

Commit 991488c

Browse files
authored
Merge pull request #8 from TerraHubCorp/dev
Refactor demo to use YAML instead of HCL
2 parents cc21859 + d9e03cc commit 991488c

File tree

27 files changed

+871
-270
lines changed

27 files changed

+871
-270
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
# Local .terraform directories
1+
# Local hidden directories
22
**/.terraform/*
3+
**/.backup/*
34

4-
# .tfstate files
5+
# Local .tfstate files
56
*.tfstate
67
*.tfstate.*
78

9+
# Zipped lambda function
10+
lambda/demo.zip

.terrahub.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
## project config
21
project:
32
name: demo-terraform-automation-aws
43
code: 7356626c
5-
include: ['.']
6-
exclude: ['**/.terraform/*', '**/node_modules/*']
7-
8-
## template config
4+
include:
5+
- .
6+
exclude:
7+
- '**/.terraform/*'
8+
- '**/node_modules/*'
9+
- '**/.git/**'
10+
terraform:
11+
varFile:
12+
- default.tfvars
13+
version: 0.11.11
914
template:
1015
locals:
1116
account_id: 123456789012
1217
region: us-east-1
1318
provider:
1419
aws:
1520
region: '${local.region}'
16-
allowed_account_ids: ['${local.account_id}']
17-
18-
## terraform config
19-
terraform:
20-
varFile: ['default.tfvars']
21-
version: 0.11.7
21+
allowed_account_ids:
22+
- '${local.account_id}'

README.md

Lines changed: 202 additions & 26 deletions
Large diffs are not rendered by default.

api_gateway_deployment/.terrahub.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
component:
2+
name: api_gateway_deployment
3+
mapping:
4+
- .
5+
dependsOn:
6+
- ../api_gateway_rest_api
7+
template:
8+
resource:
9+
aws_api_gateway_deployment:
10+
api_gateway_deployment:
11+
rest_api_id: '${data.aws_api_gateway_rest_api.api_gateway_deployment.id}'
12+
stage_name: demo
13+
description: Managed by TerraHub
14+
stage_description: >-
15+
${format("%s %s", var.api_gateway_deployment_stage_name,
16+
timestamp())}
17+
variable:
18+
api_gateway_deployment_stage_name:
19+
type: string
20+
output:
21+
id:
22+
value: '${aws_api_gateway_deployment.api_gateway_deployment.id}'
23+
thub_id:
24+
value: '${aws_api_gateway_deployment.api_gateway_deployment.id}'
25+
invoke_url:
26+
value: '${aws_api_gateway_deployment.api_gateway_deployment.invoke_url}'
27+
execution_arn:
28+
value: '${aws_api_gateway_deployment.api_gateway_deployment.execution_arn}'
29+
created_date:
30+
value: '${aws_api_gateway_deployment.api_gateway_deployment.created_date}'
31+
terraform:
32+
backend:
33+
local:
34+
path: /tmp/.terrahub/local_backend/api_gateway_deployment/terraform.tfstate
35+
data:
36+
aws_api_gateway_rest_api:
37+
api_gateway_deployment:
38+
name: DemoApi7356626c
39+
tfvars:
40+
api_gateway_deployment_stage_name: Deployed at

api_gateway_rest_api/.terrahub.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
component:
2+
name: api_gateway_rest_api
3+
mapping:
4+
- .
5+
dependsOn:
6+
- ../lambda
7+
template:
8+
resource:
9+
aws_api_gateway_rest_api:
10+
api_gateway_rest_api:
11+
name: DemoApi7356626c
12+
body: '${data.template_file.swagger.rendered}}'
13+
description: Managed by TerraHub
14+
output:
15+
id:
16+
value: '${aws_api_gateway_rest_api.api_gateway_rest_api.id}'
17+
thub_id:
18+
value: '${aws_api_gateway_rest_api.api_gateway_rest_api.id}'
19+
root_resource_id:
20+
value: '${aws_api_gateway_rest_api.api_gateway_rest_api.root_resource_id}'
21+
execution_arn:
22+
value: '${aws_api_gateway_rest_api.api_gateway_rest_api.execution_arn}'
23+
endpoint_configuration:
24+
value: >-
25+
${aws_api_gateway_rest_api.api_gateway_rest_api.endpoint_configuration}
26+
created_date:
27+
value: '${aws_api_gateway_rest_api.api_gateway_rest_api.created_date}'
28+
terraform:
29+
backend:
30+
local:
31+
path: /tmp/.terrahub/local_backend/api_gateway_rest_api/terraform.tfstate
32+
data:
33+
template_file:
34+
swagger:
35+
template: '${file("${local.project["path"]}/api_swagger.json.tpl")}'
36+
vars: '${map("account_id","${local.account_id}")}'

api_swagger.json.tpl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"version": "2019-02-27T17:25:48Z",
5+
"title": "DemoApi7356626c"
6+
},
7+
"schemes": [
8+
"https"
9+
],
10+
"paths": {
11+
"/": {
12+
"get": {
13+
"produces": [
14+
"application/json"
15+
],
16+
"responses": {
17+
"200": {
18+
"description": "200 response",
19+
"schema": {
20+
"$ref": "#/definitions/Empty"
21+
}
22+
}
23+
},
24+
"x-amazon-apigateway-integration": {
25+
"credentials": "arn:aws:iam::${account_id}:role/DemoAWSLambdaExecRole7356626c",
26+
"uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:${account_id}:function:DemoAWSLambda7356626c/invocations",
27+
"responses": {
28+
"default": {
29+
"statusCode": "200"
30+
}
31+
},
32+
"passthroughBehavior": "when_no_match",
33+
"httpMethod": "POST",
34+
"contentHandling": "CONVERT_TO_TEXT",
35+
"type": "aws"
36+
}
37+
}
38+
}
39+
},
40+
"definitions": {
41+
"Empty": {
42+
"type": "object",
43+
"title": "Empty Schema"
44+
}
45+
}
46+
}

demo.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.handler = async (event) => {
2+
// TODO implement
3+
const response = {
4+
statusCode: 200,
5+
body: JSON.stringify('Hello from Lambda!'),
6+
};
7+
return response;
8+
};

iam_assume_policy.json.tpl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Effect": "Allow",
6+
"Action": [
7+
"lambda:InvokeFunction"
8+
],
9+
"Resource": "arn:aws:lambda:us-east-1:${account_id}:function:*"
10+
},
11+
{
12+
"Effect": "Allow",
13+
"Action": "apigateway:*",
14+
"Resource": "arn:aws:apigateway:us-east-1:${account_id}:*"
15+
},
16+
{
17+
"Effect": "Allow",
18+
"Action": [
19+
"ec2:CreateNetworkInterface",
20+
"ec2:DescribeNetworkInterfaces",
21+
"ec2:DeleteNetworkInterface"
22+
],
23+
"Resource": "*"
24+
},
25+
{
26+
"Effect": "Allow",
27+
"Action": [
28+
"logs:CreateLogGroup",
29+
"logs:CreateLogStream",
30+
"logs:DescribeLogGroups",
31+
"logs:DescribeLogStreams",
32+
"logs:PutLogEvents",
33+
"logs:GetLogEvents",
34+
"logs:FilterLogEvents"
35+
],
36+
"Resource": "arn:aws:logs:*:${account_id}:*"
37+
},
38+
{
39+
"Effect": "Allow",
40+
"Action": "cloudwatch:setAlarmState",
41+
"Resource": "*"
42+
},
43+
{
44+
"Effect": "Allow",
45+
"Action": [
46+
"ec2:CreateNetworkInterface",
47+
"ec2:DescribeNetworkInterfaces",
48+
"ec2:DeleteNetworkInterface"
49+
],
50+
"Resource": "*"
51+
}
52+
]
53+
}

iam_group/.terrahub.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

iam_policy/.terrahub.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)