# Terraform backends cannot contain interpolations
terraform {
  backend "s3" {
    bucket  = "dev-orcd-terraform-state"
    key     = "dev/terraform-mysql/test/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

# Configure the MySQL provider for AWS RDS with AWS IAM authentication enabled
provider "mysql" {
  endpoint = "aws://dev-terraform-mysql-test.cluster-co2yckwm6hcp.us-east-1.rds.amazonaws.com"
  username = "admin" # username = "atlantis" if running in terraform-infra. This username should already exist in the RDS instance
  tls      = true
}

module "test" {
  source = "../"

  # Roles are automatically created once module is initialized.
  # Example of creating read, and write users that are associated with the read, and write roles.

  read_only_users = [
    {
      user = "test_user_1"
      auth_plugin = "caching_sha2_password"
      host_identifier = "%"
    },
  ]

  read_write_users = [
    {
      user = "test_user_2"
      auth_plugin = "AWSAuthenticationPlugin"
      host_identifier = "192.168.40.0/22"
    },
  ]

  custom_roles = {
    custom_role_1 = {
      name       = "custom_role_1"
      privileges = ["SELECT", "SHOW VIEW", "USAGE"]
    },
    custom_role_2 = {
      name       = "custom_role_2"
      privileges = ["SELECT", "SHOW VIEW", "USAGE"]
    }
  }

  custom_role_users = [
    {
      user = "custom_user_1"
      auth_plugin = "caching_sha2_password"
      host_identifier = "%"
      roles = ["custom_role_1"]
    },
    {
      user = "custom_user_2"
      auth_plugin = "AWSAuthenticationPlugin"
      host_identifier = "192.168.40.0/22"
      roles = ["custom_role_2"]
    }
  ]
}
