init
This commit is contained in:
3
s3_api/terraform/aws.tf
Normal file
3
s3_api/terraform/aws.tf
Normal file
@@ -0,0 +1,3 @@
|
||||
provider "aws" {
|
||||
region = "eu-central-1"
|
||||
}
|
||||
7
s3_api/terraform/backend.tf
Normal file
7
s3_api/terraform/backend.tf
Normal file
@@ -0,0 +1,7 @@
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "company-s3-tfstate-bucket-eu-central-1"
|
||||
region = "eu-central-1"
|
||||
key = "s3-prod-mybucket-python-testing-1234999"
|
||||
}
|
||||
}
|
||||
50
s3_api/terraform/main.tf
Normal file
50
s3_api/terraform/main.tf
Normal file
@@ -0,0 +1,50 @@
|
||||
resource "aws_s3_bucket" "bucket" {
|
||||
bucket = var.BUCKET_NAME
|
||||
|
||||
tags = {
|
||||
Name = var.BUCKET_NAME
|
||||
Environment = var.ENVIRONMENT
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_versioning" "versioning" {
|
||||
bucket = aws_s3_bucket.bucket.id
|
||||
|
||||
versioning_configuration {
|
||||
status = var.ENCRYPTED
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_public_access_block" "block_public" {
|
||||
bucket = aws_s3_bucket.bucket.id
|
||||
|
||||
block_public_acls = true
|
||||
block_public_policy = true
|
||||
ignore_public_acls = true
|
||||
restrict_public_buckets = true
|
||||
}
|
||||
|
||||
data "aws_iam_policy_document" "bucket_policy" {
|
||||
statement {
|
||||
sid = "AllowUserReadAccess"
|
||||
effect = "Allow"
|
||||
|
||||
principals {
|
||||
type = "AWS"
|
||||
identifiers = ["arn:aws:iam::848173547540:user/dummy_user"]
|
||||
}
|
||||
|
||||
actions = [
|
||||
"s3:GetObject"
|
||||
]
|
||||
|
||||
resources = [
|
||||
"${aws_s3_bucket.bucket.arn}/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_s3_bucket_policy" "bucket_policy" {
|
||||
bucket = aws_s3_bucket.bucket.id
|
||||
policy = data.aws_iam_policy_document.bucket_policy.json
|
||||
}
|
||||
19
s3_api/terraform/vars.tf
Normal file
19
s3_api/terraform/vars.tf
Normal file
@@ -0,0 +1,19 @@
|
||||
variable "BUCKET_NAME" {
|
||||
description = "Name of the bucket to create"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ENCRYPTED" {
|
||||
description = "S3 encryption enabled?"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "VERSIONING" {
|
||||
description = "S3 versioning enabled?"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "ENVIRONMENT" {
|
||||
description = "Staging or production env?"
|
||||
type = string
|
||||
}
|
||||
Reference in New Issue
Block a user