Skip to content

Template create tar stdin option hangs and exits #7043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
onyi-ada opened this issue Apr 7, 2023 · 20 comments
Closed

Template create tar stdin option hangs and exits #7043

onyi-ada opened this issue Apr 7, 2023 · 20 comments

Comments

@onyi-ada
Copy link

onyi-ada commented Apr 7, 2023

In creating a template using the using '-' to read tar from stdin with the -d/--directory option, the output hangs on
⧗ Queued then exits without creating the template or displaying any error output.

The command used is what is outlined here Support terraform resources outside the given template directory

version v0.21.3

@matifali
Copy link
Member

matifali commented Apr 8, 2023

Can you set CODER_VERBOSE=true and try again. Please share any logs.

@onyi-ada
Copy link
Author

onyi-ada commented Apr 10, 2023

CODER_VERBOSE=true

With that, I get an output that indicates that the terraform isn't there, even though it is. Running without the tar option and simply pointing -d to the directory does create a template.

$ CODER_VERBOSE=true tar -cvh dev_templates/aws-linux | coder templates create -d - test-dev-template
dev_templates/aws-linux/
dev_templates/aws-linux/main.tf
dev_templates/aws-linux/README.md
✔ Queued [955ms]
✔ Running [87ms]
✔ Setting up [0ms]
✔ Parsing template parameters [37ms]
⧗  Detecting persistent resources
  terraform environment variable: TF_LOG=INFO
  terraform environment variable: TF_LOG_PATH=/var/log/terraform.log
  Terraform 1.3.4
  Error: No configuration files
  Plan requires configuration to be present. Planning without a configuration would mark everything for destruction, which is normally not what is desired. If you would like to destroy everything, run plan with the -destroy option. Otherwise, create a Terraform configuration file (.tf file) and try again.
✔ Detecting persistent resources [77ms]
✘ Cleaning Up [121ms]
template import provision for start: recv import provision: plan terraform: terraform plan: exit status 1

@matifali
Copy link
Member

main.tf file should exist in the root of the tar you are creating.

@onyi-ada
Copy link
Author

main.tf file should exist in the root of the tar you are creating.

The main.tf file is already the root. I re-initialized terraform, this is the output

$ CODER_VERBOSE=true tar -cvh dev_templates/aws-linux | coder templates create -d - test-dev-template
dev_templates/aws-linux/
dev_templates/aws-linux/.terraform/
dev_templates/aws-linux/.terraform/providers/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/coder/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/coder/0.6.23/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/terraform-provider-coder_v0.6.23
◳ Uploading directory...dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/README.md
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/LICENSE
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/hashicorp/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/hashicorp/aws/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/linux_amd64/
dev_templates/aws-linux/.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/linux_amd64/terraform-provider-aws_v4.62.0_x5
Failed to read file from request.

@matifali
Copy link
Member

@ammario can you take a look what is happenings here.

@ammario
Copy link
Member

ammario commented Apr 10, 2023

The problem here is that tar is keeping the dev_templates/aws-linux prefix on all files, so there isn't a main.tf in the root of the archive. I suggest using the -C flag like this:

tar -cvh -C dev_templates/aws-linux . | coder templates create -d - test-dev-template

@onyi-ada
Copy link
Author

The problem here is that tar is keeping the dev_templates/aws-linux prefix on all files, so there isn't a main.tf in the root of the archive. I suggest using the -C flag like this:

tar -cvh -C dev_templates/aws-linux . | coder templates create -d - test-dev-template

That produces the same result

$ tar -cvh -C dev_templates/aws-linux . | coder templates create -d - test-dev-template
./
./.terraform/
./.terraform/providers/
./.terraform/providers/registry.terraform.io/
./.terraform/providers/registry.terraform.io/coder/
./.terraform/providers/registry.terraform.io/coder/coder/
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/terraform-provider-coder_v0.6.23
◳ Uploading directory..../.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/README.md
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/LICENSE
./.terraform/providers/registry.terraform.io/hashicorp/
./.terraform/providers/registry.terraform.io/hashicorp/aws/
./.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/
./.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/linux_amd64/
./.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/linux_amd64/terraform-provider-aws_v4.62.0_x5
Failed to read file from request.

@ammario
Copy link
Member

ammario commented Apr 10, 2023

Hmm, well the error has changed slightly. Now it's in the correct directory but I think the template is too big due to the .terraform folder. (#7071)

Try adding a --exclude='^\.' to your tar invocation. E.g.:

