{"id":22448217,"url":"https://github.com/ridwanbejo/terraform-mysql-admin","last_synced_at":"2026-05-02T13:34:24.374Z","repository":{"id":208535052,"uuid":"721875834","full_name":"ridwanbejo/terraform-mysql-admin","owner":"ridwanbejo","description":"Terraform module for managing MySQL users, grants and databases","archived":false,"fork":false,"pushed_at":"2023-11-22T00:41:31.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-01T10:17:12.523Z","etag":null,"topics":["devops","hashicorp","hcl","iac","infrastructure-as-code","mysql","sysadmin","terraform","terraform-modules"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ridwanbejo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-22T00:37:28.000Z","updated_at":"2024-01-08T02:04:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6b58b77-abe7-48a8-96a3-e4d611f0fda4","html_url":"https://github.com/ridwanbejo/terraform-mysql-admin","commit_stats":null,"previous_names":["ridwanbejo/terraform-mysql-admin"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ridwanbejo/terraform-mysql-admin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mysql-admin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mysql-admin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mysql-admin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mysql-admin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ridwanbejo","download_url":"https://codeload.github.com/ridwanbejo/terraform-mysql-admin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridwanbejo%2Fterraform-mysql-admin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32536578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T12:25:33.646Z","status":"ssl_error","status_checked_at":"2026-05-02T12:24:51.733Z","response_time":132,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","hashicorp","hcl","iac","infrastructure-as-code","mysql","sysadmin","terraform","terraform-modules"],"created_at":"2024-12-06T04:21:54.150Z","updated_at":"2026-05-02T13:34:24.366Z","avatar_url":"https://github.com/ridwanbejo.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform MySQL Admin\n\nThis is a Terraform module for managing databases and user access at MySQL. You can use this module both for commercial or non-commercial purposes.\n\nCurrently, you can manage these resources in MySQL by using this module:\n\n- databases\n- users\n- roles\n\nTested in:\n\n- MySQL\n\n## A. Prerequisites\n\nRequirements:\n\n- Terraform with version \u003e= 1.4\n- bangau1/mysql\n- Hashicorp/random\n\n## B. How to use this module for your Terraform project ?\n\n- Copy `example` project from this module. You can extend it as per your requirements\n- Configure MySQL hostname by modifying the `providers.tf`. For example `localhost:3306`\n  - If you want to use another authentication method, [please read more at the provider documentation](https://registry.terraform.io/providers/bangau1/mysql/latest/docs)\n- Configure `TF_VAR_mysql_user` and `TF_VAR_mysql_password` as environment variables. For example:\n\n```\n$ export TF_VAR_mysql_username=root\n$ export TF_VAR_mysql_password=example\n```\n\n- Create `terraform.tfvars` inside the Project. Then copy this sample terraform.tfvars into the file:\n\n```\nmysql_databases = [\n  {\n    name                  = \"toko_mobil\"\n    default_character_set = \"utf8\"\n    default_collation     = \"utf8_general_ci\"\n  },\n  {\n    name = \"toko_baju\"\n  },\n  {\n    name = \"toko_cat\"\n  },\n  {\n    name = \"toko_jam_tangan\"\n  },\n]\n\nmysql_users = [\n  {\n    user = \"puguh\"\n    host = \"localhost\"\n    grant = {\n      database = \"toko_jam_tangan\",\n      privileges = [\"SELECT\", \"UPDATE\"]\n    }\n  },\n  {\n    user = \"panji\"\n    host = \"localhost\"\n    grant = {\n      database = \"toko_baju\",\n      privileges = [\"SELECT\", \"UPDATE\", \"DELETE\"]\n    }\n  },\n  {\n    user = \"alam\"\n    host = \"localhost\"\n    grant = {\n      database = \"toko_mobil\",\n      privileges = [\"SELECT\", \"UPDATE\", \"DELETE\", \"DROP\"]\n    }\n  },\n  {\n    user = \"jeffry\"\n    host = \"localhost\"\n    grant = {\n      database = \"\"\n      privileges = []\n    }\n  },\n]\n```\n\n- Adjust the tfvars based on your requirements. The tfvars above is just example. Then, Save it\n- Run these commands:\n\n```\n$ terraform init\n$ terraform plan\n```\nThis is the output when you run terraform plan successfully:\n\n```\n...\n\nPlan: 15 to add, 0 to change, 0 to destroy.\n\nChanges to Outputs:\n  + mysql_databases = {\n      + toko_baju       = \"utf8\"\n      + toko_cat        = \"utf8\"\n      + toko_jam_tangan = \"utf8\"\n      + toko_mobil      = \"utf8\"\n    }\n  + mysql_grants    = {\n      + alam  = [\n          + \"DELETE\",\n          + \"DROP\",\n          + \"SELECT\",\n          + \"UPDATE\",\n        ]\n      + panji = [\n          + \"DELETE\",\n          + \"SELECT\",\n          + \"UPDATE\",\n        ]\n      + puguh = [\n          + \"SELECT\",\n          + \"UPDATE\",\n        ]\n    }\n  + mysql_users     = {\n      + alam   = \"localhost\"\n      + jeffry = \"localhost\"\n      + panji  = \"localhost\"\n      + puguh  = \"localhost\"\n    }\n\n```\n\nAfter you feel confidence with the terraform plan output, let's apply it.\n\n```\n$ terraform apply -auto-approve\n```\n\n- If it succeed, you must see this kind of output on your terminal\n\n```\n...\n\nmodule.tf_mysql_admin.mysql_grant.grants[\"puguh\"]: Creating...\nmodule.tf_mysql_admin.mysql_grant.grants[\"alam\"]: Creating...\nmodule.tf_mysql_admin.mysql_grant.grants[\"panji\"]: Creating...\nmodule.tf_mysql_admin.mysql_grant.grants[\"puguh\"]: Creation complete after 3s [id=puguh@localhost:`toko_jam_tangan`]\nmodule.tf_mysql_admin.mysql_grant.grants[\"panji\"]: Creation complete after 3s [id=panji@localhost:`toko_baju`]\nmodule.tf_mysql_admin.mysql_grant.grants[\"alam\"]: Creation complete after 3s [id=alam@localhost:`toko_mobil`]\n\nApply complete! Resources: 15 added, 0 changed, 0 destroyed.\n\nOutputs:\n\nmysql_databases = {\n  \"toko_baju\" = \"utf8\"\n  \"toko_cat\" = \"utf8\"\n  \"toko_jam_tangan\" = \"utf8\"\n  \"toko_mobil\" = \"utf8\"\n}\nmysql_grants = {\n  \"alam\" = toset([\n    \"DELETE\",\n    \"DROP\",\n    \"SELECT\",\n    \"UPDATE\",\n  ])\n  \"panji\" = toset([\n    \"DELETE\",\n    \"SELECT\",\n    \"UPDATE\",\n  ])\n  \"puguh\" = toset([\n    \"SELECT\",\n    \"UPDATE\",\n  ])\n}\nmysql_users = {\n  \"alam\" = \"localhost\"\n  \"jeffry\" = \"localhost\"\n  \"panji\" = \"localhost\"\n  \"puguh\" = \"localhost\"\n}\n```\n\nYou will see at your MySQL that users and databases are created once the terraform applied.\n\n## C. Understanding tfvars scenarios\n\nThere are some scenarios that you could choose by using this module. For example:\n\n1. You might want to create the database with default collation and charset:\n\n```\nmysql_databases = [\n  {\n    name = \"toko_jam_tangan\"\n  },\n]\n```\n\n2. You can also create database by with different collation and charset:\n\n```\nmysql_databases = [\n  {\n    name                  = \"toko_mobil\"\n    default_character_set = \"utf8\"\n    default_collation     = \"utf8_general_ci\"\n  },\n  {\n    name = \"toko_baju\"\n  },\n  {\n    name = \"toko_cat\"\n  },\n  {\n    name = \"toko_jam_tangan\"\n  },\n]\n```\n\n3. You can create user without grant\n\n```\nmysql_users = [\n  {\n    user = \"jeffry\"\n    host = \"localhost\"\n    grant = {\n      database = \"\"\n      privileges = []\n    }\n  },\n]\n```\n\n4. You can create users with grant option also\n\n```\nmysql_users = [\n  {\n    user = \"puguh\"\n    host = \"localhost\"\n    grant = {\n      database = \"toko_jam_tangan\",\n      privileges = [\"SELECT\", \"UPDATE\"]\n    }\n  },\n  {\n    user = \"panji\"\n    host = \"localhost\"\n    grant = {\n      database = \"toko_baju\",\n      privileges = [\"SELECT\", \"UPDATE\", \"DELETE\"]\n    }\n  },\n  {\n    user = \"alam\"\n    host = \"localhost\"\n    grant = {\n      database = \"toko_mobil\",\n      privileges = [\"SELECT\", \"UPDATE\", \"DELETE\", \"DROP\"]\n    }\n  },\n]\n```\n\n## D. Ensuring quality\n\nI am trying to follow these approaches for ensuring quality of the tf-module:\n\n- **validate**, ensure my Terraform module is in correct configuration based on Terraform guideline\n- **auto-format**, ensure my Terraform script is edited with correct format based on Terraform guideline\n- **linter**, ensure my Terraform script is in correct format based on Terraform guideline\n- **security**, ensure my Terraform module is free from CVE and stay compliance\n- **automation**, run all above steps by using automation tool to improve development time and keep best quality before or after merging to Git repository\n\n\nThe tools:\n\n- [terraform validate](https://developer.hashicorp.com/terraform/cli/commands)\n- [terraform fmt](https://developer.hashicorp.com/terraform/cli/commands)\n- [tflint](https://github.com/terraform-lint48ers/tflint)\n- [tfsec](https://github.com/aquasecurity/tfsec)\n- [Pre-commit](https://pre-commit.com/)\n- Github Action [Setup Terraform pipeline](https://github.com/hashicorp/setup-terraform)\n\n## E. How to contribute ?\n\nIf you find any issue, you can raise it here at our [Issue Tracker](https://github.com/ridwanbejo/terraform-mysql-admin/issues)\n\nIf you have something that you want to merge to this repo, just raise [Pull Requests](https://github.com/ridwanbejo/terraform-mysql-admin/pulls)\n\nEnsure that you install all the tools from section D. for development purpose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridwanbejo%2Fterraform-mysql-admin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fridwanbejo%2Fterraform-mysql-admin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridwanbejo%2Fterraform-mysql-admin/lists"}