-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Default encryption is enabled on S3 bucket. The RDS instance is a postgres14 instance on `db.t3.micro` instance with a random generated password. Public access to both RDS and S3 are blocked, with the RDS instance being deployed on the private subnet.
- Loading branch information
1 parent
439ca22
commit f4732c5
Showing
18 changed files
with
267 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/bash | ||
|
||
cd /home/ubuntu/webapp || exit | ||
touch .env | ||
|
||
{ | ||
echo "ENVIRONMENT=$ENVIRONMENT" | ||
echo "PORT=1337" | ||
echo "DATABASE=$DATABASE" | ||
echo "HOSTNAME=localhost" | ||
echo "DBUSER=$DBUSER" | ||
echo "DBPASSWORD=$DBPASSWORD" | ||
} >>.env | ||
|
||
sudo systemctl enable nodeserver.service | ||
sudo systemctl start nodeserver.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password | ||
resource "random_password" "dbpassword" { | ||
length = 16 | ||
special = false | ||
} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_subnet_group | ||
resource "aws_db_subnet_group" "db_subnet_group" { | ||
name = "db-subnet-group" | ||
subnet_ids = [var.private_subnets_id[0], var.private_subnets_id[1]] | ||
|
||
tags = { | ||
"Name" = "${var.environment}-db-subnet-group" | ||
} | ||
} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_parameter_group | ||
# https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Appendix.PostgreSQL.CommonDBATasks.html#Appendix.PostgreSQL.CommonDBATasks.Parameters | ||
resource "aws_db_parameter_group" "db_parameter_group" { | ||
name = "rds-psql-pg" | ||
family = "postgres14" | ||
} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/db_instance | ||
resource "aws_db_instance" "database" { | ||
allocated_storage = 10 | ||
db_name = var.database | ||
# https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html#API_CreateDBInstance_RequestParameters | ||
engine = "postgres" | ||
engine_version = "14" | ||
instance_class = "db.t3.micro" | ||
username = var.dbuser | ||
password = random_password.dbpassword.result | ||
parameter_group_name = aws_db_parameter_group.db_parameter_group.name | ||
skip_final_snapshot = true | ||
multi_az = false | ||
vpc_security_group_ids = [var.db_sg_id] | ||
db_subnet_group_name = aws_db_subnet_group.db_subnet_group.name | ||
# TODO: Encrypt storage with KMS | ||
storage_encrypted = false | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "dbpassword" { | ||
value = random_password.dbpassword.result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variable "environment" {} | ||
variable "database" {} | ||
variable "dbuser" {} | ||
variable "private_subnets_id" {} | ||
variable "db_sg_id" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/uuid | ||
resource "random_uuid" "uuid" {} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket | ||
resource "aws_s3_bucket" "bucket" { | ||
bucket = random_uuid.uuid.result | ||
force_destroy = true | ||
|
||
tags = { | ||
"Name" = "${var.environment}-s3-bucket" | ||
} | ||
} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration | ||
resource "aws_s3_bucket_lifecycle_configuration" "s3_bucket_lifecycle_config" { | ||
bucket = aws_s3_bucket.bucket.id | ||
|
||
rule { | ||
id = "rule-1" | ||
status = "Enabled" | ||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration#transition | ||
transition { | ||
days = 30 | ||
storage_class = "STANDARD_IA" | ||
} | ||
} | ||
} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration | ||
resource "aws_s3_bucket_server_side_encryption_configuration" "s3_bucket_encryption" { | ||
bucket = aws_s3_bucket.bucket.id | ||
|
||
rule { | ||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_server_side_encryption_configuration#apply_server_side_encryption_by_default | ||
apply_server_side_encryption_by_default { | ||
sse_algorithm = "AES256" | ||
} | ||
} | ||
} | ||
|
||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block | ||
resource "aws_s3_bucket_public_access_block" "s3_bucket_public_access" { | ||
bucket = aws_s3_bucket.bucket.id | ||
block_public_acls = true | ||
block_public_policy = true | ||
ignore_public_acls = true | ||
restrict_public_buckets = true | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
variable "environment" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
output "api_sg_id" { | ||
value = aws_security_group.api_sg.id | ||
} | ||
|
||
output "db_sg_id" { | ||
value = aws_security_group.db_sg.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters