Skip to content

Commit

Permalink
update main (#2)
Browse files Browse the repository at this point in the history
* Updated tf files

* updating tf code (#1)

* Create deploy.yml

* Updating deploy.yml

* Updated deploy.yml

---------

Co-authored-by: damienmwene <[email protected]>
Co-authored-by: damienmwene <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2024
1 parent fc65fa4 commit 9fb5992
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 24 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy to EC2 using AWS CLI

on:
push:
branches:
- Dev

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Install AWS CLI
run: |
sudo apt-get update
sudo apt-get install -y awscli
- name: Deploy to EC2 via SSM
run: |
aws ssm send-command \
--instance-ids "i-004aee8ed40389322" \
--document-name "AWS-RunShellScript" \
--comment "GitHub Actions EC2 deployment" \
--parameters commands='cd /var/www/html && git pull origin Dev && sudo systemctl restart httpd' \
--output text
4 changes: 4 additions & 0 deletions aws_migration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
terraform.tfstate
terraform.tfstate.backup
.terraform
.terraform.*
28 changes: 7 additions & 21 deletions aws_migration/main.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
provider "aws" {
region = "us-east-1"
}


# VPC
resource "aws_vpc" "wordpress_vpc" {
cidr_block = "10.0.0.0/16"
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Expand All @@ -14,9 +12,9 @@ resource "aws_vpc" "wordpress_vpc" {

# Subnet
resource "aws_subnet" "wordpress_subnet" {
vpc_id = aws_vpc.wordpress_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = var.availability_zone
vpc_id = aws_vpc.wordpress_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = var.availability_zone
map_public_ip_on_launch = true
}

Expand Down Expand Up @@ -71,22 +69,10 @@ resource "aws_instance" "wordpress_instance" {
instance_type = var.instance_type

subnet_id = aws_subnet.wordpress_subnet.id
security_groups = [aws_security_group.wordpress_sg.name]
security_groups = [aws_security_group.wordpress_sg.id]
associate_public_ip_address = true

user_data = <<-EOF
#!/bin/bash
yum update -y
yum install -y httpd mysql php php-mysql
systemctl start httpd
systemctl enable httpd
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* .
chown -R apache:apache /var/www/html
systemctl restart httpd
EOF
user_data = file("userdata.sh")

tags = {
Name = "bloomscoach-instance"
Expand Down
13 changes: 13 additions & 0 deletions aws_migration/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.72.0"
}
}
}

provider "aws" {
region = "us-east-1"
profile = "wp-migration"
}
11 changes: 11 additions & 0 deletions aws_migration/userdata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
yum update -y
yum install -y httpd mysql php php-mysql
systemctl start httpd
systemctl enable httpd
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* .
chown -R apache:apache /var/www/html
systemctl restart httpd
9 changes: 6 additions & 3 deletions aws_migration/variables.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
variable "ami" {
description = "The AMI ID for the EC2 instance"
type = string
default = "ami-00f251754ac5da7f0"
default = "ami-00f251754ac5da7f0"


}

variable "instance_type" {
description = "The EC2 instance type"
type = string
default = "t2.micro"
default = "t2.micro"
}

variable "availability_zone" {
description = "The availability zone for the subnet"
type = string
default = "us-east-1"
default = "us-east-1a"

}

0 comments on commit 9fb5992

Please sign in to comment.