Terraform: How to run a command after an RDS creation?

I wanted to know how to run a command after creating an RDS instance with Terraform. This was the answer I got from AWS. Even though, Terraform shouldn’t be used like this.

nn

resource "aws_db_instance" "mydb" {n  engine         = "mysql"n  engine_version = "5.6.40"n  instance_class = "db.t1.micro"n  name           = "initial_db"n  username       = "example"n  password       = "1234"n  allocated_storage = "20"n  publicly_accessible = "true"n}nnoutput "username" {n    value = "${aws_db_instance.mydb.username}"n}nnoutput "address" {n    value = "${aws_db_instance.mydb.address}"n}nnresource "null_resource" "test" {n  depends_on = ["aws_db_instance.mydb"] #wait for the db to be readyn  provisioner "local-exec" {n    command = "mysql -u ${aws_db_instance.mydb.username} -p${aws_db_instance.mydb.password} -h ${aws_db_instance.mydb.address} -e \"CALL mysql.rds_set_configuration('binlog retention hours', 24);\" "n  }n}n

nn

Gists

nn

nn

Tags

nn

    n

  • rds
  • n

  • Amazon
  • n

  • terraform
  • n

n

Proudly powered by WordPress

Discover more from Dedunu

Subscribe now to keep reading and get access to the full archive.

Continue reading