diff --git a/deployment/main.tf b/deployment/main.tf index 258df7a..d5fbc03 100644 --- a/deployment/main.tf +++ b/deployment/main.tf @@ -15,7 +15,11 @@ terraform { required_version = ">= 1.2.0" } -provider "aws" { - profile = var.profile - region = var.region -} +resource "aws_db_subnet_group" "my_db_subnet_group" { + name = "my-db-subnet-group" + subnet_ids = [aws_subnet.subnet_a.id, aws_subnet.subnet_b.id] + + tags = { + Name = "My DB Subnet Group" + } +} \ No newline at end of file diff --git a/deployment/provider.tf b/deployment/provider.tf new file mode 100644 index 0000000..77cc515 --- /dev/null +++ b/deployment/provider.tf @@ -0,0 +1,47 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.16" + } + } + backend "s3" { + bucket = "survey-extractor-terraform-state" + region = "eu-north-1" + profile = "domna.dev" # /home/vscode/aws/credentials + key = "terraform.tfstate" + } + + required_version = ">= 1.2.0" +} + +resource "aws_db_subnet_group" "my_db_subnet_group" { + name = "my-db-subnet-group" + subnet_ids = [aws_subnet.subnet_a.id, aws_subnet.subnet_b.id] + + tags = { + Name = "My DB Subnet Group" + } +} + +resource aws_db_instance "main" { + allocated_storage = var.allocated_storage + engine = "postgres" + engine_version = "14.10" + instance_class = "db.t3.micro" + db_name = "surveyDB" + username = postgres + password = makingwarmhomes + + skip_final_snapshot = true # Needed to delete the db with terraform - otherwise aws will keep a copy + + vpc_security_group_ids = [aws_security_group.rds_sg.id] + db_subnet_group_name = aws_db_subnet_group.my_db_subnet_group.name +} + + + +provider "aws" { + profile = var.profile + region = var.region +} diff --git a/deployment/variables.tf b/deployment/variables.tf index 12dee3f..6f454ad 100644 --- a/deployment/variables.tf +++ b/deployment/variables.tf @@ -8,4 +8,10 @@ variable "profile" { description = "AWS profile to use" type = string default = "Jun-te" +} + +variable allocated_storage { + description = "The allocated storage in gigabytes" + type = number + default = 20 } \ No newline at end of file diff --git a/deployment/vpc.tf b/deployment/vpc.tf new file mode 100644 index 0000000..21f2780 --- /dev/null +++ b/deployment/vpc.tf @@ -0,0 +1,29 @@ +resource "aws_vpc" "my_vpc" { + cidr_block = "10.0.0.0/16" +} + +resource "aws_subnet" "subnet_a" { + vpc_id = aws_vpc.my_vpc.id + cidr_block = "10.0.1.0/24" + availability_zone = "eu-central-1a" +} + +resource "aws_subnet" "subnet_b" { + vpc_id = aws_vpc.my_vpc.id + cidr_block = "10.0.2.0/24" + availability_zone = "eu-central-1b" +} + +resource "aws_security_group" "rds_sg" { + name_prefix = "rds-" + + vpc_id = aws_vpc.my_vpc.id + + # Add any additional ingress/egress rules as needed + ingress { + from_port = 3306 + to_port = 9000 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } +} \ No newline at end of file