Best practice to create an AWS RDS MySQL instances first and then databases in it

847 views
Skip to first unread message

Andreas Ka

unread,
Mar 16, 2017, 7:59:22 AM3/16/17
to Terraform
What is the best practice to first create RDS database instances and _then_ provision them with actual databases, users and permissions?

Terraform offers a MySQL provider which offers this functionality: https://www.terraform.io/docs/providers/mysql/.

Then, on the other hand, it's not possible to use the `depends_on` directive on providers (https://github.com/hashicorp/terraform/issues/2430) and modules (https://github.com/hashicorp/terraform/issues/10462).

This means that using the MySQL provider to create databases within a database instance which also should be created works within the same `terraform apply` step, because the MySQL Provider requires the endpoint address of the database instance before it actually has been created, hence fails.


With 0.9.0 the following example setup fails with "dial tcp: missing address".

provider "mysql" {
  endpoint = "${module.mysql-db1.db_endpoint}"
  username = "root"
  password = "${var.somepw}"
}



Is there any best practice how to keep the database layout documented in Terraform, amongst the actual database instance resources in one Terraform project?

Brian Lalor

unread,
Mar 16, 2017, 8:45:11 AM3/16/17
to terrafo...@googlegroups.com
Could you put creation and population in separate modules?

--
Brian Lalor

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/174636fc-6f68-45dc-ab9f-31d5dfb0c7d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andreas Ka

unread,
Mar 16, 2017, 9:52:46 AM3/16/17
to Terraform
This is what I had and that's not working:

- Using the MySQL provider in a module.
- Using RDS creation in another module.

I still have to input the RDS endpoint as a variable into the MySQL-provider module (which is not creating an explicit dependency which makes the RDS module execute first).
There's no way to model dependency graphs between each other, since neither the "provider" nor the "module" directives support a "depends_on".

It seems that the MySQL provider block is always initialized earlier than any resource creation, and since the MySQL endpoint is a mandatory parameter to the MySQL provider (see https://www.terraform.io/docs/providers/mysql/index.html#endpoint) it has to exist in the first place.


I'm currently trying to have two distinct projects which are not wired to each other. The first project creates instances, the second provisions the instances. For that I have to configure hardcoded MySQL endpoints in the provisioning project configuration, which is not very comfortable.

--
Andreas

YB Kim

unread,
Jun 10, 2019, 9:54:07 AM6/10/19
to Terraform
Dear Andreas Ka,

Would you be able to share how you handled it?  I am facing the same problem.

BR,
Young,

2017년 3월 16일 목요일 오후 10시 52분 46초 UTC+9, Andreas Ka 님의 말:
Reply all
Reply to author
Forward
0 new messages