Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 4f99b88

Browse files
INFRA-8575 Create repo for the AWS POC deployment scripts in Terraform + first test with GitLab CI
1 parent 3e47cba commit 4f99b88

7 files changed

+215
-85
lines changed

.gitlab-ci.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Based on the template at:
2+
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
3+
4+
include:
5+
- local: templates/tf/Base.latest.gitlab-ci.yml
6+
# See https://gitlab.com/gitlab-org/gitlab/blob/master/lib/gitlab/ci/templates/Terraform/
7+
8+
stages:
9+
- validate
10+
- test
11+
- build
12+
- deploy
13+
- cleanup
14+
15+
fmt:
16+
extends: .terraform:fmt
17+
needs: []
18+
19+
validate:
20+
extends: .terraform:validate
21+
needs: []
22+
23+
build:
24+
extends: .terraform:build
25+
26+
deploy:
27+
extends: .terraform:deploy
28+
dependencies:
29+
- build
30+
environment:
31+
name: $TF_STATE_NAME
32+
33+
tfsec:
34+
image: aquasec/tfsec
35+
stage: validate
36+
script:
37+
- cd "${TF_ROOT}"
38+
- /usr/bin/tfsec
39+
allow_failure: false

README.md

+5-85
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,12 @@
11
# deployment
2+
# AWS POC Deployment
23

4+
Deployment of the SBO POC in AWS with Terraform.
35

6+
# GitLab CI
47

5-
## Getting started
8+
Based on: https://bbpgitlab.epfl.ch/help/user/infrastructure/iac/terraform_state
69

7-
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
10+
Added: https://github.com/aquasecurity/tfsec
811

9-
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
1012

11-
## Add your files
12-
13-
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14-
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
15-
16-
```
17-
cd existing_repo
18-
git remote add origin https://bbpgitlab.epfl.ch/cs/cloud/aws/deployment.git
19-
git branch -M main
20-
git push -uf origin main
21-
```
22-
23-
## Integrate with your tools
24-
25-
- [ ] [Set up project integrations](https://bbpgitlab.epfl.ch/cs/cloud/aws/deployment/-/settings/integrations)
26-
27-
## Collaborate with your team
28-
29-
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30-
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31-
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32-
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33-
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34-
35-
## Test and Deploy
36-
37-
Use the built-in continuous integration in GitLab.
38-
39-
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40-
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41-
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42-
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43-
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44-
45-
***
46-
47-
# Editing this README
48-
49-
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
50-
51-
## Suggestions for a good README
52-
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
53-
54-
## Name
55-
Choose a self-explaining name for your project.
56-
57-
## Description
58-
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
59-
60-
## Badges
61-
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
62-
63-
## Visuals
64-
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
65-
66-
## Installation
67-
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
68-
69-
## Usage
70-
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
71-
72-
## Support
73-
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
74-
75-
## Roadmap
76-
If you have ideas for releases in the future, it is a good idea to list them in the README.
77-
78-
## Contributing
79-
State if you are open to contributions and what your requirements are for accepting them.
80-
81-
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
82-
83-
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
84-
85-
## Authors and acknowledgment
86-
Show your appreciation to those who have contributed to the project.
87-
88-
## License
89-
For open source projects, say how it is licensed.
90-
91-
## Project status
92-
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

gitlab-config.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
terraform {
2+
backend "http" {
3+
}
4+
}

templates/tf/Base.gitlab-ci.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Terraform/Base
2+
#
3+
# The purpose of this template is to provide flexibility to the user so
4+
# they are able to only include the jobs that they find interesting.
5+
#
6+
# Therefore, this template is not supposed to run any jobs. The idea is to only
7+
# create hidden jobs. See: https://docs.gitlab.com/ee/ci/jobs/#hide-jobs
8+
#
9+
# There is a more opinionated template which we suggest the users to abide,
10+
# which is the lib/gitlab/ci/templates/Terraform.gitlab-ci.yml
11+
image:
12+
name: "$CI_TEMPLATE_REGISTRY_HOST/gitlab-org/terraform-images/releases/1.1:v0.43.0"
13+
14+
variables:
15+
TF_ROOT: ${CI_PROJECT_DIR} # The relative path to the root directory of the Terraform project
16+
TF_STATE_NAME: default # The name of the state file used by the GitLab Managed Terraform state backend
17+
18+
cache:
19+
key: "${TF_ROOT}"
20+
paths:
21+
- ${TF_ROOT}/.terraform/
22+
23+
.terraform:fmt: &terraform_fmt
24+
stage: validate
25+
script:
26+
- cd "${TF_ROOT}"
27+
- gitlab-terraform fmt
28+
allow_failure: true
29+
30+
.terraform:validate: &terraform_validate
31+
stage: validate
32+
script:
33+
- cd "${TF_ROOT}"
34+
- gitlab-terraform validate
35+
36+
.terraform:build: &terraform_build
37+
stage: build
38+
script:
39+
- cd "${TF_ROOT}"
40+
- gitlab-terraform plan
41+
- gitlab-terraform plan-json
42+
resource_group: ${TF_STATE_NAME}
43+
artifacts:
44+
paths:
45+
- ${TF_ROOT}/plan.cache
46+
reports:
47+
terraform: ${TF_ROOT}/plan.json
48+
49+
.terraform:deploy: &terraform_deploy
50+
stage: deploy
51+
script:
52+
- cd "${TF_ROOT}"
53+
- gitlab-terraform apply
54+
resource_group: ${TF_STATE_NAME}
55+
rules:
56+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
57+
when: manual
58+
59+
.terraform:destroy: &terraform_destroy
60+
stage: cleanup
61+
script:
62+
- cd "${TF_ROOT}"
63+
- gitlab-terraform destroy
64+
resource_group: ${TF_STATE_NAME}
65+
when: manual
66+
+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Terraform/Base.latest
2+
#
3+
# The purpose of this template is to provide flexibility to the user so
4+
# they are able to only include the jobs that they find interesting.
5+
#
6+
# Therefore, this template is not supposed to run any jobs. The idea is to only
7+
# create hidden jobs. See: https://docs.gitlab.com/ee/ci/yaml/#hide-jobs
8+
#
9+
# There is a more opinionated template which we suggest the users to abide,
10+
# which is the lib/gitlab/ci/templates/Terraform.latest.gitlab-ci.yml
11+
12+
image:
13+
name: "$CI_TEMPLATE_REGISTRY_HOST/gitlab-org/terraform-images/stable:latest"
14+
15+
variables:
16+
TF_ROOT: ${CI_PROJECT_DIR} # The relative path to the root directory of the Terraform project
17+
TF_STATE_NAME: default # The name of the state file used by the GitLab Managed Terraform state backend
18+
19+
cache:
20+
key: "${TF_ROOT}"
21+
paths:
22+
- ${TF_ROOT}/.terraform/
23+
24+
.terraform:fmt: &terraform_fmt
25+
stage: validate
26+
script:
27+
- cd "${TF_ROOT}"
28+
- gitlab-terraform fmt
29+
allow_failure: true
30+
rules:
31+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
32+
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
33+
when: never
34+
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
35+
36+
.terraform:validate: &terraform_validate
37+
stage: validate
38+
script:
39+
- cd "${TF_ROOT}"
40+
- gitlab-terraform validate
41+
rules:
42+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
43+
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
44+
when: never
45+
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
46+
47+
.terraform:build: &terraform_build
48+
stage: build
49+
script:
50+
- cd "${TF_ROOT}"
51+
- gitlab-terraform plan
52+
- gitlab-terraform plan-json
53+
resource_group: ${TF_STATE_NAME}
54+
artifacts:
55+
paths:
56+
- ${TF_ROOT}/plan.cache
57+
reports:
58+
terraform: ${TF_ROOT}/plan.json
59+
rules:
60+
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
61+
- if: $CI_OPEN_MERGE_REQUESTS # Don't add it to a *branch* pipeline if it's already in a merge request pipeline.
62+
when: never
63+
- if: $CI_COMMIT_BRANCH # If there's no open merge request, add it to a *branch* pipeline instead.
64+
65+
.terraform:deploy: &terraform_deploy
66+
stage: deploy
67+
script:
68+
- cd "${TF_ROOT}"
69+
- gitlab-terraform apply
70+
resource_group: ${TF_STATE_NAME}
71+
rules:
72+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $TF_AUTO_DEPLOY == "true"
73+
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
74+
when: manual
75+
76+
.terraform:destroy: &terraform_destroy
77+
stage: cleanup
78+
script:
79+
- cd "${TF_ROOT}"
80+
- gitlab-terraform destroy
81+
resource_group: ${TF_STATE_NAME}
82+
when: manual
83+

terraform-config.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 4.16"
6+
}
7+
}
8+
9+
required_version = ">= 1.2.0"
10+
}
11+
12+
provider "aws" {
13+
region = var.aws_region
14+
}

variables-common.tf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
variable "aws_region" {
2+
type = string
3+
default = "us-east-1"
4+
}

0 commit comments

Comments
 (0)