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,310 points
1,401 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
• 56,160 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,480 points
590 views
0 votes
1 answer

How can i copy tables from one database to other on AWS?

You can use AWS Data pipeline to ...READ MORE

answered Jul 5, 2018 in AWS by Priyaj
• 56,160 points
40 views
0 votes
1 answer

How can I do Continuous data ingestion from on prem data sources to redshift

I can Recommend looking into AWS Schema ...READ MORE

answered Aug 8, 2018 in AWS by Priyaj
• 56,160 points
160 views
+1 vote
1 answer
+13 votes
2 answers
0 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
• 56,160 points
36 views
0 votes
2 answers