LoginSignup
2
1

More than 1 year has passed since last update.

RDS内のデータベースやユーザーをterraformで管理する

Posted at

Mysql Provider

とういうものがあって便利

ポートフォワード

ssh -i develop.key ec2-user@i-aaaaaaaaaaaaaaa -L 33061:aiuo.cluster-xxxxxxxx.ap-northeast-1.rds.amazonaws.com:3306

terraform

# Configure the MySQL provider
provider "mysql" {
  endpoint = "127.0.0.1:33061"
  username = "admin"
  password = "password"
}

# Create a Database
resource "mysql_database" "app" {
  name = "my_awesome_app"
}

# Create user
resource "mysql_user" "sample" {
  user  = "sample"
  host  = "%"
  plaintext_password = "password"
}

# Grant User
resource "mysql_grant" "sample" {
  user       = mysql_user.sample.user
  host       = mysql_user.sample.host
  database   = "sample"
  table      = "*"
  privileges = ["SELECT", "INSERT", "UPDATE", "DELETE"]
}

terraform {
  required_providers {
    mysql = {
      source = "terraform-providers/mysql"
      version = "1.9.0"
    }
  }
}

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1