terraform-k8s
terraform-k8s copied to clipboard
Output values are double quoted
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
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.
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.
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.
Did anyone found a way to correct this issue?
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 yeap I checked your suggestion but I didn't want to make a custom build. Maybe @koikonom can give a look? Regards, Nuno
Is there any update on this issue?
This is a stumbling block for our deployment - connection strings being quoted makes things that use them break. When can this be addressed?
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.
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