Skip to content

Commit

Permalink
terraform for s3
Browse files Browse the repository at this point in the history
  • Loading branch information
farzaneh-haghani committed Mar 5, 2024
1 parent f1ef00e commit 31477f2
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Docker.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy on AWS EC2
name: Deploy on AWS EC2 By Docker

on:
push:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jobs:
echo "AWS_REGION=us-east-1" >> "$GITHUB_ENV"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Upload to S3
run: aws s3 sync ./build s3://cyf-video-hub --delete
run: aws s3 sync ./build s3://video-hub-terraform --delete
13 changes: 0 additions & 13 deletions client/src/index.css

This file was deleted.

1 change: 0 additions & 1 deletion client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";

ReactDOM.render(
Expand Down
12 changes: 12 additions & 0 deletions terraform/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.27.0"
}
}
}

provider "aws" {
region = "us-east-1"
}
4 changes: 4 additions & 0 deletions terraform/s3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.terraform/
.terraform.*
*.tfstate
*.tfstate.*
47 changes: 47 additions & 0 deletions terraform/s3/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ------------------------- Creating bucket -------------------------
resource "aws_s3_bucket" "video_bucket" {
bucket = "video-hub-terraform" //Should be unique name
}


# ------------------------- Making it public -------------------------
resource "aws_s3_bucket_public_access_block" "video_bucket" {
bucket = aws_s3_bucket.video_bucket.id

block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}


# ------------------------- Adding policy to bucket -------------------------
resource "aws_s3_bucket_policy" "video_bucket" {
bucket = aws_s3_bucket.video_bucket.id

policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Sid" : "PublicReadGetObject",
"Effect" : "Allow",
"Principal" : "*",
"Action" : "s3:GetObject",
"Resource" : "${aws_s3_bucket.video_bucket.arn}/*"
}
]
})
}


# ------------------------- Making it as a static website hosting -------------------------
resource "aws_s3_bucket_website_configuration" "video_bucket" {
bucket = aws_s3_bucket.video_bucket.id

index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
}

0 comments on commit 31477f2

Please sign in to comment.