Skip to content

Commit

Permalink
Create s3 bucket in terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
vilnor committed May 17, 2024
1 parent bea98e0 commit 87b70aa
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,43 @@ resource "aws_security_group" "unibasement_database" {
//////////////////////////////// Database //////////////////////////////////////


resource "aws_s3_bucket" "unibasement_images" {
bucket = "unibasement-images"

tags = {
Name = "UniBasement Images"
}
}

resource "aws_s3_bucket_public_access_block" "unibasement_images" {
bucket = aws_s3_bucket.unibasement_images.id

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

data "aws_iam_policy_document" "public_read" {
statement {
sid = "PublicReadGetObject"
effect = "Allow"

principals {
type = "AWS"
identifiers = ["*"]
}

actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::${aws_s3_bucket.unibasement_images.bucket}/*"]
}
}

resource "aws_s3_bucket_policy" "unibasement_images" {
bucket = aws_s3_bucket.unibasement_images.id
policy = data.aws_iam_policy_document.public_read.json
depends_on = [aws_s3_bucket_public_access_block.unibasement_images]
}

//////////////////////////////// Frontend //////////////////////////////////////
resource "docker_image" "unibasement_frontend" {
Expand Down Expand Up @@ -320,6 +356,7 @@ resource "aws_ecs_task_definition" "unibasement_backend" {
cpu = 4096
memory = 12288
execution_role_arn = data.aws_iam_role.lab.arn
task_role_arn = data.aws_iam_role.lab.arn

container_definitions = <<DEFINITION
[
Expand Down Expand Up @@ -362,6 +399,18 @@ resource "aws_ecs_task_definition" "unibasement_backend" {
{
"name": "DB_PORT",
"value": "5432"
},
{
"name": "S3_BUCKET_NAME",
"value": "${aws_s3_bucket.unibasement_images.bucket}"
},
{
"name": "S3_BUCKET_URL",
"value": "${aws_s3_bucket.unibasement_images.bucket_regional_domain_name}"
},
{
"name": "AWS_REGION",
"value": "us-east-1"
}
]
}
Expand Down

0 comments on commit 87b70aa

Please sign in to comment.