Closed hashibot closed 6 years ago
Any news about this? I still run in this bug.
Version:
$ ./terraform version
Terraform v0.11.3
+ provider.docker v0.1.1
+ provider.mysql v1.0.1
Proof of concept:
provider "docker" {
host = "unix:///var/run/docker.sock"
}
resource "docker_image" "database" {
name = "mysql:5"
}
resource "docker_container" "database" {
name = "database"
image = "${docker_image.database.latest}"
env = [ "MYSQL_ROOT_PASSWORD=example" ]
}
provider "mysql" {
endpoint = "${docker_container.database.ip_address}:3306"
username = "root"
password = "example"
}
resource "mysql_database" "example" {
name = "example"
}
Output: (same for apply)
$ ./terraform plan
Error: Error running plan: 1 error(s) occurred:
* provider.mysql: dial tcp 127.0.0.1:3306: getsockopt: connection refused
Hi @andricicezar , i think the issue is when the mysql provider tried to connect to the database, but this resource doesn't exist yet.
I have the same issue with Google Cloud Platform Provider and Mysql Provider. I sended a PR for this problem.
This feels like a fairly common use case. I'm surprised there haven't been more people asking about this. The MySQL provider is basically useless if you can't use it to configure a database after provisioning the server.
Although it made me sad, I ended up using this hack to overcome this limitation.
In our company we use a docker image with terraform and mariadb service to run plans. Using this approach, the mysql provider try connect to the local database (when the new database don't exist), but the configurations it's applied in the new server (using flag depends_on
, when it's up).
This issue was originally opened by @partamonov as hashicorp/terraform#5687. It was migrated here as part of the provider split. The original body of the issue is below.
This part of code causing issues. (see attched create.log)
And if I'm creating RDS instance first and as second run I'm creating DBs everything is fine, but destroy failing with
And once again commenting mysql databases part and apply did the trick for first run and second run can be with destroy flag
create.txt