Skip to content
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

[WIP] Raise an error if terraform runner run fails #47

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

agrare
Copy link
Member

@agrare agrare commented May 29, 2024

If the Terraform::Runner.run call fails there is no stack_id returned which means that any error message returned by the opentofu-runner API is lost.

Re-work how the API response is handled so that the error message is available if the initial call fails.

Fixes #45

@agrare agrare added bug Something isn't working radjabov/yes? labels May 29, 2024
@miq-bot miq-bot added the wip label May 29, 2024
@agrare agrare force-pushed the raise_an_error_if_terraform_runner_run_fails branch from 3e79fb1 to 2617071 Compare May 29, 2024 18:20
response = create_stack_job(
template_path,
:input_vars => input_vars,
:tags => tags,
:credentials => credentials,
:env_vars => env_vars
)

raise Terraform::Runner::Error, response.error_message if response.status == "FAILED"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@putmanoj can you help out here? I'm seeing in ResponseAsync that status is a string like: "SUCCESS", "FAILED", "CANCELLED", but if I submit a create_stack_job I see status is 401:

#<Terraform::Runner::Response:0x00007f94dcb031c8
 @action=nil,
 @created_at=nil,
 @details=nil,
 @error_message=nil,
 @message="You do not have the necessary credentials.",
 @stack_id=nil,
 @stack_job_end_time=nil,
 @stack_job_start_time=nil,
 @stack_name=nil,
 @status=401>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when is message used vs error_message?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when is message used vs error_message?

The 'message' is the full terraform/opentofu command output (including error message)
whereas 'error_message' , in case fails, cause of the failure or it only contains the error message for the failure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have a failure posted above and there is only an entry in message and not error_message is that normal?

Copy link
Contributor

@putmanoj putmanoj May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we can have some improvement here.
But in this case the terraform command was not executed, as there is auth failure when calling the API.

For now to complete the dev test, you could use this example 'TOKEN' -> https://github.ibm.com/Orpheus/terraform-runner/blob/main/examples/simple-template-hcl/01-create-stack.sh#L11

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@putmanoj this isn't dev this is on an appliance, what is the plan for auth in prod?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now you could hardcode the above token and continue.

We can continue the discussion on the channel

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened to track this issue #49

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@putmanoj circling back to this question, I know we are tackling the auth issue separately but how do I tell when a terraform response is success/failure and how do I get the error response?

@agrare agrare force-pushed the raise_an_error_if_terraform_runner_run_fails branch from 2617071 to abda20e Compare June 3, 2024 17:02
@miq-bot
Copy link
Member

miq-bot commented Jun 3, 2024

Checked commits agrare/manageiq-providers-embedded_terraform@1d7f755~...abda20e with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
4 files checked, 0 offenses detected
Everything looks fine. 👍

@miq-bot
Copy link
Member

miq-bot commented Jun 3, 2024

This pull request is not mergeable. Please rebase and repush.

@miq-bot
Copy link
Member

miq-bot commented Sep 9, 2024

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

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

Successfully merging this pull request may close these issues.

No error message if Terraform::Runner.run fails
3 participants