Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DMVP-6480): ProxySQL setup on RDS #21

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions modules/proxysql/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
resource "helm_release" "proxysql" {
name = var.name
chart = "christianhuth/proxysql"
repository = "proxysql"
namespace = var.namespace

values = [
templatefile(
"${path.module}/values.yaml",
{
replica_count = var.proxysql_config.replicas
proxysql_admin_user = var.proxysql_config.username
proxysql_admin_password = var.proxysql_config.password
mysql_max_connections = var.mysql_config.max_connections
mysql_query_retries = var.mysql_config.query_retries
mysql_wait_timeout = var.mysql_config.timeout
mysql_server_hostname = var.mysql_config.hostname
mysql_server_port = var.mysql_config.port
mysql_server_hostgroup = var.mysql_config.hostgroup
mysql_server_max_connections = var.mysql_config.server_max_connections
mysql_user_username = var.mysql_config.username
mysql_user_password = var.mysql_config.password
mysql_user_default_hostgroup = var.mysql_config.default_hostgroup
mysql_user_max_connections = var.mysql_config.user_max_connections
readwritesplit = var.mysql_config.readwritesplit
}
)
]

depends_on = [
kubernetes_namespace.proxysql
]
}

resource "kubernetes_namespace" "proxysql" {
metadata {
name = var.namespace
}
}
30 changes: 30 additions & 0 deletions modules/proxysql/tests/basic/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
locals {
eks_name = "eks"
}

module "proxysql" {
source = "../../"

name = "proxysql"

proxysql_config = {
replicas = 2
username = "proxysqladmin"
password = "proxysqladmin"
}

mysql_config = {
max_connections = 20480
query_retries = 5
timeout = 28800000
hostname = "<hostname>.<region>.rds.amazonaws.com"
port = 3306
hostgroup = 1
server_max_connections = 10000
username = "admin"
password = "admin"
readwritesplit = false
default_hostgroup = 1
user_max_connections = 10000
}
}
21 changes: 21 additions & 0 deletions modules/proxysql/tests/basic/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
data "aws_eks_cluster" "this" {
name = local.eks_name
}

data "aws_eks_cluster_auth" "this" {
name = local.eks_name
}

provider "helm" {
kubernetes {
host = data.aws_eks_cluster.this.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.this.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.this.token
}
}

provider "kubernetes" {
host = data.aws_eks_cluster.this.endpoint
cluster_ca_certificate = base64decode(data.aws_eks_cluster.this.certificate_authority[0].data)
token = data.aws_eks_cluster_auth.this.token
}
30 changes: 30 additions & 0 deletions modules/proxysql/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
replicaCount: ${replica_count}

proxysql:
admin:
user: "${proxysql_admin_user}"
password: "${proxysql_admin_password}"

mysql:
maxConnections: ${mysql_max_connections}
queryRetriesOnFailure: ${mysql_query_retries}
wait_timeout: ${mysql_wait_timeout}
readWriteSplit: ${readwritesplit}
servers:
- hostname: "${mysql_server_hostname}"
port: ${mysql_server_port}
hostgroup: ${mysql_server_hostgroup}
maxConnections: ${mysql_server_max_connections}
users:
- username: "${mysql_user_username}"
password: "${mysql_user_password}"
defaultHostgroup: ${mysql_user_default_hostgroup}
maxConnections: ${mysql_user_max_connections}

service:
type: ClusterIP
ports:
admin:
port: 6032
mysql:
port: 6033
40 changes: 40 additions & 0 deletions modules/proxysql/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
variable "name" {
type = string
description = "Name"
}

variable "namespace" {
type = string
description = "Namespace"
default = "proxysql"
}

variable "proxysql_config" {
type = any
default = {
replicas = 2
username = "admin"
password = "admin"
}
description = "ProxySQL configuration, including replicas and admin credentials."
}


variable "mysql_config" {
type = any
default = {
max_connections = 20480
query_retries = 5
timeout = 28800000
hostname = ""
port = 3306
hostgroup = 1
server_max_connections = 10000
username = "admin"
password = "admin"
default_hostgroup = 1
user_max_connections = 20480
readwritesplit = false
}
description = "MySQL configuration, including connections, retries, and optional server/user details."
}
19 changes: 19 additions & 0 deletions modules/proxysql/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_version = ">= 0.15.0"

required_providers {
aws = {
source = "hashicorp/aws"
}

helm = {
source = "hashicorp/helm"
version = "~> 2.4.0"
}

kubernetes = {
source = "hashicorp/kubernetes"
version = "2.12.1"
}
}
}
Loading