Can we use Terraform to execute SQL script on RDS MySQL

0 votes

I created the aws_db_instance to provision the RDS MySQL database using Terraform configuration. Now my next question is to execute the SQL Script (CREATE TABLE and INSERT statements) on the RDS. I did the following but there is no effect. terraform plan cannot even see my changes on executing the sql. What did I miss here? Thanks.

resource "aws_db_instance" "mydb" {
# …
provisioner "remote-exec" { 
    inline = [ 
        "chmod +x 
        script.sql", "script.sql args",
         ] 
    } 
}
Aug 21, 2018 in AWS by bug_seeker
• 15,550 points
6,177 views

1 answer to this question.

0 votes

I don't think remote-exec is what you need. You need to use local-exec provisioner to achieve this. Documentation: terraform.io/docs/provisioners/local-exec.html. I believe, remote-exec is similar to user data (terraform logs into the instance - linux/windows and runs some script there).
if you switch to local exec, you'll need to open your IP address on the security group, also you need to be able to connect to it, either thru a
vpn or a if the db is on a public subnet then your ip needs to be open

answered Aug 21, 2018 by Priyaj
• 58,100 points

Related Questions In AWS

0 votes
1 answer

How to execute scheduled SQL scripts in on Amazon Redshift?

I had faced the same problem earlier. ...READ MORE

answered Nov 19, 2018 in AWS by Archana
• 5,640 points
2,926 views
+1 vote
0 answers
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
1,042 views
+2 votes
1 answer
+1 vote
1 answer

Can we use AWS Public DNS as Domian name to enable https on our instance

I don't believe you can get a ...READ MORE

answered Aug 23, 2018 in AWS by Priyaj
• 58,100 points
180 views
0 votes
2 answers