Skip to content

Improve error handling #92

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
michvllni opened this issue Sep 11, 2024 · 3 comments · Fixed by #95
Closed

Improve error handling #92

michvllni opened this issue Sep 11, 2024 · 3 comments · Fixed by #95
Assignees

Comments

@michvllni
Copy link

When deploying a template via the coderd_template resource, the errors from the internal commands do not bubble up.

All I get is for example this:

╷
│ Error: Client Error
│ 
│   with coderd_template.templates["az-ps-function"],
│   on templates.tf line 2, in resource "coderd_template" "templates":
│    2: resource "coderd_template" "templates" {
│ 
│ failed to wait for job: provisioner job did not succeed: failed (template
│ import provision for start: terraform plan: exit status 1)
╵

I have to use debug mode in terraform to get the actual error, which is very cumbersome:
2024-09-11T14:48:56.832Z [INFO] provider.terraform-provider-coderd_v0.0.4: A data resource "coder_parameter" "ado_projects" has not been declared in the root module.: job_stage="Detecting persistent resources" log_source=provisioner tf_req_id=6f199328-b1d4-3746-8d48-3cb8af035cfe job_id=10626 tf_provider_addr=registry.terraform.io/coder/coderd tf_resource_type=coderd_template @caller=github.com/coder/terraform-provider-coderd/internal/provider/template_resource.go:954 @module=coderd created_at=2024-09-11T14:48:56.783Z level=error tf_rpc=ApplyResourceChange timestamp=2024-09-11T14:48:56.832Z

It would be great if errors from the executed commands would be visible in the output.

@coder-labeler coder-labeler bot added the bug label Sep 11, 2024
@matifali
Copy link
Member

This is a design decision, and to surface these errors. You need TF_LOG=INFO or higher.
We may look into revisiting this.

This is documented here: https://registry.terraform.io/providers/coder/coderd/latest/docs/resources/template

Logs from building template versions are streamed from the provisioner when the TF_LOG environment variable is INFO or higher.

cc: @ethanndickson

@michvllni
Copy link
Author

Sorry, must have missed that disclaimer when I read the documentation.

In my opinion an error does not belong into info but into error, but you must have had your reasons.

Isn't it possible to separate the outputs and print errors in the build to error?

I agree that it is not necessary to print the whole plan all the time

@ethanndickson
Copy link
Member

ethanndickson commented Sep 11, 2024

Unfortunately, this is a Terraform provider restriction.
Our output options are either the aforementioned logging (where none of the available logging levels show by default, afaik) or a Terraform warning, which always show, but don't seem suitable for the Coder provisioner output due to their size and the fact they always contain Warning at the top.

e.g:

│ Warning: Log Output
│ 
│   with coderd_template.sample,
│   on main.tf line 24, in resource "coderd_template" "sample":
│   24: resource "coderd_template" "sample" {
│ 
│ module.git-clone.coder_script.git_clone: Plan to create

As I write this message, I realise we could just wait for the build to finish/fail and then include them all as a single warning/error respectively (or just omit the logs if successful).
That way they'd always show, and I wouldn't want to stream them as individual warnings, as that seems pretty horrid.
I'll experiment, thanks for the inspiration! :)

Update: This is much nicer, will implement

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

Successfully merging a pull request may close this issue.

3 participants