/*
locals {
  fivetran_tags = merge(
    local.common_tags,
    {
      service                  = "fivetran",
      plat_env_project_service = "${local.aggregated_tag}_FIVETRN"
    }
  )
}

# Create subnet group for PostgreSQL in RDS
resource "aws_db_subnet_group" "fivetran" {
  name       = "${local.name_prefix}-fivetran-public-subnet-group"
  subnet_ids = module.main_public_subnets.subnet_ids
  tags       = local.fivetran_tags
}

# Create security group for PostgreSQL in RDS
resource aws_security_group sg_postgres {
  description = "Allow connection to PostgreSQL from VPC"
  vpc_id      = module.main_vpc.vpc_id

  ingress {
    description = "Access to PG from VPC"
    from_port   = 5432
    to_port     = 5432
    protocol    = "tcp"
    cidr_blocks = [module.main_vpc.vpc_cidr]
  }

  ingress {
    description = "Access to PG from VPN"
    from_port   = 5432
    to_port     = 5432
    protocol    = "tcp"
    cidr_blocks = var.vpn_servers
  }

  ingress {
    description = "Access to PG from FIVETRAN"
    from_port   = 5432
    to_port     = 5432
    protocol    = "tcp"
    cidr_blocks = ["35.234.176.144/29", "52.0.2.4/32", "35.227.135.0/29"]
  }

  ingress {
    description = "Access from databricks"
    from_port   = 5432
    to_port     = 5432
    protocol    = "tcp"
    cidr_blocks = ["10.163.0.0/16"]
  }

  tags = merge(
    local.fivetran_tags,
    {
      "Name" = format("%v-sg-postgres", local.name_prefix)
    }
  )
}

locals {
  master_password = random_id.master_password.b64
}

resource "random_id" "master_password" {
  byte_length = 30
}

module fivetran_aurora {
  source                              = "../../../modules/rds/aurora"
  name                                = "fivetran-cluster"
  name_prefix                         = local.name_prefix
  vpc_id                              = module.main_vpc.vpc_id
  db_subnet_group_name                = aws_db_subnet_group.fivetran.id
  security_groups                     = [aws_security_group.sg_postgres.id]
  instance_type                       = "db.t3.medium"
  engine                              = "aurora-postgresql"
  engine_version                      = "11.10"
  db_cluster_parameter_group_name     = ""
  db_parameter_group_name             = ""
  publicly_accessible                 = true
  apply_immediately                   = true
  username                            = "main_admin"
  performance_insights_enabled        = true
  iam_database_authentication_enabled = true
  storage_encrypted                   = true
  copy_tags_to_snapshot               = true
  common_tags = merge(
    local.common_tags,
    {
      project                  = "Data",
      service                  = "Aurora",
      description              = "Fivetran db by DLPM-527"
      plat_env_project_service = "${local.aggregated_tag}_DATA_AURA"
    }
  )
}
*/
