added terraform things

This commit is contained in:
Jun-te Kim 2025-03-31 14:52:13 +00:00
parent 39c29f2ac2
commit 665f4da567
4 changed files with 90 additions and 4 deletions

View file

@ -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"
}
}

47
deployment/provider.tf Normal file
View file

@ -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
}

View file

@ -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
}

29
deployment/vpc.tf Normal file
View file

@ -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"]
}
}