data "fivetran_group" "prod_warehouse" {
    id = "gentry_invitro"
}

resource "fivetran_connector" "royalty_accounting_connector" {
  group_id = data.fivetran_group.prod_warehouse.id
  service  = "aurora"

  destination_schema {
    prefix = "uat_royalty_accounting"
  }

  config {
    host             = module.royalty_accounting_rds.rds_cluster_endpoint
    port             = module.royalty_accounting_rds.rds_cluster_port
    user             = "fivetran"
    database         = "royalty_accounting"
    tunnel_host      = "uat-fivetran.qa-accounting.theorchard.io"
    tunnel_port      = "2222"
    tunnel_user      = "fivetran"
  }
}

resource "fivetran_connector_schedule" "royalty_accounting_connector" {
  connector_id      = fivetran_connector.royalty_accounting_connector.id
  sync_frequency    = 1
  pause_after_trial = false
}

resource "fivetran_connector_schema_config" "royalty_accounting_connector" {
  connector_id           = fivetran_connector.royalty_accounting_connector.id
  schema_change_handling = "ALLOW_COLUMNS"
  schemas = {
    "royalty_accounting" = {
      enabled = true
      tables = { for table in var.tables_to_sync_to_snowflake : table => {
        enabled   = true
        sync_mode = "SOFT_DELETE"
      }}
    }
  }
}
