Terraform init for a PostgreSQL (remote backend for state file) giving me a "invalid userinfo"

I spinned up anew PostgreSQL Database and added the connection info (from here) and ran a simple terraform init and got this below error:

Initializing the backend... │ Error: parse "postgres://username:password@PGSERVER.name.com/pg_database": net/url: invalid userinfo

My password is a combination of alphanumeric & special characters. Is this what might be causing this issue?

What am I missing here people’s?

Hi @yerneniv,

The “userinfo” this message mentions is talking about the “User Information” field in the URL, so I think you are right that you’re using some characters in your password that are not allowed literally in URL syntax.

The RFC says that the syntax for this field is:

userinfo = *( unreserved / pct-encoded / sub-delims / ":" )

This refers to some other productions elsewhere in the spec:

unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="

So apparently the valid characters you can write literally are:

  • “ALPHA”, which represents ASCII letters
  • “DIGIT”, which represents ASCII digits
  • Any of the following: -._~!$&'()*+,;=

If your password contains any other characters then you will need to use the pct-encoded production to escape them. For example, if you have an “at sign” @ in your password you would need to find its hexadecimal ASCII code (which for @ is 40 in hexadecimal) and write it after a percent symbol %, giving %40.

For example, if my password were b@dp@ssword then I would write it as:


I have not tested this with the Postgres backend in particular, but if it’s written correctly then it should decode those %40 sequences to recover the original @ symbols. If that doesn’t work then you may have found a bug in the backend, but we’ll see once you’ve tested.

1 Like

Wow!! I truly appreciate the details here @apparentlymart :blue_heart: :blue_heart:

I will do the needful and will update you if I see any more concerns here.