Skip to content

Commit 4300fbd

Browse files
committed
add terratest and terraform pipeline
1 parent dc44b20 commit 4300fbd

File tree

4 files changed

+111
-15
lines changed

4 files changed

+111
-15
lines changed

Diff for: .github/workflows/terraform.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: 'Terraform GitHub Actions'
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
7+
jobs:
8+
terraform:
9+
name: 'Terraform'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 'Checkout'
13+
uses: actions/checkout@master
14+
15+
- name: Configure AWS Credentials
16+
uses: clouddrove/configure-aws-credentials@v1
17+
with:
18+
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }}
19+
aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }}
20+
aws-region: us-east-2
21+
22+
- name: 'Terraform Format'
23+
uses: 'clouddrove/[email protected]'
24+
with:
25+
actions_subcommand: 'fmt'
26+
27+
- name: 'Terraform init'
28+
uses: 'clouddrove/[email protected]'
29+
with:
30+
actions_subcommand: 'init'
31+
tf_actions_working_dir: ./_example/basic
32+
33+
- name: 'Terraform validate'
34+
uses: 'clouddrove/[email protected]'
35+
with:
36+
actions_subcommand: 'validate'
37+
tf_actions_working_dir: ./_example/basic
38+
39+
- name: 'Terraform plan'
40+
uses: 'clouddrove/[email protected]'
41+
with:
42+
actions_subcommand: 'plan'
43+
tf_actions_working_dir: ./_example/basic
44+
45+
- name: 'Slack Notification'
46+
uses: clouddrove/action-slack@v2
47+
with:
48+
status: ${{ job.status }}
49+
fields: repo,author
50+
author_name: 'CloudDrove'
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
53+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required
54+
if: always()

Diff for: .github/workflows/terratest.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: 'Terratest GitHub Actions'
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
types: [labeled]
7+
8+
jobs:
9+
terraform:
10+
name: 'Terraform'
11+
runs-on: ubuntu-latest
12+
steps:
13+
14+
- name: 'Checkout'
15+
uses: actions/checkout@master
16+
17+
- name: Configure AWS Credentials
18+
uses: clouddrove/configure-aws-credentials@v1
19+
with:
20+
aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }}
21+
aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }}
22+
aws-region: us-east-2
23+
24+
- name: 'Terratest'
25+
if: ${{ github.event.label.name == 'terratest' }}
26+
uses: 'clouddrove/[email protected]'
27+
with:
28+
actions_subcommand: 'terratest'
29+
tf_actions_working_dir: '_test/basic'
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: 'Slack Notification'
34+
uses: clouddrove/action-slack@v2
35+
with:
36+
status: ${{ job.status }}
37+
fields: repo,author
38+
author_name: 'CloudDrove'
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required
41+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required
42+
if: always()

Diff for: _example/basic/example.tf

+13-13
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,34 @@ module "api-gateway" {
1111
enabled = true
1212

1313
# Api Gateway Resource
14-
path_parts = ["mytestresource", "mytestresource1"]
14+
path_parts = ["mytestresource"]
1515

1616
# Api Gateway Method
1717
method_enabled = true
18-
http_methods = ["GET", "GET"]
18+
http_methods = ["GET"]
1919

2020
# Api Gateway Integration
21-
integration_types = ["MOCK", "AWS_PROXY"]
22-
integration_http_methods = ["POST", "POST"]
23-
uri = ["", "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:xxxxxxxxxxxx:function:test/invocations"]
21+
integration_types = ["MOCK"]
22+
integration_http_methods = ["POST"]
23+
uri = [""]
2424
integration_request_parameters = [{
2525
"integration.request.header.X-Authorization" = "'static'"
26-
}, {}]
26+
}]
2727
request_templates = [{
2828
"application/xml" = <<EOF
2929
{
3030
"body" : $input.json('$')
3131
}
3232
EOF
33-
}, {}]
33+
}]
3434

3535
# Api Gateway Method Response
36-
status_codes = [200, 200]
37-
response_models = [{ "application/json" = "Empty" }, {}]
38-
response_parameters = [{ "method.response.header.X-Some-Header" = true }, {}]
36+
status_codes = [200]
37+
response_models = [{ "application/json" = "Empty" }]
38+
response_parameters = [{ "method.response.header.X-Some-Header" = true }]
3939

4040
# Api Gateway Integration Response
41-
integration_response_parameters = [{ "method.response.header.X-Some-Header" = "integration.response.header.X-Some-Other-Header" }, {}]
41+
integration_response_parameters = [{ "method.response.header.X-Some-Header" = "integration.response.header.X-Some-Other-Header" }]
4242
response_templates = [{
4343
"application/xml" = <<EOF
4444
#set($inputRoot = $input.path('$'))
@@ -47,13 +47,13 @@ EOF
4747
$inputRoot.body
4848
</message>
4949
EOF
50-
}, {}]
50+
}]
5151

5252
# Api Gateway Deployment
5353
deployment_enabled = true
5454
stage_name = "deploy"
5555

5656
# Api Gateway Stage
5757
stage_enabled = true
58-
stage_names = ["qa", "dev"]
58+
stage_names = ["qa"]
5959
}

Diff for: main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# for resources. You can use terraform-labels to implement a strict naming
77
# convention.
88
module "labels" {
9-
source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.12.0"
9+
source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.13.0"
1010

1111
name = var.name
1212
application = var.application
@@ -16,7 +16,7 @@ module "labels" {
1616
}
1717

1818
# Module : Api Gateway
19-
# Description : Terraform module to create Api Gateway resource on AWS for creating api.
19+
# Description : Terraform module to create Api Gateway resource on AWS for creatng api.
2020
resource "aws_api_gateway_rest_api" "default" {
2121
count = var.enabled ? 1 : 0
2222

0 commit comments

Comments
 (0)