Skip to content

Commit

Permalink
Merge pull request #13 from kabisa/feat/add-S3bucket-and-DynamoDB
Browse files Browse the repository at this point in the history
Feat/add S3 bucket and Dynamodb Tables
  • Loading branch information
anasgrt authored Dec 15, 2023
2 parents 4d352c3 + 9d4a51c commit f77799d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
17 changes: 17 additions & 0 deletions dynamodb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Terraform State dynamodb table
resource "aws_dynamodb_table" "kabisa_terraform_lockfiles_dynamodb_table" {
count = var.dynamodb_tables_creation ? 1 : 0
name = var.dynamodb_tables_name
read_capacity = 5
write_capacity = 5
hash_key = "LockID"

attribute {
name = "LockID"
type = "S"
}

tags = {
Terraform = true
}
}
42 changes: 42 additions & 0 deletions s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Terraform State S3 buacket
resource "aws_s3_bucket" "kabisa_terraform_statefiles_bucket" {
count = var.s3_bucket_state_file_creation ? 1 : 0
bucket = var.s3_bucket_state_file_name

tags = {
Terraform = true
}
}

resource "aws_s3_bucket_acl" "s3_bucket_private_acl" {
count = var.s3_bucket_state_file_creation ? 1 : 0
bucket = aws_s3_bucket.kabisa_terraform_statefiles_bucket[count.index].id
acl = "private"
depends_on = [aws_s3_bucket_ownership_controls.s3_bucket_acl_ownership]
}

resource "aws_s3_bucket_ownership_controls" "s3_bucket_acl_ownership" {
count = var.s3_bucket_state_file_creation ? 1 : 0
bucket = aws_s3_bucket.kabisa_terraform_statefiles_bucket[count.index].id
rule {
object_ownership = "ObjectWriter"
}
}

resource "aws_s3_bucket_versioning" "versioning_bucket" {
count = var.s3_bucket_state_file_creation ? 1 : 0
bucket = aws_s3_bucket.kabisa_terraform_statefiles_bucket[count.index].id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_server_side_encryption_configuration" "s3_bucket_encrypt_rule" {
count = var.s3_bucket_state_file_creation ? 1 : 0
bucket = aws_s3_bucket.kabisa_terraform_statefiles_bucket[count.index].id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
24 changes: 24 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,27 @@ variable "cloudwatch_encryption_enabled" {
description = "(Optional) Encrypt log data."
}

variable "s3_bucket_state_file_creation" {
type = bool
default = false
description = "Whether to create S3 bucket in the AWS Account to store terraform state file"
}

variable "s3_bucket_state_file_name" {
type = string
default = ""
description = "The S3 bucket name which store the terraform state file"
}

variable "dynamodb_tables_creation" {
type = bool
default = false
description = "Whether to create dynamodb tables for terraform state file"
}

variable "dynamodb_tables_name" {
type = string
default = ""
description = "The dynamodb tables name"
}

0 comments on commit f77799d

Please sign in to comment.