postgresql_role creation fails for database with SCRAM-SHA-256 encryption UNLESS provider is built from source #153
Description
Hi there,
I'm getting an Error: pq: unknown authentication response: 10
when attempting to create a user role in a DB configured with SCRAM-SHA-256 password encryption. This issue does NOT happen for DBs configured with MD5.
I understand this should already be fixed thanks to #113 and #114 (included in v.1.5.0), but role creation only succeeds when I build the v.1.6.0 release from source and manually place that binary in the .terraform
folder (replacing the one downloaded by terraform init
).
Terraform Version
Terraform v0.12.28
+ provider.external v1.2.0
+ provider.postgresql v1.6.0
Affected Resource(s)
Please list the resources as a list, for example:
- postgresql_role
Terraform Configuration Files
provider "postgresql" {
connect_timeout = 15
database = "stg_dummyusers"
expected_version = "11.6"
host = data.terraform_remote_state.postgresql_dummyusers.outputs.route53.record.fqdn
password = "password"
port = data.terraform_remote_state.postgresql_dummyusers.outputs.instance_details.port
sslmode = "require"
superuser = false
username = "master"
}
resource "postgresql_role" "user" {
encrypted_password = true
login = true
name = "rod"
password = "1234"
roles = ["ro-stg-dummyusers]
skip_reassign_owned = true
}
Debug Output
https://gist.github.com/rodsoaresTD/c27cff93c322bc81959393e808d281b2
Expected Behavior
When I use the binary built from v1.6.0's source:
terraform apply
data.terraform_remote_state.postgresql_dummyusers: Refreshing state...
module.gopass_secrets_postgresql.data.external.secrets["masteruser"]: Refreshing state...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# postgresql_role.user will be created
+ resource "postgresql_role" "user" {
+ bypass_row_level_security = false
+ connection_limit = -1
+ create_database = false
+ create_role = false
+ encrypted_password = true
+ id = (known after apply)
+ inherit = true
+ login = true
+ name = "rod"
+ password = (sensitive value)
+ replication = false
+ roles = [
+ "ro-stg-dummyusers",
]
+ skip_drop_role = false
+ skip_reassign_owned = true
+ superuser = false
+ valid_until = "infinity"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
postgresql_role.user: Creating...
postgresql_role.user: Creation complete after 2s [id=rod]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Releasing state lock. This may take a few moments...
Actual Behavior
When I use the binary downloaded by terraform init
:
terraform apply
data.terraform_remote_state.postgresql_dummyusers: Refreshing state...
module.gopass_secrets_postgresql.data.external.secrets["masteruser"]: Refreshing state...
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# postgresql_role.user will be created
+ resource "postgresql_role" "user" {
+ bypass_row_level_security = false
+ connection_limit = -1
+ create_database = false
+ create_role = false
+ encrypted_password = true
+ id = (known after apply)
+ inherit = true
+ login = true
+ name = "rod"
+ password = (sensitive value)
+ replication = false
+ roles = [
+ "ro-stg-dummyusers",
]
+ skip_drop_role = false
+ skip_reassign_owned = true
+ superuser = false
+ valid_until = "infinity"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
postgresql_role.user: Creating...
Error: pq: unknown authentication response: 10
on users.tf line 8, in resource "postgresql_role" "user":
8: resource "postgresql_role" "user" {
Releasing state lock. This may take a few moments...
Steps to Reproduce
terraform init
terraform apply
- issue occurs- Manually download and extract source code from v.1.6.0:
https://github.com/terraform-providers/terraform-provider-postgresql/releases/tag/v1.6.0 - Build source downloaded in previous step: `go build -o terraform-provider-postgresql_v1.6.0_x4``
- Overwrite the "terraform-provider-postgresql_v1.6.0_x4" binary that was downloaded by
terraform init
in step 1, by the one built in the previous step terraform init
(notice it does NOT re-download the v1.6.0 binary, the one built in step 4 is kept)terraform apply
should now create the user with no issues
Important Factoids
There is a pre-existing default role in the Postgres DB ("ro-stg-dummyusers") that we want to GRANT to the new user.
References
- We use
expected_version = "11.6"
because of Postgres Compatibility Issue with 11.6 #124 - We use
skip_reassign_owned = true
because of Can not destroy postgresql_role after create #36