Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/aws s3 module #46

Merged
merged 42 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
dcc7271
New file
Nov 6, 2024
aed3612
deleted a number of files and folders in preparation for submitting t…
13pisicinegre Nov 11, 2024
0434c3d
Commit de pe VM
BlackText Nov 13, 2024
3ba1e36
Revert "Commit de pe VM"
BlackText Nov 13, 2024
f6441b3
Reapply "Commit de pe VM"
BlackText Nov 13, 2024
434d036
close #5
MariusB-DevOps Nov 13, 2024
dfde6ac
closes #5
MariusB-DevOps Nov 13, 2024
afe6f9e
#5
MariusB-DevOps Nov 13, 2024
e7ec570
Add NGINX role with load balancer configuration
MariusB-DevOps Nov 17, 2024
f19ad1e
Creat si sortat fisiere relevante
BlackText Nov 20, 2024
ef0bdc7
Merge pull request #20 from mihai-satmarean/feature-update-gitignore
melania27dev Nov 27, 2024
7c4acf5
Create github-actions-demo.yml
sebbastianG Nov 27, 2024
bd24dee
Added github actions yml
MariusB-DevOps Nov 27, 2024
4e07e8c
Create sebastian git hub actions
sebbastianG Nov 27, 2024
8ce7c0e
added file for issue #21
Alllexia Nov 27, 2024
b0feeae
Create workflows
BlackText Nov 27, 2024
476de12
Merge pull request #23 from mihai-satmarean/feature/paula_github_actions
Alllexia Nov 27, 2024
4bdc22f
Rename sebastian git hub actions to .github/workflow/github-actions-d…
sebbastianG Nov 27, 2024
c6656a1
Reverting changes
BlackText Nov 27, 2024
dba3c46
Remaking desired config
BlackText Nov 27, 2024
dcc4f6e
Te pupa Jean
sebbastianG Nov 27, 2024
944fa33
Update github-actions-demo.yml
sebbastianG Nov 27, 2024
c683cb6
Update github-actions-demo.yml
sebbastianG Nov 27, 2024
a6fb8be
Update github-actions-demo.yml
sebbastianG Nov 27, 2024
f239534
Modificat job
MariusB-DevOps Nov 27, 2024
d17d399
Modificat job
MariusB-DevOps Nov 27, 2024
055e6e2
deleting initial .github directory
BlackText Nov 27, 2024
6aea8c9
Create github-actions-demo.yml
BlackText Nov 27, 2024
f7d64a5
Merge pull request #25 from mihai-satmarean/feature/rc_git_hub_actions
BlackText Nov 27, 2024
b24b897
Merge pull request #22 from mihai-satmarean/feature/sebastian_git_hub…
sebbastianG Nov 28, 2024
e3c845f
Create main.tf
sebbastianG Nov 29, 2024
8d406dd
Merge pull request #29 from mihai-satmarean/feature/add-s3-module
sebbastianG Nov 29, 2024
d3a23fd
Add S3 module for managing AWS S3 buckets
MariusB-DevOps Nov 30, 2024
93703f1
Added required info in the readme.md
MariusB-DevOps Nov 30, 2024
5620238
synced with main
MariusB-DevOps Nov 30, 2024
11a758d
Added local.tf
MariusB-DevOps Dec 2, 2024
3a19ac4
Added custom var
MariusB-DevOps Dec 2, 2024
0c7aaf0
moved file
MariusB-DevOps Dec 2, 2024
fe7c990
Added AWS EC2 module
MariusB-DevOps Dec 2, 2024
dd65734
Added README.md file
MariusB-DevOps Dec 2, 2024
e21c9de
Update github-actions-demo.yml
MariusB-DevOps Dec 4, 2024
5aff7e1
Update and rename github-actions-demo.yml to terraform-apply.yml
MariusB-DevOps Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/terraform-apply.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.box
45 changes: 0 additions & 45 deletions README.md

This file was deleted.

16 changes: 16 additions & 0 deletions ansible/python.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions ansible/roles/nginx/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Restart NGINX
systemd:
name: nginx
state: restarted
become: true
34 changes: 34 additions & 0 deletions ansible/roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions ansible/roles/nginx/templates/load-balancer.conf.j2
Original file line number Diff line number Diff line change
@@ -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;
}
}
26 changes: 26 additions & 0 deletions ansible/roles/nginx/templates/nginx.conf.j2
Original file line number Diff line number Diff line change
@@ -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;
}
9 changes: 9 additions & 0 deletions ansible/roles/nginx/vars/main.yml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions ci-cd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@













































1 change: 0 additions & 1 deletion docs/ansible_guide.md

This file was deleted.

4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "aws_s3_bucket" "bucket" {
bucket = var.bucket_name
acl = var.acl
}
21 changes: 21 additions & 0 deletions terraform/readme.md
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions terraform/s3.tf
Original file line number Diff line number Diff line change
@@ -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

}
26 changes: 26 additions & 0 deletions terraform/terraform-modules/tf-ec2-module/.gitignore
Original file line number Diff line number Diff line change
@@ -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.*
32 changes: 32 additions & 0 deletions terraform/terraform-modules/tf-ec2-module/README.md
Original file line number Diff line number Diff line change
@@ -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.





6 changes: 6 additions & 0 deletions terraform/terraform-modules/tf-ec2-module/apache.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions terraform/terraform-modules/tf-ec2-module/local.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
locals {
common_tags = {
ManagedBy = "Terraform"
Owner = var.owner
Env = var.name
}
}

Loading
Loading