petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
65 stars 42 forks source link

Don't connect to MySQL Instance when the provider is instantiated #25

Closed RyanW8 closed 1 year ago

RyanW8 commented 1 year ago

Hey we're looking to migrate to this provider away from the deprecated https://github.com/hashicorp/terraform-provider-mysql. However we've hit a bit of a roadblock. This provider seems to attempt to connect to the MySQL instance when the provider is instantiated which is causing problems for us.

We have a wrapper module that allows us to create AWS RDS instances of various engine types (postgres, mysql etc), in this module we declare the MySQL provider so that MySQL engine types can create users; this is causing problems for postgres engine types as obviously the provider won't work. Is it possible to move the connecting to the MySQL instance into the specific resources like it did in the old provider?

snolan-amount commented 1 year ago

This issue prevents a simple plan too - if your terraform creates a database instance and then uses this provider to work with the new database instance, the plan fails because this provider tries to connect to the instance that doesn't exist. Using terraform 1.0.9.

petoju commented 1 year ago

We could do it now as I understand the rationale. Database could be connected to lazily in resources. It needs some locking, but it can be done.

Bear in mind it brings something (it works with RDS when provisioned specially), but brings a bit of WTF moment - one can make a provider, that seems to work until a resource is created.

petoju commented 1 year ago

@RyanW8 @snolan-amount could you test it now? Provider 3.0.20 could behave better. It still needs some testing - while it passed the integration test, I am afraid there could be more issues with it.

RyanW8 commented 1 year ago

Thanks @petoju we've now switched to using this MySQL provider, haven't encountered any issues yet. Thanks!