Skip to content

Commit 3729569

Browse files
committed
Terraform AWS GitLab OIDC module
0 parents  commit 3729569

20 files changed

+982
-0
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
name: 🐛 Bug Report
3+
about: If something isn't working as expected.
4+
5+
---
6+
7+
## Bug Report
8+
9+
### Steps to Reproduce:
10+
1. ...step 1 description...
11+
2. ...step 2 description...
12+
3. ...step 3 description...
13+
14+
### Expected Result:
15+
...description of what you expected to see...
16+
17+
### Actual Result:
18+
...what actually happened, including full exceptions (please include the entire stack trace, including "caused by" entries), log entries, screen shots etc. where appropriate...
19+
20+
### Environment:
21+
...version and build of the project, OS and runtime versions, virtualised environment (if any), etc. ...
22+
23+
### Additional Context:
24+
...add any other context about the problem here. If applicable, add screenshots to help explain...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: 🚀 Feature Request
3+
about: I have a suggestion and may want to implement it!
4+
5+
---
6+
7+
## Feature Request
8+
9+
### Description of Problem:
10+
...what is the *problem* you trying to solve that the project doesn't currently solve?
11+
12+
...please resist the temptation to describe your request in terms of a solution. Job Story form ("When [triggering condition], I want to [motivation/goal], so I can [outcome].") can help ensure you're expressing a problem statement.
13+
14+
### Potential Solutions:
15+
...clearly and concisely describe what you want to happen. Add any considered drawbacks.
16+
17+
... if you've considered alternatives, clearly and concisely describe those too.

.github/dependabot.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gitlab-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
reviewers:
8+
- "saidsef"
9+
pull-request-branch-name:
10+
separator: "-"
11+
- package-ecosystem: "terraform"
12+
directory: "/"
13+
schedule:
14+
interval: "weekly"
15+
reviewers:
16+
- "saidsef"
17+
pull-request-branch-name:
18+
separator: "-"

.github/workflows/ci.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
validate:
13+
name: Validate
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
- name: Setup Terraform
19+
uses: hashicorp/setup-terraform@v2
20+
with:
21+
terraform_version: 1.1.9
22+
- name: Initialise with no backend
23+
run: terraform init -backend=false
24+
- name: Check formatting
25+
run: terraform fmt -check -recursive
26+
- name: Validate the configuration
27+
run: terraform validate
28+
29+
tfsec:
30+
name: tfsec
31+
runs-on: ubuntu-latest
32+
needs: [validate]
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v3
36+
- name: tfsec
37+
uses: aquasecurity/tfsec-action@v1.0.2
38+
39+
caller-identity-check:
40+
if: ${{ gitlab.event_name == 'pull_request' }}
41+
name: Return the IAM user
42+
needs: [validate, tfsec]
43+
permissions:
44+
contents: read
45+
id-token: write
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Configure AWS credentials
49+
uses: aws-actions/configure-aws-credentials@v1
50+
with:
51+
aws-region: ${{ secrets.AWS_REGION }}
52+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/gitlab-runner
53+
- run: |
54+
aws sts get-caller-identity
55+
56+
auto-approve:
57+
if: ${{ gitlab.event_name == 'pull_request' }}
58+
runs-on: ubuntu-latest
59+
needs: [validate, tfsec, caller-identity-check]
60+
steps:
61+
- name: Auto Approve PR
62+
uses: actions/gitlab-script@v6
63+
with:
64+
script: |
65+
gitlab.rest.pulls.createReview({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
pull_number: context.issue.number,
69+
event: "APPROVE"
70+
})

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**/.terraform/*
2+
*.tfstate
3+
*.tfstate.*
4+
*_override.tf
5+
*_override.tf.json
6+
.terraform.lock.hcl
7+
.terraformrc
8+
.tfsec/
9+
crash.log
10+
override.tf
11+
override.tf.json
12+
terraform.rc

.gitlab-ci.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
image:
2+
name: amazon/aws-cli:latest
3+
entrypoint:
4+
- "/usr/bin/env"
5+
6+
variables:
7+
TF_LOG_PATH: ./terraform.log
8+
TF_DATA_DIR: ./.terraform
9+
ROLE_ARN: "arn:aws:iam::$SECRET_AWS_ACCOUNT_ID:role/gitlab-runner"
10+
AWS_REGION: "$SECRET_AWS_REGION"
11+
12+
stages:
13+
- validate
14+
- aws-test
15+
16+
.assume-role:
17+
before_script:
18+
- >
19+
STS=($(aws sts assume-role-with-web-identity
20+
--role-arn $ROLE_ARN
21+
--role-session-name "GitLabRunner-${CI_PROJECT_ID}-${CI_PIPELINE_ID}"
22+
--web-identity-token $CI_JOB_JWT_V2
23+
--duration-seconds 3600
24+
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
25+
--output text))
26+
- export AWS_ACCESS_KEY_ID="${STS[0]}"
27+
- export AWS_SECRET_ACCESS_KEY="${STS[1]}"
28+
- export AWS_SESSION_TOKEN="${STS[2]}"
29+
30+
validate:
31+
stage: validate
32+
needs: []
33+
image:
34+
name: hashicorp/terraform:1.1.9
35+
entrypoint:
36+
- "/usr/bin/env"
37+
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
38+
interruptible: true
39+
script:
40+
- terraform init -backend=false
41+
- terraform fmt -check -recursive
42+
- terraform validate
43+
44+
aws:
45+
stage: aws-test
46+
needs: [validate]
47+
extends: .assume-role
48+
script:
49+
- aws sts get-caller-identity

CONTRIBUTING.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Contributing
2+
3+
When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.
4+
5+
Please note we have a code of conduct, please follow it in all your interactions with the project.
6+
7+
## Pull Request Process
8+
9+
1. Ensure any install or build dependencies are removed before the end of the layer when doing a build.
10+
2. Update the README.md and/or TERRAFORM.md with details of changes to the interface, this includes new environment variables, useful file locations and parameters.
11+
3. Increase the version numbers is managed by the GitLab Actions CI workflow `tagging.yml`
12+
4. You may merge the Pull Request in once you have the sign-off of from the project team, or if you do not have permission to do that, you may request a reviewer to merge it for you.
13+
14+
## Code of Conduct
15+
16+
### Our Pledge
17+
18+
In the interest of fostering an open and welcoming environment, we as
19+
contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
20+
21+
### Our Standards
22+
23+
Examples of behavior that contributes to creating a positive environment include:
24+
25+
* Using welcoming and inclusive language
26+
* Being respectful of differing viewpoints and experiences
27+
* Gracefully accepting constructive criticism
28+
* Focusing on what is best for the community
29+
* Showing empathy towards other community members
30+
31+
Examples of unacceptable behavior by participants include:
32+
33+
* The use of sexualized language or imagery and unwelcome sexual attention or
34+
advances
35+
* Trolling, insulting/derogatory comments, and personal or political attacks
36+
* Public or private harassment
37+
* Publishing others' private information, such as a physical or electronic
38+
address, without explicit permission
39+
* Other conduct which could reasonably be considered inappropriate in a
40+
professional setting
41+
42+
### Our Responsibilities
43+
44+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
45+
46+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
47+
48+
### Scope
49+
50+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
51+
52+
### Enforcement
53+
54+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
55+
56+
Further details of specific enforcement policies may be posted separately.
57+
58+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
59+
60+
### Attribution
61+
62+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
63+
64+
[homepage]: http://contributor-covenant.org
65+
[version]: http://contributor-covenant.org/version/1/4/

0 commit comments

Comments
 (0)