terraform-k8s icon indicating copy to clipboard operation
terraform-k8s copied to clipboard

Output values are double quoted

Open mcfearsome opened this issue 5 years ago • 10 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

terraform-k8s & Kubernetes Version

hashicorp/terraform-k8s:0.1.2-alpha

Client Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:26:26Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"13+", GitVersion:"v1.13.12-eks-eb1860", GitCommit:"eb1860579253bb5bf83a5a03eb0330307ae26d18", GitTreeState:"clean", BuildDate:"2019-12-23T08:58:45Z", GoVersion:"go1.11.13", Compiler:"gc", Platform:"linux/amd64"}

Affected Resource(s)

OutputStatus

Terraform Configuration Files

  outputs:
  - key: aws_access_key_id
    moduleOutputName: aws_access_key_id
  - key: aws_secret_access_key
    moduleOutputName: aws_secret_access_key

Debug Output

data:
  aws_access_key_id: '"REDACTED"'
  aws_secret_access_key: '"REDACTED"'

Expected Behavior

Expect the values to be quoted normally

Actual Behavior

it looks like convertValueToString is adding double quotes " and then it is getting quoted again when output as yaml probably

Steps to Reproduce

Run a workspace with a string output

mcfearsome avatar Apr 28 '20 18:04 mcfearsome

I dug into this a bit further and it seems to happen when the values themselves have escaped double quotes in Terraform output. For example, if we pass a value such as "example", that is escaped as \"example\" in Terraform.

If the module output contains escaped quotes, we'll likely need to add a regular expression check to extract the center group and pass it to YAML.

joatmon08 avatar May 15 '20 18:05 joatmon08

For reference this was my module output definition:

output "aws_access_key_id" {
  value = aws_iam_access_key.workarea-app.id
}

output "aws_secret_access_key" {
  value     = aws_iam_access_key.workarea-app.secret
  sensitive = true
}

I would not expect aws_iam_access_key.workarea-app.secret and aws_iam_access_key.workarea-app.id to return a pre-quoted value, but I have not explicitly checked.

mcfearsome avatar May 15 '20 18:05 mcfearsome

It seems to be the line 48 in the file workspacehelper/tfc_output.go is the point where those double quotes get added.

return `"` + val.AsString() + `"`

I removed those double quotes from the statement, recompiled and tested it. It produces secrets with values that are not enclosed in double quotes.

I don't know whether there are specific cases where the values must be double quoted, but when I am sourcing secrets with terraform outputs, due to presence of double quotes nothing is working and I need to run a command on a container startup to remove leading and training double quotes. If there was a need for specific cases to have values enclosed in double quotes, I would suggest introducing workspace resource key which would control whether a specific secret with outputs should be quoted or not.

polasekr avatar Mar 10 '21 23:03 polasekr

Did anyone found a way to correct this issue?

nuno407 avatar Jun 18 '21 15:06 nuno407

I modified the code from

return '"' + val.AsString() + '"' to return val.AsString()

, re-compiled it and running my compiled version as a temporary workaround. Such solution is not optimal. Since I do not understand the original need for double-quoting in the code, I am hesitant to submit PR. I hope that somebody will explain the need for those double quotes in the code or confirms that it is a bug.

polasekr avatar Jun 18 '21 15:06 polasekr

@polasekr yeap I checked your suggestion but I didn't want to make a custom build. Maybe @koikonom can give a look? Regards, Nuno

nuno407 avatar Jun 18 '21 16:06 nuno407

Is there any update on this issue?

polasekr avatar Oct 28 '21 20:10 polasekr

This is a stumbling block for our deployment - connection strings being quoted makes things that use them break. When can this be addressed?

fractos avatar Oct 29 '21 13:10 fractos

This behaviour should be made optional (like the hcl toggle for input variables).

I understand the need for this behaviour as an output from a module could be a non-string value (list, map, etc), and needs a way to be expressed as a string, but it makes using plain string values way more complicated than it needs to be.

phyber avatar Oct 29 '21 13:10 phyber

Hi, is there an update on this? I am looking to promote adopting this in my organization and this is seen as a major blocker. In the meantime, are there any workarounds that can be used within a Kubernetes manifest? I was wondering if the "--raw" option that's available via CLI is to be added to the operator

EmmanuelOgiji avatar Dec 21 '21 13:12 EmmanuelOgiji