petoju / terraform-provider-mysql

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

Issue getting password from data source #78

Closed greenkiwi closed 1 year ago

greenkiwi commented 1 year ago

Terraform Version

Terraform v1.4.5
on darwin_amd64
+ provider registry.terraform.io/cyralinc/cyral v2.11.1
+ provider registry.terraform.io/hashicorp/aws v4.63.0
+ provider registry.terraform.io/hashicorp/random v3.5.1
+ provider registry.terraform.io/newrelic/newrelic v3.20.2
+ provider registry.terraform.io/petoju/mysql v3.0.34

Affected Resource(s)

Data provider

╷
│ Error: failed to connect to MySQL: could not connect to server: Error 1045 (28000): Access denied for user ''@'10.150.0.182' (using password: NO)
│ 

Terraform Configuration Files

data "aws_secretsmanager_secret" "admin" {
  arn = module.aurora.secretmanager_admin_secret_arn
  depends_on = [
    module.aurora
  ]
}

data "aws_secretsmanager_secret_version" "admin" {
  secret_id = data.aws_secretsmanager_secret.admin.id
}

provider "mysql" {
  endpoint = module.aurora.cluster_writer_endpoint
  username = jsondecode(data.aws_secretsmanager_secret_version.admin.secret_string)["username"]
  password = jsondecode(data.aws_secretsmanager_secret_version.admin.secret_string)["password"]
}

terraform {
  required_version = ">= 1.0.0, < 2.0.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.21"
    }
    mysql = {
      source  = "petoju/mysql"
      version = ">= 3.0.19, < 4.0.0"
    }
  }
}

Debug Output

╷
│ Error: failed to connect to MySQL: could not connect to server: Error 1045 (28000): Access denied for user ''@'10.150.0.182' (using password: NO)
│ 

Expected Behavior

I would expect that the username and password would be read from the aws secretmanager secret before the provider is created. This would allow the provider to connect.

Actual Behavior

Initially it worked and created the DB and users, but plans are now not able to connect.

The username and password are "" and it cannot connect.

Steps to Reproduce

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

  1. terraform apply

Important Factoids

References

I found a few other issues that appeared to have similar issues

https://github.com/hashicorp/terraform/issues/12775 https://github.com/hashicorp/terraform/issues/11264

petoju commented 1 year ago

I believe this is a known bug we cannot do a lot about - you referenced the tickets, I don't have much more to say.

greenkiwi commented 1 year ago

@petoju thanks. Yeah - I didn't know whether there was any sort of work around. The options provided there didn't seem to work.

I'll keep working with them.

Thanks for responding.

greenkiwi commented 1 year ago

I'll close this - if there isn't any workaround available.