You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
terraform output -raw logs should output exactly what the container entrypoint echo '' outputs: a single newline character, just like docker logs repro outputs.
Actual Behaviour
terraform output -raw logs outputs the stdout prefixed with the Docker log header: 01 00 00 00 00 00 00 01 0a, which can be more easily observed by running terraform output -raw logs | xxd.
While Terraform seems to handle this fine by Unicode escaping these bytes as "\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0001\n" in the terraform.tfstate JSON, this causes GitLab's Terraform HTTP state backend to return a 400 Bad Request response when attempting to push the new state, which seems like a separate bug in GitLab that also needs to be addressed.
This can be partially worked around by using the docker_logs data source with discard_headers = true, but this should either be fixed in the docker_container resource, or the container_logs attribute should be deprecated and removed from the docker_container resource in favor of only using the docker_logs data source.
More importantly, strings in Terraform must be valid Unicode, while the stdout/stderr of a container may be an arbitrary sequence of bytes, so logs should really be base64 encoded before being returned.
Additionally, the docker_logs data source offers no way to demultiplex the stdout/stderr from the container logs. This should be done using StdCopy()as shown in the documentation comment for the client.ContainerLogs() function, and the stdout and stderr should probably be exposed as two separate attributes, e.g. stdout_base64 and stderr_base64.
Steps to Reproduce
terraform apply
Observe output from terraform output -raw logs | xxd
Compare with docker logs repro | xxd
Important Factoids
Running docker in rootful podman on macos, but the issue is also reproducible in docker on WSL2 on Windows 10
The text was updated successfully, but these errors were encountered:
Community Note
Terraform (and docker Provider) Version
Affected Resource(s)
docker_container
Terraform Configuration Files
Debug Output
https://gist.github.com/zanecodes/a3959cdc746cbea6330d91cf9aa9bfef#file-debug-log-L218
Expected Behaviour
terraform output -raw logs
should output exactly what the container entrypointecho ''
outputs: a single newline character, just likedocker logs repro
outputs.Actual Behaviour
terraform output -raw logs
outputs the stdout prefixed with the Docker log header:01 00 00 00 00 00 00 01 0a
, which can be more easily observed by runningterraform output -raw logs | xxd
.While Terraform seems to handle this fine by Unicode escaping these bytes as
"\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0001\n"
in theterraform.tfstate
JSON, this causes GitLab's Terraform HTTP state backend to return a400 Bad Request
response when attempting to push the new state, which seems like a separate bug in GitLab that also needs to be addressed.This can be partially worked around by using the
docker_logs
data source withdiscard_headers = true
, but this should either be fixed in thedocker_container
resource, or thecontainer_logs
attribute should be deprecated and removed from thedocker_container
resource in favor of only using thedocker_logs
data source.More importantly, strings in Terraform must be valid Unicode, while the stdout/stderr of a container may be an arbitrary sequence of bytes, so logs should really be base64 encoded before being returned.
Additionally, the
docker_logs
data source offers no way to demultiplex the stdout/stderr from the container logs. This should be done usingStdCopy()
as shown in the documentation comment for theclient.ContainerLogs()
function, and the stdout and stderr should probably be exposed as two separate attributes, e.g.stdout_base64
andstderr_base64
.Steps to Reproduce
terraform apply
terraform output -raw logs | xxd
docker logs repro | xxd
Important Factoids
Running docker in rootful podman on macos, but the issue is also reproducible in docker on WSL2 on Windows 10
The text was updated successfully, but these errors were encountered: