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,360 points
2,186 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,940 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,560 points
1,010 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,940 points
75 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,940 points
328 views
+1 vote
1 answer
+13 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,380 points
216 views
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,940 points
53 views
0 votes
2 answers