Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Suresh Ramasamy <[email protected]>
  • Loading branch information
Suresh Ramasamy authored and savkumar committed Apr 10, 2024
1 parent 9ec54dc commit 5fc3e09
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 35 deletions.
6 changes: 3 additions & 3 deletions apis/v1beta1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -149,11 +150,11 @@ 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()
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
o.Encoder = zapcore.NewJSONEncoder(encoderConfig)
}
}

4 changes: 2 additions & 2 deletions docs/monolith/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`
- `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`
17 changes: 0 additions & 17 deletions examples/providerconfig-enable-logging.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion internal/controller/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions internal/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -36,6 +34,9 @@ import (
"strings"
"sync"
"syscall"

"github.com/crossplane/crossplane-runtime/pkg/logging"
"github.com/pkg/errors"
)

// Error strings.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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))
}
}
Expand Down

0 comments on commit 5fc3e09

Please sign in to comment.