module "default_tags" {
  source             = "git@github.com:theorchard/terraform-default-tags.git//?ref=2.0.0"
  environment        = var.environment
  application_family = var.application_family
  service_name       = var.service_name
  team_name          = var.team_name
}

provider "aws" {
  region = var.aws_region

  default_tags {
    tags = module.default_tags.tags
  }
}

# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket  = "dev-media-conversion-terraform-state"
    key     = "dev/reserved-instances/terraform.tfstate"
    region  = "eu-central-1"
    encrypt = true
  }
}

data "aws_rds_reserved_instance_offering" "db_m5_xlarge_reserved_instance_offering" {
  db_instance_class   = "db.m5.xlarge"
  duration            = 1
  offering_type       = "No Upfront"
  product_description = "sqlserver-se(li)"
  multi_az            = false
}

data "aws_rds_reserved_instance_offering" "db_m5_xlarge_custom_reserved_instance_offering" {
  db_instance_class   = "db.m5.xlarge"
  duration            = 1
  offering_type       = "No Upfront"
  product_description = "custom-sqlserver-se(li)"
  multi_az            = false
}

data "aws_rds_reserved_instance_offering" "db_t3_micro_reserved_instance_offering" {
  db_instance_class   = "db.t3.micro"
  duration            = 1
  offering_type       = "No Upfront"
  product_description = "postgresql"
  multi_az            = false
}

data "aws_rds_reserved_instance_offering" "db_r5_large_reserved_instance_offering" {
  db_instance_class   = "db.r5.large"
  duration            = 1
  offering_type       = "No Upfront"
  product_description = "aurora-postgresql"
  multi_az            = false
}

# Reserved RDS Instance for SQL Server SE (LI) db.m5.xlarge instance for 1 year with No Upfront payment option
# 1-year No Upfront commitment for cost optimization
resource "aws_rds_reserved_instance" "rds_m5_xlarge_reserved_instance" {
  offering_id    = data.aws_rds_reserved_instance_offering.db_m5_xlarge_reserved_instance_offering.offering_id
  reservation_id = "sqlserver-se-m5-xlarge-2026-06-12"
  instance_count = 1
}

# Reserved RDS Instance for RDS Custom SQL Server SE (LI) db.m5.xlarge instance for 1 year with No Upfront payment option
# 1-year No Upfront commitment for cost optimization
resource "aws_rds_reserved_instance" "rds_m5_xlarge_custom_reserved_instance" {
  offering_id    = data.aws_rds_reserved_instance_offering.db_m5_xlarge_custom_reserved_instance_offering.offering_id
  reservation_id = "custom-sqlserver-se-m5-xlarge-2026-06-12"
  instance_count = 1
}

# Reserved RDS Instance for PostgreSQL db.t3.micro instance for 1 year with No Upfront payment option
# 1-year No Upfront commitment for cost optimization
resource "aws_rds_reserved_instance" "rds_t3_micro_reserved_instance" {
  offering_id = data.aws_rds_reserved_instance_offering.db_t3_micro_reserved_instance_offering.offering_id
  reservation_id = "postgresql-t3-micro-2026-06-12"
  instance_count = 8
}

# Reserved RDS Instances for Aurora PostgreSQL db.r5.large instance for 1 year with No Upfront payment option
# 1-year No Upfront commitment for cost optimization
resource "aws_rds_reserved_instance" "rds_r5_large_reserved_instance" {
  offering_id = data.aws_rds_reserved_instance_offering.db_r5_large_reserved_instance_offering.offering_id
  reservation_id = "aurora-postgresql-r5-large-2026-06-12"
  instance_count = 1
}
