From bee67380bdf72049e25335a5e7735605306bd90f Mon Sep 17 00:00:00 2001 From: Suresh Ramasamy Date: Wed, 10 Apr 2024 15:24:27 -0400 Subject: [PATCH] fix lint errors Signed-off-by: Suresh Ramasamy --- apis/v1beta1/workspace_types.go | 6 +++--- cmd/provider/main.go | 7 ++++--- docs/monolith/Configuration.md | 4 ++-- examples/providerconfig-enable-logging.yaml | 17 ----------------- internal/controller/workspace/workspace.go | 2 +- internal/terraform/terraform.go | 19 ++++++++++--------- 6 files changed, 20 insertions(+), 35 deletions(-) delete mode 100644 examples/providerconfig-enable-logging.yaml diff --git a/apis/v1beta1/workspace_types.go b/apis/v1beta1/workspace_types.go index d0e4ddfe..46727c59 100644 --- a/apis/v1beta1/workspace_types.go +++ b/apis/v1beta1/workspace_types.go @@ -157,9 +157,9 @@ type WorkspaceObservation struct { // A WorkspaceSpec defines the desired state of a Workspace. type WorkspaceSpec struct { - xpv1.ResourceSpec `json:",inline"` - ForProvider WorkspaceParameters `json:"forProvider"` - EnableTerraformCLILogging bool `json:"enableTerraformCLILogging,omitempty"` + xpv1.ResourceSpec `json:",inline"` + ForProvider WorkspaceParameters `json:"forProvider"` + EnableTerraformCLILogging bool `json:"enableTerraformCLILogging,omitempty"` } // A WorkspaceStatus represents the observed state of a Workspace. diff --git a/cmd/provider/main.go b/cmd/provider/main.go index 1b86c77b..eb03729a 100644 --- a/cmd/provider/main.go +++ b/cmd/provider/main.go @@ -18,11 +18,12 @@ package main import ( "context" - zapuber "go.uber.org/zap" "os" "path/filepath" "time" + zapuber "go.uber.org/zap" + "github.com/crossplane/crossplane-runtime/pkg/certificates" "github.com/crossplane/crossplane-runtime/pkg/controller" "github.com/crossplane/crossplane-runtime/pkg/feature" @@ -65,7 +66,7 @@ func main() { ) kingpin.MustParse(app.Parse(os.Args[1:])) - zl := zap.New(zap.UseDevMode(*debug),UseJSONencoder()) + zl := zap.New(zap.UseDevMode(*debug), UseJSONencoder()) log := logging.NewLogrLogger(zl.WithName("provider-terraform")) if *debug { // The controller-runtime runs with a no-op logger by default. It is @@ -149,6 +150,7 @@ func main() { kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager") } +// UseJSONencoder sets the logger to use json format for log records func UseJSONencoder() zap.Opts { return func(o *zap.Options) { encoderConfig := zapuber.NewProductionEncoderConfig() @@ -156,4 +158,3 @@ func UseJSONencoder() zap.Opts { o.Encoder = zapcore.NewJSONEncoder(encoderConfig) } } - diff --git a/docs/monolith/Configuration.md b/docs/monolith/Configuration.md index 3c0a8365..c121e707 100644 --- a/docs/monolith/Configuration.md +++ b/docs/monolith/Configuration.md @@ -359,7 +359,7 @@ here for inspiration. ## Enable Terraform CLI logs -Terraform CLI logs can be written to a container logs as standard output to assist with debugging and to view detailed information about Terraform operations. +Terraform CLI logs can be written to the container logs as standard output to assist with debugging and to view detailed information about Terraform operations. To enable it, the `Workspace` spec has an **optional** `EnableTerraformCLILogging` field. ```yaml apiVersion: tf.upbound.io/v1beta1 @@ -376,4 +376,4 @@ spec: ... ``` -- `enableTerraformCLILogging`: Specifies whether logging is enabled (`true`) or disabled (`false`). When enabled, Terraform CLI command logs will be written cpntainer logs as standard output. Default is `false` \ No newline at end of file +- `enableTerraformCLILogging`: Specifies whether logging is enabled (`true`) or disabled (`false`). When enabled, Terraform CLI command logs will be written to the container logs as standard output. Default is `false` \ No newline at end of file diff --git a/examples/providerconfig-enable-logging.yaml b/examples/providerconfig-enable-logging.yaml deleted file mode 100644 index 0d5880f1..00000000 --- a/examples/providerconfig-enable-logging.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: tf.upbound.io/v1beta1 -kind: ProviderConfig -metadata: - name: default -spec: - # This optional configuration block can be used to inject HCL into any - # workspace that uses this provider config, for example to setup Terraform - # providers. - configuration: | - // Modules _must_ use remote state. The provider does not persist state. - terraform { - backend "kubernetes" { - secret_suffix = "providerconfig-default" - namespace = "default" - config_path = "~/.kube/config" - } - } diff --git a/internal/controller/workspace/workspace.go b/internal/controller/workspace/workspace.go index 82def011..10e3be66 100644 --- a/internal/controller/workspace/workspace.go +++ b/internal/controller/workspace/workspace.go @@ -319,7 +319,7 @@ func (c *connector) Connect(ctx context.Context, mg resource.Managed) (managed.E } envs[idx] = strings.Join([]string{env.Name, runtimeVal}, "=") } - + tf := c.terraform(dir, *pc.Spec.PluginCache, cr.Spec.EnableTerraformCLILogging, l, envs...) if cr.Status.AtProvider.Checksum != "" { checksum, err := tf.GenerateChecksum(ctx) diff --git a/internal/terraform/terraform.go b/internal/terraform/terraform.go index aab58fd0..099b5279 100644 --- a/internal/terraform/terraform.go +++ b/internal/terraform/terraform.go @@ -25,8 +25,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "github.com/crossplane/crossplane-runtime/pkg/logging" - "github.com/pkg/errors" "os" "os/exec" "path/filepath" @@ -36,6 +34,9 @@ import ( "strings" "sync" "syscall" + + "github.com/crossplane/crossplane-runtime/pkg/logging" + "github.com/pkg/errors" ) // Error strings. @@ -567,14 +568,14 @@ func (h Harness) Diff(ctx context.Context, o ...Option) (bool, error) { // 2 - Succeeded, there is a diff log, err := runCommand(ctx, cmd) switch cmd.ProcessState.ExitCode() { - case 1: + case 1: ee := &exec.ExitError{} errors.As(err, &ee) - if h.EnableTerraformCLILogging{ + if h.EnableTerraformCLILogging { h.Logger.Info(string(ee.Stderr)) } case 2: - if h.EnableTerraformCLILogging{ + if h.EnableTerraformCLILogging { h.Logger.Info(string(log)) } return true, nil @@ -614,13 +615,13 @@ func (h Harness) Apply(ctx context.Context, o ...Option) error { log, err := runCommand(ctx, cmd) switch cmd.ProcessState.ExitCode() { case 0: - if h.EnableTerraformCLILogging{ + if h.EnableTerraformCLILogging { h.Logger.Info(string(log)) } default: ee := &exec.ExitError{} errors.As(err, &ee) - if h.EnableTerraformCLILogging{ + if h.EnableTerraformCLILogging { h.Logger.Info(string(ee.Stderr)) } } @@ -659,13 +660,13 @@ func (h Harness) Destroy(ctx context.Context, o ...Option) error { // Non Zero output - Errored switch cmd.ProcessState.ExitCode() { case 0: - if h.EnableTerraformCLILogging{ + if h.EnableTerraformCLILogging { h.Logger.Info(string(log)) } default: ee := &exec.ExitError{} errors.As(err, &ee) - if h.EnableTerraformCLILogging{ + if h.EnableTerraformCLILogging { h.Logger.Info(string(ee.Stderr)) } }