mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-03 23:04:53 -04:00
cli: add Terraform log support (#1620)
* add Terraform logging * add TF logging to CLI * fix path * only create file if logging is enabled * update bazel files * register persistent flags manually * clidocgen * move logging code to separate file * reword yes flag parsing error * update bazel buildfile * factor out log level setting
This commit is contained in:
parent
ca1400819d
commit
1d0ee796e8
30 changed files with 688 additions and 238 deletions
|
@ -11,22 +11,24 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/terraform"
|
||||
)
|
||||
|
||||
// rollbacker does a rollback.
|
||||
type rollbacker interface {
|
||||
rollback(ctx context.Context) error
|
||||
rollback(ctx context.Context, logLevel terraform.LogLevel) error
|
||||
}
|
||||
|
||||
// rollbackOnError calls rollback on the rollbacker if the handed error is not nil,
|
||||
// and writes logs to the writer w.
|
||||
func rollbackOnError(w io.Writer, onErr *error, roll rollbacker) {
|
||||
func rollbackOnError(w io.Writer, onErr *error, roll rollbacker, logLevel terraform.LogLevel) {
|
||||
if *onErr == nil {
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "An error occurred: %s\n", *onErr)
|
||||
fmt.Fprintln(w, "Attempting to roll back.")
|
||||
if err := roll.rollback(context.Background()); err != nil {
|
||||
if err := roll.rollback(context.Background(), logLevel); err != nil {
|
||||
*onErr = errors.Join(*onErr, fmt.Errorf("on rollback: %w", err)) // TODO: print the error, or return it?
|
||||
return
|
||||
}
|
||||
|
@ -37,8 +39,8 @@ type rollbackerTerraform struct {
|
|||
client terraformClient
|
||||
}
|
||||
|
||||
func (r *rollbackerTerraform) rollback(ctx context.Context) error {
|
||||
if err := r.client.Destroy(ctx); err != nil {
|
||||
func (r *rollbackerTerraform) rollback(ctx context.Context, logLevel terraform.LogLevel) error {
|
||||
if err := r.client.Destroy(ctx, logLevel); err != nil {
|
||||
return err
|
||||
}
|
||||
return r.client.CleanUpWorkspace()
|
||||
|
@ -50,9 +52,9 @@ type rollbackerQEMU struct {
|
|||
createdWorkspace bool
|
||||
}
|
||||
|
||||
func (r *rollbackerQEMU) rollback(ctx context.Context) (retErr error) {
|
||||
func (r *rollbackerQEMU) rollback(ctx context.Context, logLevel terraform.LogLevel) (retErr error) {
|
||||
if r.createdWorkspace {
|
||||
retErr = r.client.Destroy(ctx)
|
||||
retErr = r.client.Destroy(ctx, logLevel)
|
||||
}
|
||||
if retErr := errors.Join(retErr, r.libvirt.Stop(ctx)); retErr != nil {
|
||||
return retErr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue