From dcc7271a1f40efc6b8a4cb3fffb99ea5854048ba Mon Sep 17 00:00:00 2001 From: Paula P Date: Wed, 6 Nov 2024 20:17:24 +0200 Subject: [PATCH 01/36] New file --- docs/git_guide.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/git_guide.md diff --git a/docs/git_guide.md b/docs/git_guide.md new file mode 100644 index 0000000..e69de29 From aed361217bd4caf9bf758cceb7bfee2e3ef3500c Mon Sep 17 00:00:00 2001 From: Paula P Date: Mon, 11 Nov 2024 19:47:27 +0200 Subject: [PATCH 02/36] deleted a number of files and folders in preparation for submitting the guides I worked on --- .gitignore | 1 + README.md | 90 ++++++++++++++++---------------- ansible/examples/ansible-ping.md | 0 docs/ansible_guide.md | 1 - docs/git_guide.md | 0 5 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 .gitignore delete mode 100644 ansible/examples/ansible-ping.md delete mode 100644 docs/ansible_guide.md delete mode 100644 docs/git_guide.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcb502a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.box diff --git a/README.md b/README.md index bad6537..c4edc7f 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,45 @@ -# sciitdevops - -## Project Overview -This repository serves as the base for the DevOps training program. It is designed to help participants advance towards the final goal of deploying a web site/app using all the tooling and practices covered in the DevOps training. - -## How to Use This Repository - -### Branching Strategy -- Each participant is encouraged to create their own branch from the main branch. -- Use your branch to work on exercises, projects, and any custom implementations related to the training. -- Regularly merge changes from the main branch to keep your branch up to date. - -### Repository Structure -- The repository will contain specific folders for different exercises and projects. -- **Terraform Code:** Store Terraform scripts for managing AWS and Azure resources in the `terraform/` directory. -- **CI/CD Configuration:** Store Jenkins, GitHub Actions, or other CI/CD configuration files in the `ci-cd/` directory. -- **Application Code:** Store the web application code in the `app/` directory. -- **Documentation:** Use the `docs/` directory for any additional documentation or notes. - -## Getting Started -1. **Clone the Repository:** - ```bash - git clone git@github.com:mihai-satmarean/sciitdevops.git - ``` - -2. **Create a Branch:** - ```bash - git checkout -b your-branch-name - ``` - -3. **Work on Exercises and Projects:** - - Use the provided directories to organize your work. - - Commit and push your changes regularly. - -4. **Collaborate and Review:** - - Collaborate with other participants by reviewing and discussing each other's work. - - Use pull requests to propose changes to the main branch. - -## Final Goal -The final goal of this training is to deploy a fully functional web site/app using the DevOps tools and practices learned throughout the course. This includes: -- Infrastructure provisioning with Terraform -- CI/CD pipelines with Jenkins or GitHub Actions -- Application deployment and monitoring - -By following this structure and utilizing the repository, participants will gain hands-on experience and work towards achieving the final goal of the training. \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ansible/examples/ansible-ping.md b/ansible/examples/ansible-ping.md deleted file mode 100644 index e69de29..0000000 diff --git a/docs/ansible_guide.md b/docs/ansible_guide.md deleted file mode 100644 index 9d6011a..0000000 --- a/docs/ansible_guide.md +++ /dev/null @@ -1 +0,0 @@ -https://docs.ansible.com/ansible/latest/getting_started/get_started_ansible.html#get-started-ansible diff --git a/docs/git_guide.md b/docs/git_guide.md deleted file mode 100644 index e69de29..0000000 From 0434c3dc87c13b84df69e07324c63013e5e3721b Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 13 Nov 2024 15:28:22 +0000 Subject: [PATCH 03/36] Commit de pe VM --- hello.tf | 5 +++++ terraform.tfstate | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 hello.tf create mode 100644 terraform.tfstate diff --git a/hello.tf b/hello.tf new file mode 100644 index 0000000..6f89fb5 --- /dev/null +++ b/hello.tf @@ -0,0 +1,5 @@ +resource "null_resource" "default" { + provisioner "local-exec" { + command = "echo 'Hello World'" + } +} diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000..ef95c54 --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,26 @@ +{ + "version": 4, + "terraform_version": "1.9.8", + "serial": 1, + "lineage": "c49cef41-e140-8eee-bb81-5294bf9d8fc6", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "null_resource", + "name": "default", + "provider": "provider[\"registry.terraform.io/hashicorp/null\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "7313156813347977250", + "triggers": null + }, + "sensitive_attributes": [] + } + ] + } + ], + "check_results": null +} From 3ba1e36f74a67eeea041e712d75029b03e334b50 Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 13 Nov 2024 15:32:23 +0000 Subject: [PATCH 04/36] Revert "Commit de pe VM" This reverts commit 0434c3dc87c13b84df69e07324c63013e5e3721b. --- hello.tf | 5 ----- terraform.tfstate | 26 -------------------------- 2 files changed, 31 deletions(-) delete mode 100644 hello.tf delete mode 100644 terraform.tfstate diff --git a/hello.tf b/hello.tf deleted file mode 100644 index 6f89fb5..0000000 --- a/hello.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "null_resource" "default" { - provisioner "local-exec" { - command = "echo 'Hello World'" - } -} diff --git a/terraform.tfstate b/terraform.tfstate deleted file mode 100644 index ef95c54..0000000 --- a/terraform.tfstate +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.9.8", - "serial": 1, - "lineage": "c49cef41-e140-8eee-bb81-5294bf9d8fc6", - "outputs": {}, - "resources": [ - { - "mode": "managed", - "type": "null_resource", - "name": "default", - "provider": "provider[\"registry.terraform.io/hashicorp/null\"]", - "instances": [ - { - "schema_version": 0, - "attributes": { - "id": "7313156813347977250", - "triggers": null - }, - "sensitive_attributes": [] - } - ] - } - ], - "check_results": null -} From f6441b3a618130b3e83e5b42b994d24059741dc5 Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 13 Nov 2024 15:33:56 +0000 Subject: [PATCH 05/36] Reapply "Commit de pe VM" This reverts commit 3ba1e36f74a67eeea041e712d75029b03e334b50. --- hello.tf | 5 +++++ terraform.tfstate | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 hello.tf create mode 100644 terraform.tfstate diff --git a/hello.tf b/hello.tf new file mode 100644 index 0000000..6f89fb5 --- /dev/null +++ b/hello.tf @@ -0,0 +1,5 @@ +resource "null_resource" "default" { + provisioner "local-exec" { + command = "echo 'Hello World'" + } +} diff --git a/terraform.tfstate b/terraform.tfstate new file mode 100644 index 0000000..ef95c54 --- /dev/null +++ b/terraform.tfstate @@ -0,0 +1,26 @@ +{ + "version": 4, + "terraform_version": "1.9.8", + "serial": 1, + "lineage": "c49cef41-e140-8eee-bb81-5294bf9d8fc6", + "outputs": {}, + "resources": [ + { + "mode": "managed", + "type": "null_resource", + "name": "default", + "provider": "provider[\"registry.terraform.io/hashicorp/null\"]", + "instances": [ + { + "schema_version": 0, + "attributes": { + "id": "7313156813347977250", + "triggers": null + }, + "sensitive_attributes": [] + } + ] + } + ], + "check_results": null +} From 434d036b37ef98a5c0a7b9289be5d3dea298ca4f Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 13 Nov 2024 17:42:07 +0000 Subject: [PATCH 06/36] close #5 --- python.yaml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 python.yaml diff --git a/python.yaml b/python.yaml new file mode 100644 index 0000000..ec20980 --- /dev/null +++ b/python.yaml @@ -0,0 +1,16 @@ +--- +- name: Start Python web server + hosts: all + become: yes + tasks: + - name: Ensure Python is installed + apt: + name: python3 + state: present + + - name: Start Python web server + command: python3 -m http.server + args: + chdir: /var/www/html + async: 3600 + poll: 0 From dfde6ac91e1122bd202d1e79e1b35b9649a583a5 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 13 Nov 2024 17:49:54 +0000 Subject: [PATCH 07/36] closes #5 --- python.yaml => ansible/python.yaml | 0 readme.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename python.yaml => ansible/python.yaml (100%) create mode 100644 readme.md diff --git a/python.yaml b/ansible/python.yaml similarity index 100% rename from python.yaml rename to ansible/python.yaml diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e69de29 From afe6f9e0dfa8e7bae40f8aa4445c7cfb3efd3f75 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 13 Nov 2024 17:53:13 +0000 Subject: [PATCH 08/36] #5 --- readme.md => terraform/readme.md | 0 virtualbox/readme.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename readme.md => terraform/readme.md (100%) create mode 100644 virtualbox/readme.md diff --git a/readme.md b/terraform/readme.md similarity index 100% rename from readme.md rename to terraform/readme.md diff --git a/virtualbox/readme.md b/virtualbox/readme.md new file mode 100644 index 0000000..e69de29 From e7ec570cd332533a3ac4a4034e1b60f680b3c137 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Sun, 17 Nov 2024 11:26:21 +0000 Subject: [PATCH 09/36] Add NGINX role with load balancer configuration --- ansible/roles/nginx/handlers/main.yml | 6 ++++ ansible/roles/nginx/tasks/main.yml | 34 +++++++++++++++++++ .../nginx/templates/load-balancer.conf.j2 | 16 +++++++++ ansible/roles/nginx/templates/nginx.conf.j2 | 26 ++++++++++++++ ansible/roles/nginx/vars/main.yml | 9 +++++ 5 files changed, 91 insertions(+) create mode 100644 ansible/roles/nginx/handlers/main.yml create mode 100644 ansible/roles/nginx/tasks/main.yml create mode 100644 ansible/roles/nginx/templates/load-balancer.conf.j2 create mode 100644 ansible/roles/nginx/templates/nginx.conf.j2 create mode 100644 ansible/roles/nginx/vars/main.yml diff --git a/ansible/roles/nginx/handlers/main.yml b/ansible/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..ed98649 --- /dev/null +++ b/ansible/roles/nginx/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: Restart NGINX + systemd: + name: nginx + state: restarted + become: true diff --git a/ansible/roles/nginx/tasks/main.yml b/ansible/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..c4df2ce --- /dev/null +++ b/ansible/roles/nginx/tasks/main.yml @@ -0,0 +1,34 @@ +--- +- name: Install NGINX + apt: + name: nginx + state: present + update_cache: yes + become: true + +- name: Create NGINX configuration + template: + src: nginx.conf.j2 + dest: /etc/nginx/nginx.conf + owner: root + group: root + mode: '0644' + notify: Restart NGINX + become: true + +- name: Create load balancer configuration + template: + src: load-balancer.conf.j2 + dest: /etc/nginx/conf.d/load-balancer.conf + owner: root + group: root + mode: '0644' + notify: Restart NGINX + become: true + +- name: Ensure NGINX service is running + systemd: + name: nginx + state: started + enabled: yes + become: true diff --git a/ansible/roles/nginx/templates/load-balancer.conf.j2 b/ansible/roles/nginx/templates/load-balancer.conf.j2 new file mode 100644 index 0000000..2ab95c3 --- /dev/null +++ b/ansible/roles/nginx/templates/load-balancer.conf.j2 @@ -0,0 +1,16 @@ +upstream backend { + {% for server in backend_servers %} + server {{ server.host }}:{{ server.port }} weight={{ server.weight | default(1) }}; + {% endfor %} +} + +server { + listen 80; + server_name {{ server_name }}; + + location / { + proxy_pass http://backend; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } +} diff --git a/ansible/roles/nginx/templates/nginx.conf.j2 b/ansible/roles/nginx/templates/nginx.conf.j2 new file mode 100644 index 0000000..a5420b7 --- /dev/null +++ b/ansible/roles/nginx/templates/nginx.conf.j2 @@ -0,0 +1,26 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; + +events { + worker_connections 768; +} + +http { + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ssl_protocols TLSv1.2 TLSv1.3; + ssl_prefer_server_ciphers on; + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/ansible/roles/nginx/vars/main.yml b/ansible/roles/nginx/vars/main.yml new file mode 100644 index 0000000..8718ea2 --- /dev/null +++ b/ansible/roles/nginx/vars/main.yml @@ -0,0 +1,9 @@ +--- +server_name: example.com +backend_servers: + - host: 192.168.1.10 + port: 8080 + weight: 3 + - host: 192.168.1.11 + port: 8080 + weight: 2 From f19ad1e2be34b34fd99a76482f7fa62243ccb4a6 Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 20 Nov 2024 17:10:18 +0000 Subject: [PATCH 10/36] Creat si sortat fisiere relevante --- README.md => ci-cd/README.md | 0 hello.tf => terraform/hello.tf | 0 terraform.tfstate => terraform/terraform.tfstate | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename README.md => ci-cd/README.md (100%) rename hello.tf => terraform/hello.tf (100%) rename terraform.tfstate => terraform/terraform.tfstate (100%) diff --git a/README.md b/ci-cd/README.md similarity index 100% rename from README.md rename to ci-cd/README.md diff --git a/hello.tf b/terraform/hello.tf similarity index 100% rename from hello.tf rename to terraform/hello.tf diff --git a/terraform.tfstate b/terraform/terraform.tfstate similarity index 100% rename from terraform.tfstate rename to terraform/terraform.tfstate From 7c4acf52e3401a1c5712139adc921918e546e16e Mon Sep 17 00:00:00 2001 From: sebastianG Date: Wed, 27 Nov 2024 18:48:52 +0200 Subject: [PATCH 11/36] Create github-actions-demo.yml --- github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 github-actions-demo.yml diff --git a/github-actions-demo.yml b/github-actions-demo.yml new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/github-actions-demo.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From bd24dee816576972157641c817f9be7d9edba30f Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 27 Nov 2024 16:54:32 +0000 Subject: [PATCH 12/36] Added github actions yml --- .github/workflows/github-actions-demo.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..769842c --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,19 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + From 4e07e8c9d7b1a827935880f8bdfa49abcd6fe8fa Mon Sep 17 00:00:00 2001 From: sebastianG Date: Wed, 27 Nov 2024 19:01:19 +0200 Subject: [PATCH 13/36] Create sebastian git hub actions https://docs.github.com/en/actions/writing-workflows/quickstart --- sebastian git hub actions | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 sebastian git hub actions diff --git a/sebastian git hub actions b/sebastian git hub actions new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/sebastian git hub actions @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From 8ce7c0e62b2d19689ae4627cc2a48f73048f6db6 Mon Sep 17 00:00:00 2001 From: Alllexia Date: Wed, 27 Nov 2024 19:07:06 +0200 Subject: [PATCH 14/36] added file for issue #21 --- .github/workflows/github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From b0feeae3de90a9fddc5dfc3c7cc4ab67100a3904 Mon Sep 17 00:00:00 2001 From: RC-DevOps Date: Wed, 27 Nov 2024 17:10:07 +0000 Subject: [PATCH 15/36] Create workflows GitHub Actions workflow added --- .github/workflows | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows diff --git a/.github/workflows b/.github/workflows new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/.github/workflows @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From 4bdc22fb840baecdbbc4d05cc871bb498dc52608 Mon Sep 17 00:00:00 2001 From: sebastianG Date: Wed, 27 Nov 2024 19:17:47 +0200 Subject: [PATCH 16/36] Rename sebastian git hub actions to .github/workflow/github-actions-demo.yml --- .../workflow/github-actions-demo.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sebastian git hub actions => .github/workflow/github-actions-demo.yml (100%) diff --git a/sebastian git hub actions b/.github/workflow/github-actions-demo.yml similarity index 100% rename from sebastian git hub actions rename to .github/workflow/github-actions-demo.yml From c6656a1dba28f6a19479a50f9ae290fd1f22b925 Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 27 Nov 2024 17:18:23 +0000 Subject: [PATCH 17/36] Reverting changes --- .github/workflows | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .github/workflows diff --git a/.github/workflows b/.github/workflows deleted file mode 100644 index 15a61d6..0000000 --- a/.github/workflows +++ /dev/null @@ -1,18 +0,0 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." From dba3c4638ddab16f2980e6dcfbc2bf3c62489bcf Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 27 Nov 2024 17:22:41 +0000 Subject: [PATCH 18/36] Remaking desired config --- .github/workflows/github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From dcc4f6e55c638215980286f687442bf044a461d0 Mon Sep 17 00:00:00 2001 From: sebbastianG Date: Wed, 27 Nov 2024 17:24:59 +0000 Subject: [PATCH 19/36] Te pupa Jean --- .github/{workflow => workflows}/github-actions-demo.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/github-actions-demo.yml (100%) diff --git a/.github/workflow/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml similarity index 100% rename from .github/workflow/github-actions-demo.yml rename to .github/workflows/github-actions-demo.yml From 944fa3396ef08ae85015f215fb6459560d9c8aae Mon Sep 17 00:00:00 2001 From: sebastianG Date: Wed, 27 Nov 2024 19:51:56 +0200 Subject: [PATCH 20/36] Update github-actions-demo.yml --- .github/workflows/github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index 15a61d6..51770d9 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -16,3 +16,21 @@ jobs: run: | ls ${{ github.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From c683cb69c0c0d7ba9d7e5548f73d81d742f811d4 Mon Sep 17 00:00:00 2001 From: sebastianG Date: Wed, 27 Nov 2024 19:53:15 +0200 Subject: [PATCH 21/36] Update github-actions-demo.yml --- .github/workflows/github-actions-demo.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index 51770d9..acc9735 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -16,11 +16,7 @@ jobs: run: | ls ${{ github.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: +Explore-GitHub-Actions: runs-on: ubuntu-latest steps: - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." From a6fb8be46465bbbef9772150e73295453876ba82 Mon Sep 17 00:00:00 2001 From: sebastianG Date: Wed, 27 Nov 2024 19:54:38 +0200 Subject: [PATCH 22/36] Update github-actions-demo.yml --- .github/workflows/github-actions-demo.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index acc9735..15a61d6 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -16,17 +16,3 @@ jobs: run: | ls ${{ github.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." -Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." From f239534de4dddd50e517627e525137deeed50d9c Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 27 Nov 2024 17:55:15 +0000 Subject: [PATCH 23/36] Modificat job --- .github/workflows/github-actions-demo.yml | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index 769842c..d1c7c11 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -16,4 +16,48 @@ jobs: run: | ls ${{ github.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." + Explore-GitHub-Actions-1: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + Explore-GitHub-Actions-2: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + Explore-GitHub-Actions-3: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." + - run: echo "Te pupa Jean "" + From d17d3992b6cf00201f6b0cae25f2a128e22d7796 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 27 Nov 2024 17:56:32 +0000 Subject: [PATCH 24/36] Modificat job --- .github/workflows/github-actions-demo.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index d1c7c11..8453d39 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -58,6 +58,6 @@ jobs: run: | ls ${{ github.workspace }} - run: echo "🍏 This job's status is ${{ job.status }}." - - run: echo "Te pupa Jean "" + - run: echo "Te pupa Jean " From 055e6e232c0f26a965cc7a3aba026c61ccea8081 Mon Sep 17 00:00:00 2001 From: "Radu C." Date: Wed, 27 Nov 2024 18:07:36 +0000 Subject: [PATCH 25/36] deleting initial .github directory --- .github/workflows/github-actions-demo.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml deleted file mode 100644 index 15a61d6..0000000 --- a/.github/workflows/github-actions-demo.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." From 6aea8c9ca59063acc72bea51fc542eee061c9f6c Mon Sep 17 00:00:00 2001 From: RC-DevOps Date: Wed, 27 Nov 2024 18:08:47 +0000 Subject: [PATCH 26/36] Create github-actions-demo.yml --- .github/workflows/github-actions-demo.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..15a61d6 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,18 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From e3c845fe7c85ab59be29bab13edb21061f96582f Mon Sep 17 00:00:00 2001 From: sebastianG Date: Fri, 29 Nov 2024 20:10:26 +0800 Subject: [PATCH 27/36] Create main.tf I want to implement a Terraform module that automates the creation and management of AWS S3 buckets. This feature will help us to standardize our AWS S3 infrastructure and enable version-controlled management of these resources. --- main.tf | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 main.tf diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..437b66b --- /dev/null +++ b/main.tf @@ -0,0 +1,4 @@ +resource "aws_s3_bucket" "bucket" { + bucket = var.bucket_name + acl = var.acl +} From d3a23fd7c4e0f5341d2e4e7a2a21a0e0d1c525f9 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Sat, 30 Nov 2024 08:57:24 +0000 Subject: [PATCH 28/36] Add S3 module for managing AWS S3 buckets --- .../terraform-modules/tf-s3-module/inputs.tf | 149 ++++++++++++++++++ .../terraform-modules/tf-s3-module/main.tf | 40 +++++ .../terraform-modules/tf-s3-module/outputs.tf | 12 ++ .../tf-s3-module/versions.tf | 10 ++ 4 files changed, 211 insertions(+) create mode 100644 terraform/terraform-modules/tf-s3-module/inputs.tf create mode 100644 terraform/terraform-modules/tf-s3-module/main.tf create mode 100644 terraform/terraform-modules/tf-s3-module/outputs.tf create mode 100644 terraform/terraform-modules/tf-s3-module/versions.tf diff --git a/terraform/terraform-modules/tf-s3-module/inputs.tf b/terraform/terraform-modules/tf-s3-module/inputs.tf new file mode 100644 index 0000000..ce8318e --- /dev/null +++ b/terraform/terraform-modules/tf-s3-module/inputs.tf @@ -0,0 +1,149 @@ +variable "owner" { + description = "The person who requested this resource" + type = string +} + +variable "name" { + description = "The name of the env" + type = string +} + +variable "s3_bucket_names" { + type = list(any) + default = [] + +} + +variable "s3_bucket_names_overrides" { + type = list(any) + default = [] + +} + +variable "server_side_encryption_configuration" { + description = "Encrypt s3 bucket" + type = any + default = {} + +} + +variable "force_destroy" { + type = bool + description = "" + default = false + +} + +variable "block_public_acls" { + description = "Whether Amazon S3 should block public ACLs for this bucket." + type = bool + default = true +} + +variable "block_public_policy" { + description = "Whether Amazon S3 should block public bucket policies for this bucket." + type = bool + default = true +} + +variable "ignore_public_acls" { + description = "Whether Amazon S3 should ignore public ACLs for this bucket." + type = bool + default = true +} + +variable "restrict_public_buckets" { + description = "Whether Amazon S3 should restrict public bucket policies for this bucket." + type = bool + default = true +} + +variable "acl" { + type = string + default = "private" + +} + +variable "policy" { + description = "A valid bucket policy JSON document" + type = string + default = "" + +} + +variable "attach_policy" { + description = "Controls if S3 bucket should have bucket policy attached (set to `true` to use value of `policy` as bucket policy)" + type = bool + default = false + +} + +variable "lifecycle_rule" { + description = "List of maps containing configuration of object lifecycle management." + type = any + default = [] + +} + +variable "logging" { + description = "Map containing access bucket logging configuration." + type = map(string) + default = {} + +} + +variable "versioning" { + description = "Map containing versioning configuration." + type = map(string) + default = {} + +} + +variable "cors_rule" { + description = "Map containing versioning configuration." + type = any + default = [] +} + +variable "attach_elb_log_delivery_policy" { + description = "Controls if S3 bucket should have ELB log delivery policy attached" + type = bool + default = false +} + +variable "attach_lb_log_delivery_policy" { + description = "Controls if S3 bucket should have ALB/NLB log delivery policy attached" + type = bool + default = false +} + +variable "control_object_ownership" { + description = "Whether to manage S3 Bucket Ownership Controls on this bucket" + type = bool + default = true +} + +variable "object_ownership" { + description = "Object ownership. Valid values: BucketOwnerEnforced, BucketOwnerPreferred or ObjectWriter. 'BucketOwnerEnforced': ACLs are disabled, and the bucket owner automatically owns and has full control over every object in the bucket. 'BucketOwnerPreferred': Objects uploaded to the bucket change ownership to the bucket owner if the objects are uploaded with the bucket-owner-full-control canned ACL. 'ObjectWriter': The uploading account will own the object if the object is uploaded with the bucket-owner-full-control canned ACL." + type = string + default = "BucketOwnerPreferred" +} + +variable "attach_public_policy" { + description = "Controls if a user defined public bucket policy will be attached (set to `false` to allow upstream to apply defaults to the bucket)" + type = bool + default = true +} + +variable "extra_tags" { + description = "Extra tags to dd to the bucket" + type = map(any) + default = {} +} + +variable "website" { + description = "Map containing static web-site hosting or redirect configuration." + type = any # map(string) + default = {} +} + diff --git a/terraform/terraform-modules/tf-s3-module/main.tf b/terraform/terraform-modules/tf-s3-module/main.tf new file mode 100644 index 0000000..956d06e --- /dev/null +++ b/terraform/terraform-modules/tf-s3-module/main.tf @@ -0,0 +1,40 @@ +locals { + common_tags = { + ManagedBy = "Terraform" + Owner = var.owner + Env = var.name + } +} + +module "s3_buckets" { + source = "terraform-aws-modules/s3-bucket/aws" + version = "4.2.2" + + count = length(var.s3_bucket_names_overrides) > 0 ? length(var.s3_bucket_names_overrides) : length(var.s3_bucket_names) + bucket = length(var.s3_bucket_names_overrides) > 0 ? var.s3_bucket_names_overrides[count.index] : "tf-${var.s3_bucket_names[count.index]}-${var.owner}-${var.name}" + acl = var.acl + force_destroy = var.force_destroy + + server_side_encryption_configuration = var.server_side_encryption_configuration + lifecycle_rule = var.lifecycle_rule + logging = var.logging + versioning = var.versioning + cors_rule = var.cors_rule + attach_elb_log_delivery_policy = var.attach_elb_log_delivery_policy + attach_lb_log_delivery_policy = var.attach_lb_log_delivery_policy + + block_public_acls = var.block_public_acls + block_public_policy = var.block_public_policy + ignore_public_acls = var.ignore_public_acls + restrict_public_buckets = var.restrict_public_buckets + attach_public_policy = var.attach_public_policy + attach_policy = var.attach_policy + control_object_ownership = var.control_object_ownership + object_ownership = var.object_ownership + policy = var.policy + + website = var.website + + tags = merge(local.common_tags, var.extra_tags) +} + diff --git a/terraform/terraform-modules/tf-s3-module/outputs.tf b/terraform/terraform-modules/tf-s3-module/outputs.tf new file mode 100644 index 0000000..29051d9 --- /dev/null +++ b/terraform/terraform-modules/tf-s3-module/outputs.tf @@ -0,0 +1,12 @@ +output "bucket_names" { + value = module.s3_buckets[*].s3_bucket_id +} + +output "bucket_regional_domain_name" { + value = module.s3_buckets[*].s3_bucket_bucket_regional_domain_name +} + +output "bucket_arn" { + value = module.s3_buckets[*].s3_bucket_arn +} + diff --git a/terraform/terraform-modules/tf-s3-module/versions.tf b/terraform/terraform-modules/tf-s3-module/versions.tf new file mode 100644 index 0000000..f640f6b --- /dev/null +++ b/terraform/terraform-modules/tf-s3-module/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 5.64.0" + } + } + required_version = ">= 1.9.5" +} + From 93703f143cf6dc087c575eae5e16491a142e4391 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Sat, 30 Nov 2024 10:21:31 +0000 Subject: [PATCH 29/36] Added required info in the readme.md --- terraform/.gitignore | 26 ++++++++++++++++++++++++++ terraform/readme.md | 21 +++++++++++++++++++++ terraform/s3.tf | 11 +++++++++++ 3 files changed, 58 insertions(+) create mode 100644 terraform/.gitignore create mode 100644 terraform/s3.tf diff --git a/terraform/.gitignore b/terraform/.gitignore new file mode 100644 index 0000000..787b882 --- /dev/null +++ b/terraform/.gitignore @@ -0,0 +1,26 @@ +# Local .terraform directories +**/.terraform/* + +# Ignore variables files +*.auto.tfvars + +# Ignore override files +*.tfoverride + +# Ignore environment-specific files +.envrc + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# Ignore Terraform state files and providers +terraform.tfstate +terraform.lock.hcl + +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* diff --git a/terraform/readme.md b/terraform/readme.md index e69de29..bd72841 100644 --- a/terraform/readme.md +++ b/terraform/readme.md @@ -0,0 +1,21 @@ +TERRAFORM AWS S3 BUCKETS MODULE + +To keep our work well structured, ww will use separate folders for each type of resource. In our case, for modules we will use "terraform-modules". + +The structure of this project is: +Main folder - terraform + Subfolder - terraform-modules + Subfolder - tf-s3-module + +In the "terraform" folder we have 2 files: +1. readme.md - this is the file that contains valuable information about the project +2. s3.tf - this is the file that we will use to create our AWS S3 buckets. In this file we need to change the "name" and "owner" vars to our desire. +Also, we can specify more variables (ex. acl, force_destroy, etc) or use the default ones in the module folder. + +In the "terraform-modules" folder we will create separate folders for each module. The first one is the AWS S3 Module, "tf-s3-module", that contains +the code for a module that we will use to manage the AWS S3 buckets in an easy and organized way, using variables. The folder contains 4 files: +1. inputs.tf - this file contains the variables we can use with our module +2. outputs.tf - this file contains the output variables we need from the job execution output +3. versions.tf - this file contains the module version as well as the minimum required version (using an older version may lead to errors as variables may not be implemented, etc.) +4. main.tf - this is the main module file + diff --git a/terraform/s3.tf b/terraform/s3.tf new file mode 100644 index 0000000..49fa3f1 --- /dev/null +++ b/terraform/s3.tf @@ -0,0 +1,11 @@ +module "s3_bucket" { + source = "git::https://github.com/mihai-satmarean/sciitdevops/blob/main/terraform/terraform-modules/tf-s3-modules/" # se va modifica in functie de locatia modulului in GitHub + + name = "nume" # numele tag-ului ce il atribuim resursei + owner = "owner" # numele owner-ului resursei + + s3_bucket_names = ["mariusb_devops_bucket1"] + acl = "private" + force_destroy = false + +} From 11a758d216eba7e634563b84b891e10ab942c3c7 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Mon, 2 Dec 2024 16:09:46 +0000 Subject: [PATCH 30/36] Added local.tf --- terraform/terraform-modules/tf-s3-module/local.tf | 7 +++++++ terraform/terraform-modules/tf-s3-module/main.tf | 8 -------- 2 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 terraform/terraform-modules/tf-s3-module/local.tf diff --git a/terraform/terraform-modules/tf-s3-module/local.tf b/terraform/terraform-modules/tf-s3-module/local.tf new file mode 100644 index 0000000..1f7264e --- /dev/null +++ b/terraform/terraform-modules/tf-s3-module/local.tf @@ -0,0 +1,7 @@ +locals { + common_tags = { + ManagedBy = "Terraform" + Owner = var.owner + Env = var.name + } +} diff --git a/terraform/terraform-modules/tf-s3-module/main.tf b/terraform/terraform-modules/tf-s3-module/main.tf index 956d06e..8cc39c3 100644 --- a/terraform/terraform-modules/tf-s3-module/main.tf +++ b/terraform/terraform-modules/tf-s3-module/main.tf @@ -1,11 +1,3 @@ -locals { - common_tags = { - ManagedBy = "Terraform" - Owner = var.owner - Env = var.name - } -} - module "s3_buckets" { source = "terraform-aws-modules/s3-bucket/aws" version = "4.2.2" From 3a19ac4bcfad138ece107f0248b017becb8249a4 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Mon, 2 Dec 2024 17:17:19 +0000 Subject: [PATCH 31/36] Added custom var --- .github/workflows/github-actions-demo.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/github-actions-demo.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml new file mode 100644 index 0000000..3e4ee35 --- /dev/null +++ b/.github/workflows/github-actions-demo.yml @@ -0,0 +1,19 @@ +name: GitHub Actions Demo +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [push] +jobs: + Explore-GitHub-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The custom variable is ${{ vars.CLOUD_VENDOR }} " + - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" + - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ github.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." From 0c7aaf076133c191c0d4ed7836b7f0ea3b23faf4 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Mon, 2 Dec 2024 19:58:14 +0000 Subject: [PATCH 32/36] moved file --- github-actions-demo.yml | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 github-actions-demo.yml diff --git a/github-actions-demo.yml b/github-actions-demo.yml deleted file mode 100644 index 15a61d6..0000000 --- a/github-actions-demo.yml +++ /dev/null @@ -1,18 +0,0 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." From fe7c990a7322afe02821370274509c1b84da1914 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Mon, 2 Dec 2024 22:48:53 +0000 Subject: [PATCH 33/36] Added AWS EC2 module --- terraform/hello.tf | 5 -- .../tf-ec2-module/.gitignore | 26 ++++++ .../terraform-modules/tf-ec2-module/apache.sh | 6 ++ .../terraform-modules/tf-ec2-module/local.tf | 8 ++ .../terraform-modules/tf-ec2-module/main.tf | 79 +++++++++++++++++++ .../tf-ec2-module/outputs.tf | 20 +++++ .../tf-ec2-module/terraform.tfvars | 2 + .../tf-ec2-module/variables.tf | 52 ++++++++++++ terraform/terraform.tfstate | 26 ------ 9 files changed, 193 insertions(+), 31 deletions(-) delete mode 100644 terraform/hello.tf create mode 100644 terraform/terraform-modules/tf-ec2-module/.gitignore create mode 100644 terraform/terraform-modules/tf-ec2-module/apache.sh create mode 100644 terraform/terraform-modules/tf-ec2-module/local.tf create mode 100644 terraform/terraform-modules/tf-ec2-module/main.tf create mode 100644 terraform/terraform-modules/tf-ec2-module/outputs.tf create mode 100644 terraform/terraform-modules/tf-ec2-module/terraform.tfvars create mode 100644 terraform/terraform-modules/tf-ec2-module/variables.tf delete mode 100644 terraform/terraform.tfstate diff --git a/terraform/hello.tf b/terraform/hello.tf deleted file mode 100644 index 6f89fb5..0000000 --- a/terraform/hello.tf +++ /dev/null @@ -1,5 +0,0 @@ -resource "null_resource" "default" { - provisioner "local-exec" { - command = "echo 'Hello World'" - } -} diff --git a/terraform/terraform-modules/tf-ec2-module/.gitignore b/terraform/terraform-modules/tf-ec2-module/.gitignore new file mode 100644 index 0000000..787b882 --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/.gitignore @@ -0,0 +1,26 @@ +# Local .terraform directories +**/.terraform/* + +# Ignore variables files +*.auto.tfvars + +# Ignore override files +*.tfoverride + +# Ignore environment-specific files +.envrc + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# Ignore Terraform state files and providers +terraform.tfstate +terraform.lock.hcl + +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* diff --git a/terraform/terraform-modules/tf-ec2-module/apache.sh b/terraform/terraform-modules/tf-ec2-module/apache.sh new file mode 100644 index 0000000..6f512d3 --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/apache.sh @@ -0,0 +1,6 @@ +#! /bin/bash +sudo apt-get update +sudo apt-get install -y apache2 +sudo systemctl start apache2 +sudo systemctl enable apache2 +echo "Mi-am facut tema pentru cursul DevOps din data de 02.12.2024" | sudo tee /var/www/html/index.html diff --git a/terraform/terraform-modules/tf-ec2-module/local.tf b/terraform/terraform-modules/tf-ec2-module/local.tf new file mode 100644 index 0000000..fc62847 --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/local.tf @@ -0,0 +1,8 @@ +locals { + common_tags = { + ManagedBy = "Terraform" + Owner = var.owner + Env = var.name + } +} + diff --git a/terraform/terraform-modules/tf-ec2-module/main.tf b/terraform/terraform-modules/tf-ec2-module/main.tf new file mode 100644 index 0000000..4fb4f56 --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/main.tf @@ -0,0 +1,79 @@ +provider "aws" { + region = var.region +} + +resource "aws_vpc" "mariusb-vpc" { + cidr_block = var.vpc_cidr + tags = merge(local.common_tags, { Name = "mariusb-vpc" }) +} + +resource "aws_subnet" "public-subnet" { + vpc_id = aws_vpc.mariusb-vpc.id + cidr_block = var.public_subnet_cidr + map_public_ip_on_launch = true + availability_zone = var.public_subnet_az + tags = merge(local.common_tags, { Name = "public-subnet" }) +} + +resource "aws_subnet" "private-subnet" { + vpc_id = aws_vpc.mariusb-vpc.id + cidr_block = var.private_subnet_cidr + availability_zone = var.private_subnet_az + tags = merge(local.common_tags, { Name = "private-subnet" }) +} + +resource "aws_internet_gateway" "net-igw" { + vpc_id = aws_vpc.mariusb-vpc.id + tags = merge(local.common_tags, { Name = "net-igw" }) +} + +resource "aws_route_table" "public-rt" { + vpc_id = aws_vpc.mariusb-vpc.id + route { + cidr_block = "0.0.0.0/0" + gateway_id = aws_internet_gateway.net-igw.id + } + tags = merge(local.common_tags, { Name = "public-rt" }) +} + +resource "aws_route_table_association" "public-rt" { + subnet_id = aws_subnet.public-subnet.id + route_table_id = aws_route_table.public-rt.id +} + +resource "aws_security_group" "mariusb-sg" { + vpc_id = aws_vpc.mariusb-vpc.id + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + ingress { + description = "SSH" + from_port = 22 + to_port = 22 + protocol = "tcp" + cidr_blocks = ["86.120.230.117/32"] + ipv6_cidr_blocks = ["::/0"] + } + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + tags = merge(local.common_tags, { Name = "mariusb-sg" }) +} +resource "aws_instance" "web" { + ami = "ami-0084a47cc718c111a" # Ubuntu AMI + instance_type = "t2.micro" + availability_zone = var.public_subnet_az + subnet_id = aws_subnet.public-subnet.id + vpc_security_group_ids = [aws_security_group.mariusb-sg.id] + + tags = merge(local.common_tags, { Name = "WebServer" }) + + user_data = file("apache.sh") +} + diff --git a/terraform/terraform-modules/tf-ec2-module/outputs.tf b/terraform/terraform-modules/tf-ec2-module/outputs.tf new file mode 100644 index 0000000..5c3cd5d --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/outputs.tf @@ -0,0 +1,20 @@ +output "vpc_id" { + description = "The ID of the VPC" + value = aws_vpc.mariusb-vpc.id +} + +output "public_subnet_id" { + description = "The ID of the public subnet" + value = aws_subnet.public-subnet.id +} + +output "private_subnet_id" { + description = "The ID of the private subnet" + value = aws_subnet.private-subnet.id +} + +output "security_group_id" { + description = "The ID of the security group" + value = aws_security_group.mariusb-sg.id +} + diff --git a/terraform/terraform-modules/tf-ec2-module/terraform.tfvars b/terraform/terraform-modules/tf-ec2-module/terraform.tfvars new file mode 100644 index 0000000..21edc65 --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/terraform.tfvars @@ -0,0 +1,2 @@ +owner = "Marius" +name = "Dev" diff --git a/terraform/terraform-modules/tf-ec2-module/variables.tf b/terraform/terraform-modules/tf-ec2-module/variables.tf new file mode 100644 index 0000000..9ed2d23 --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/variables.tf @@ -0,0 +1,52 @@ +variable "region" { + description = "The AWS region to deploy resources in" + type = string + default = "eu-central-1" +} + +variable "vpc_cidr" { + description = "The CIDR block for the VPC" + type = string + default = "10.0.0.0/16" +} + +variable "public_subnet_cidr" { + description = "The CIDR block for the public subnet" + type = string + default = "10.0.1.0/24" +} + +variable "private_subnet_cidr" { + description = "The CIDR block for the private subnet" + type = string + default = "10.0.2.0/24" +} + +variable "public_subnet_az" { + description = "The availability zone for the public subnet" + type = string + default = "eu-central-1a" +} + +variable "private_subnet_az" { + description = "The availability zone for the private subnet" + type = string + default = "eu-central-1b" +} + +variable "owner" { + description = "Owner of the resources" + type = string +} + +variable "name" { + description = "Environment name" + type = string +} + +variable "extra_tags" { + description = "Additional tags to apply to resources" + type = map(string) + default = {} +} + diff --git a/terraform/terraform.tfstate b/terraform/terraform.tfstate deleted file mode 100644 index ef95c54..0000000 --- a/terraform/terraform.tfstate +++ /dev/null @@ -1,26 +0,0 @@ -{ - "version": 4, - "terraform_version": "1.9.8", - "serial": 1, - "lineage": "c49cef41-e140-8eee-bb81-5294bf9d8fc6", - "outputs": {}, - "resources": [ - { - "mode": "managed", - "type": "null_resource", - "name": "default", - "provider": "provider[\"registry.terraform.io/hashicorp/null\"]", - "instances": [ - { - "schema_version": 0, - "attributes": { - "id": "7313156813347977250", - "triggers": null - }, - "sensitive_attributes": [] - } - ] - } - ], - "check_results": null -} From dd657345e03a6f9889825d537c273c933a280ae7 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Mon, 2 Dec 2024 22:50:44 +0000 Subject: [PATCH 34/36] Added README.md file --- .../terraform-modules/tf-ec2-module/README.md | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 terraform/terraform-modules/tf-ec2-module/README.md diff --git a/terraform/terraform-modules/tf-ec2-module/README.md b/terraform/terraform-modules/tf-ec2-module/README.md new file mode 100644 index 0000000..ee482ba --- /dev/null +++ b/terraform/terraform-modules/tf-ec2-module/README.md @@ -0,0 +1,32 @@ + +Project steps: +1. Set Up Terraform: +• Install Terraform on your local machine or use a cloud-based development environment. +sudo apt install terraform +• Configure Terraform to authenticate with AWS using environment variables or IAM roles. +aws configure + +2. Infrastructure Requirements: +• VPC: Create a VPC with a custom CIDR block (e.g., 10.0.0.0/16). +• Subnets: Create two subnets within the VPC (e.g., one public and one private). +• Route Table: Define a route table and associate it with the public subnet. Add a default route to the internet. +• Internet Gateway: Attach an internet gateway to the VPC for internet connectivity. +• Security Group: Security Group allowing HTTP connection from outside. + +3. We create the above resources using main.tf and variables.tf files. +We create an outputs.tf file to get information about created resources and we format the Terraform files using terraform fmt. + +4. Deploy Infrastructure: +• Run the following Terraform commands: +- terraform init to initialize the working directory. +- terraform plan to review the execution plan. +- terraform apply to deploy the infrastructure. + +5. Validate the Deployment: +• Verify the VPC and its components in the AWS Management Console. +• Confirm that the public subnet has internet access. + + + + + From e21c9de2d15eb75de790ccc78d91d995d8625ce6 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 4 Dec 2024 19:48:15 +0200 Subject: [PATCH 35/36] Update github-actions-demo.yml --- .github/workflows/github-actions-demo.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml index 3e4ee35..dd3d72b 100644 --- a/.github/workflows/github-actions-demo.yml +++ b/.github/workflows/github-actions-demo.yml @@ -5,6 +5,15 @@ jobs: Explore-GitHub-Actions: runs-on: ubuntu-latest steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v3 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_MARIUS }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_MARIUS }} + aws-region: eu-central-1 + - name: Deploy Infrastructure + run: | + aws s3 ls - run: echo "🎉 The custom variable is ${{ vars.CLOUD_VENDOR }} " - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" From 5aff7e14279f1e926878ed7eebff8eb4ab669254 Mon Sep 17 00:00:00 2001 From: MariusB-DevOps Date: Wed, 4 Dec 2024 20:07:08 +0200 Subject: [PATCH 36/36] Update and rename github-actions-demo.yml to terraform-apply.yml --- .github/workflows/github-actions-demo.yml | 28 ----------------------- .github/workflows/terraform-apply.yml | 21 +++++++++++++++++ 2 files changed, 21 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/github-actions-demo.yml create mode 100644 .github/workflows/terraform-apply.yml diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml deleted file mode 100644 index dd3d72b..0000000 --- a/.github/workflows/github-actions-demo.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: GitHub Actions Demo -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 -on: [push] -jobs: - Explore-GitHub-Actions: - runs-on: ubuntu-latest - steps: - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v3 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_MARIUS }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_MARIUS }} - aws-region: eu-central-1 - - name: Deploy Infrastructure - run: | - aws s3 ls - - run: echo "🎉 The custom variable is ${{ vars.CLOUD_VENDOR }} " - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." - - name: Check out repository code - uses: actions/checkout@v4 - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." - - run: echo "🖥️ The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ github.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/.github/workflows/terraform-apply.yml b/.github/workflows/terraform-apply.yml new file mode 100644 index 0000000..4f264f7 --- /dev/null +++ b/.github/workflows/terraform-apply.yml @@ -0,0 +1,21 @@ +name: Terraform apply +run-name: ${{ github.actor }} is deploying on AWS 🚀 +on: + push: + branches: + feature/aws-s3-module +jobs: + Deploy-AWS-Ec2: + runs-on: ubuntu-latest + steps: + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v3 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_MARIUS }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_MARIUS }} + aws-region: eu-central-1 + - name: Deploy Infrastructure + run: | + terraform init + - run: | + terraform apply -auto-approve