mmichaelb / terraform-provider-redshift

Terraform Redshift provider
https://registry.terraform.io/providers/mmichaelb/redshift/latest/docs
MIT License
1 stars 1 forks source link

Converting the schema owner to lowercase results in a user does not exist error #168

Closed phr3nzii closed 2 months ago

phr3nzii commented 3 months ago

We are starting to use this provider to manage existing resources inside a Redshift cluster. We use IAM roles for authentication, when doing so a user is automatically created in Redshift for the associated role, in our case the role is Admin and so the user that is created is called IAMR:Admin.

We have imported our existing schemas, but Terraform now wants to change the schema owner from IAMR:Admin to iamr:admin. When trying to apply this change we get an error:

Error: pq: user "IAMR:admin" does not exist

I had a look at the code and I believe it is this line that is causing the issue, https://github.com/mmichaelb/terraform-provider-redshift/blob/main/redshift/resource_redshift_schema.go#L63.

Is the conversion to lowercase needed? If not, could it be removed? If it can be removed, another place where it would be useful to remove the lowercase conversion would be https://github.com/mmichaelb/terraform-provider-redshift/blob/main/redshift/data_source_redshift_user.go#L27, as we use this to read users that are automatically created when using IAM roles for authentication.

For now, I've worked around the issue by adding this to the schema resources:

lifecycle {
  ignore_changes = [owner]
}
mmichaelb commented 2 months ago

Hi @phr3nzii, thank you for the issue and the detailed description. I will have a look at it and give you an update as soon as I know more.

mmichaelb commented 2 months ago

The changes got merged and released with the newest version v1.9.0. Thank you for opening the issue! If the problem still persists, feel free to ping me again.