petoju / terraform-provider-mysql

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

The provider fails when connection info is passed from a modules outputs #10

Closed luis-guimaraes-exoawk closed 2 years ago

luis-guimaraes-exoawk commented 2 years ago

Hi, I'm trying to create a database in RDS, and therefore am using a module to create the RDS instance without a database and then output the endpoint to the mysql provider in order to create it independently. When I tried using winebarrel's version of this provider it did not fail, and handles the connection correctly.

Terraform Version

Terraform v1.2.0
on linux_amd64
+ provider registry.terraform.io/cyrilgdn/postgresql v1.16.0
+ provider registry.terraform.io/hashicorp/aws v4.15.1
+ provider registry.terraform.io/hashicorp/helm v2.5.1
+ provider registry.terraform.io/hashicorp/kubernetes v2.11.0
+ provider registry.terraform.io/hashicorp/local v2.2.3
+ provider registry.terraform.io/hashicorp/random v3.2.0
+ provider registry.terraform.io/hashicorp/tls v3.4.0
+ provider registry.terraform.io/petoju/mysql v3.0.13

Affected Resource(s)

Terraform Configuration Files

## The outputs from the aws_rds module
output "db_endpoint" {
  value = aws_db_instance.db_server.endpoint
}

output "db_address" {
  value = aws_db_instance.db_server.address
}

output "db_port" {
  value = aws_db_instance.db_server.port
}

output "db_user" {
  value = aws_db_instance.db_server.username
}

output "db_pass" {
  value = aws_db_instance.db_server.password
}

## the provider defined outside of that module
provider "mysql" {
  endpoint = module.aws_rds.db_endpoint
  username = module.aws_rds.db_user
  password = module.aws_rds.db_pass
}

Debug Output

Cannot share this as it contains confidential info regarding AWS accounts

Expected Behavior

The apply should've went ahead and worked, and the connection should only be started once the module outputs are available

Actual Behavior

Just hangs and after I interrupted the apply this showed up: image

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Nothing out of the ordinary

References

Nope

petoju commented 2 years ago

Hi, I see absolutely no reason why this should behave differently from just constants.

Did you have any MYSQL_* environment variables set?

luis-guimaraes-exoawk commented 2 years ago

No, I did not

marc-jan commented 2 years ago

I'm actually having the exact same issue.

petoju commented 2 years ago

Good news: I managed to reproduce it and find the source of the issue. Bad news: I cannot fix it as that's an issue of terraform. You could still run terraform apply -target that.resource.with.rds first and run apply only then.

I reported the issue here: https://github.com/hashicorp/terraform/issues/31465

petoju commented 2 years ago

The response in the linked ticket is that it is WAI.

So we cannot do anything about this - we won't fix it.