tar -cvh --exclude='^\.' -C dev_templates/aws-linux . | coder templates create -d - test-dev-template

@onyi-ada
Copy link
Author

onyi-ada commented Apr 10, 2023

Hmm, well the error has changed slightly. Now it's in the correct directory but I think the template is too big due to the .terraform folder. (#7071)

Try adding a --exclude='^\.' to your tar invocation. E.g.:

tar -cvh --exclude='^\.' -C dev_templates/aws-linux . | coder templates create -d - test-dev-template

I see the same error Failed to read file from request.

@ammario
Copy link
Member

ammario commented Apr 10, 2023

Can you send the full error again? Is it still tarring the '.terraform' directory? Can you try tarring into a file with the same exact command and tell me the size?

@onyi-ada
Copy link
Author

onyi-ada commented Apr 10, 2023

Yes, this is the full error, same as above

$ tar -cvh --exclude='^\.' -C dev_templates/aws-linux . | CODER_VERBOSE=true coder templates create -d - test-dev-template
./
./.terraform/
./.terraform/providers/
./.terraform/providers/registry.terraform.io/
./.terraform/providers/registry.terraform.io/coder/
./.terraform/providers/registry.terraform.io/coder/coder/
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/terraform-provider-coder_v0.6.23
◱ Uploading directory..../.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/README.md
./.terraform/providers/registry.terraform.io/coder/coder/0.6.23/linux_amd64/LICENSE
./.terraform/providers/registry.terraform.io/hashicorp/
./.terraform/providers/registry.terraform.io/hashicorp/aws/
./.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/
./.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/linux_amd64/
./.terraform/providers/registry.terraform.io/hashicorp/aws/4.62.0/linux_amd64/terraform-provider-aws_v4.62.0_x5
Failed to read file from request.

I've tarred the directory, it's about 80M
80M Apr 10 21:26 aws_linux.tar.gz

@ammario
Copy link
Member

ammario commented Apr 10, 2023

Ah ok, your goal should be to play around with the tar flags to reduce the size of the archive to less than a megabyte. The .terraform directory is probably the main problem.

I'm going to be out of pocket for a while, feel free to ping me on Discord, but may not be responsive here.

@onyi-ada
Copy link
Author

Ah ok, your goal should be to play around with the tar flags to reduce the size of the archive to less than a megabyte. The .terraform directory is probably the main problem.

I'm going to be out of pocket for a while, feel free to ping me on Discord, but may not be responsive here.

I've reduced the size to less than a megabyte. It hangs on queued, then exits

3.0K Apr 11 00:27 aws_linux.tar.gz

$ tar --exclude='.[^/]*' -cvh -C dev_templates/aws-linux . | CODER_VERBOSE=true coder templates create -d - test-dev-template
./
./main.tf
./README.md
⧗  Queued

$

@ammario
Copy link
Member

ammario commented Apr 11, 2023

Ok, would you mind uploading the template archive here (with any secrets stripped) so that I can try to reproduce?

@onyi-ada
Copy link
Author

aws_linux.tar.gz

Ok, would you mind uploading the template archive here (with any secrets stripped) so that I can try to reproduce?

@onyi-ada
Copy link
Author

@ammario Were you able to reproduce the issue?

@ammario
Copy link
Member

ammario commented Apr 18, 2023

I was able to run:

tar -C dev_templates/aws-linux  -cvh . | coder templates create -d - debug

with the provided archive with no issue. Is it possible you have a load balancer between you and the coder server that is causing the request to fail?

@onyi-ada
Copy link
Author

I was able to run:

tar -C dev_templates/aws-linux  -cvh . | coder templates create -d - debug

with the provided archive with no issue. Is it possible you have a load balancer between you and the coder server that is causing the request to fail?

We do have a load balancer.
We are able to create templates without the tar option though, so I'm wondering what issue using the load balancer would be causing?

@ammario
Copy link
Member

ammario commented Apr 18, 2023

@onyi-ada

Try again using the --debug-http flag introduced here in your templates create invocation. You can install that version of the binary with:

git clone https://github.com/coder/coder
cd coder
go install enterprise/cmd/coder
~/go/bin/coder

Note that the output will contain your session tokens so be careful about sharing. Hopefully it will show us something useful.

@onyi-ada
Copy link
Author

onyi-ada commented Apr 21, 2023

@ammario It appears the latest version of Coder allows us to get further. I'll close the issue for now and report back if we are still running into an issue with this feature. Thanks for your support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants