From 7961b94fe8f102640b745a51ea66008e316fc2b4 Mon Sep 17 00:00:00 2001 From: Wellyson Freitas Date: Sat, 16 Mar 2024 08:37:13 +0100 Subject: [PATCH 1/2] Change instance class --- terraform/rds.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/rds.tf b/terraform/rds.tf index 529ea63..c7e5109 100644 --- a/terraform/rds.tf +++ b/terraform/rds.tf @@ -4,7 +4,7 @@ resource "aws_db_instance" "default" { identifier = "selfordermanagement" engine = "postgres" engine_version = "15.6" - instance_class = "db.t2.micro" + instance_class = "db.t3.micro" parameter_group_name = "default.postgres15" username = "master" From af27ebff8168aa84ceea2e612390aefb7cf4737c Mon Sep 17 00:00:00 2001 From: Wellyson Freitas Date: Sat, 16 Mar 2024 09:56:21 +0100 Subject: [PATCH 2/2] Change instance class --- .../workflows/{rds.yml => provisioning.yml} | 10 +-- terraform/main.tf | 62 +++++++++++++++++++ terraform/providers.tf | 2 +- terraform/rds.tf | 16 ----- 4 files changed, 68 insertions(+), 22 deletions(-) rename .github/workflows/{rds.yml => provisioning.yml} (87%) create mode 100644 terraform/main.tf delete mode 100644 terraform/rds.tf diff --git a/.github/workflows/rds.yml b/.github/workflows/provisioning.yml similarity index 87% rename from .github/workflows/rds.yml rename to .github/workflows/provisioning.yml index dafb901..9ffe479 100644 --- a/.github/workflows/rds.yml +++ b/.github/workflows/provisioning.yml @@ -1,21 +1,21 @@ -name: "RDS" +name: "Provisioning" on: push: branches: - main paths: - - .github/workflows/rds.yml + - .github/workflows/provisioning.yml - 'terraform/**' pull_request: branches: - main paths: - - .github/workflows/rds.yml + - .github/workflows/provisioning.yml - 'terraform/**' jobs: - rds: + provisioning: runs-on: ubuntu-latest defaults: run: @@ -62,5 +62,5 @@ jobs: run: exit 1 - name: Terraform Apply - if: github.ref == 'refs/heads/main' && github.event_name == 'push' + #if: github.ref == 'refs/heads/main' && github.event_name == 'push' run: terraform apply -auto-approve -input=false diff --git a/terraform/main.tf b/terraform/main.tf new file mode 100644 index 0000000..e663f5a --- /dev/null +++ b/terraform/main.tf @@ -0,0 +1,62 @@ +locals { + name = "selfordermanagementdb" +} + +data "terraform_remote_state" "tech-challenge" { + backend = "s3" + + config = { + bucket = "fiap-3soat-g15-infra-tech-challenge-state" + key = "live/terraform.tfstate" + region = var.region + } +} + +module "db" { + source = "terraform-aws-modules/rds/aws" + version = "6.5.2" + + identifier = local.name + + engine = "postgres" + engine_version = "15" + family = "postgres15" + major_engine_version = "15" + instance_class = "db.t3.micro" + + allocated_storage = 10 + max_allocated_storage = 20 + + storage_encrypted = false + + db_name = local.name + username = "master" + port = 5432 + + manage_master_user_password = true + + multi_az = false + db_subnet_group_name = data.terraform_remote_state.tech-challenge.outputs.database_subnet_group_name + vpc_security_group_ids = [module.security_group.security_group_id] + + backup_retention_period = 0 + skip_final_snapshot = true + deletion_protection = false +} + +module "security_group" { + source = "terraform-aws-modules/security-group/aws" + version = "~> 5.0" + + name = local.name + vpc_id = data.terraform_remote_state.tech-challenge.outputs.vpc_id + + ingress_with_cidr_blocks = [ + { + from_port = 5432 + to_port = 5432 + protocol = "tcp" + cidr_blocks = data.terraform_remote_state.tech-challenge.outputs.vpc_cidr_block + }, + ] +} diff --git a/terraform/providers.tf b/terraform/providers.tf index 82e21c3..fe687ee 100644 --- a/terraform/providers.tf +++ b/terraform/providers.tf @@ -2,7 +2,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = "~> 5.0.0" + version = ">= 5.36" } } diff --git a/terraform/rds.tf b/terraform/rds.tf deleted file mode 100644 index c7e5109..0000000 --- a/terraform/rds.tf +++ /dev/null @@ -1,16 +0,0 @@ -resource "aws_db_instance" "default" { - allocated_storage = 10 - db_name = "selfordermanagement" - identifier = "selfordermanagement" - engine = "postgres" - engine_version = "15.6" - instance_class = "db.t3.micro" - parameter_group_name = "default.postgres15" - - username = "master" - manage_master_user_password = true - - multi_az = false - backup_retention_period = 0 - skip_final_snapshot = true -}