From b169012bff806cbc400d1e986007baaed96ff75b Mon Sep 17 00:00:00 2001 From: George Blue Date: Thu, 3 Oct 2024 13:14:35 +0100 Subject: [PATCH] chore: debug option to leave workspace on disk (#1025) --- docs/configuration.md | 10 ++++++++++ pkg/providers/tf/workspace/workspace.go | 21 ++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 80df62af8..a58e7f609 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -78,6 +78,7 @@ no longer marked as primary. ## Broker Service Configuration Broker service configuration values: + | Environment Variable | Config File Value | Type | Description | |----------------------|------|-------------|------------------| | SECURITY_USER_NAME * | api.user | string |

Broker authentication username

| @@ -86,9 +87,18 @@ Broker service configuration values: | TLS_CERT_CHAIN | api.certCaBundle | string |

File path to a pem encoded certificate chain

| | TLS_PRIVATE_KEY | api.tlsKey | string |

File path to a pem encoded private key

| + +## Debugging +Values for debugging: + +| Environment Variable | Config File Value | Type | Description | +|----------------------------------------|---------------------------|------|-------------------------------------------------------------------------------------------------| +| CSB_DEBUG_LEAVE_WORKSPACE_DIR | debug.leave_workspace_dir | bool | Disables the cleanup of workspace directories, so you can inspect the files and run tf commands | + ## Feature flags Configuration Feature flags can be toggled through the following configuration values. See also [source code occurences of "toggles.Features.Toggle"](https://github.com/cloudfoundry/cloud-service-broker/search?q=toggles.Features.Toggle&type=code) + | Environment Variable | Config File Value | Type | Description | Default | |----------------------|------|-------------|------------------|----------| | GSB_COMPATIBILITY_ENABLE_BUILTIN_BROKERPAKS * | compatibility.enable_builtin_brokerpaks | Boolean |

Load brokerpaks that are built-in to the software.

| "true" | diff --git a/pkg/providers/tf/workspace/workspace.go b/pkg/providers/tf/workspace/workspace.go index 2da28988f..a54073c87 100644 --- a/pkg/providers/tf/workspace/workspace.go +++ b/pkg/providers/tf/workspace/workspace.go @@ -25,18 +25,27 @@ import ( "strings" "sync" + "github.com/spf13/viper" + "github.com/cloudfoundry/cloud-service-broker/v2/pkg/providers/tf/command" "github.com/cloudfoundry/cloud-service-broker/v2/pkg/providers/tf/executor" "github.com/hashicorp/go-version" ) -// DefaultInstanceName is the default name of an instance of a particular module. const ( - DefaultInstanceName = "instance" - binaryName = "tofu" + // DefaultInstanceName is the default name of an instance of a particular module. + DefaultInstanceName = "instance" + binaryName = "tofu" + leaveWorkspaceDirectoryConfigKey = "debug.leave_workspace_dir" + leaveWorkspaceDirectoryEnvVar = "CSB_DEBUG_LEAVE_WORKSPACE_DIR" ) +func init() { + viper.BindEnv(leaveWorkspaceDirectoryConfigKey, leaveWorkspaceDirectoryEnvVar) + viper.SetDefault(leaveWorkspaceDirectoryConfigKey, false) +} + // NewWorkspace creates a new TerraformWorkspace from a given template and variables to populate an instance of it. // The created instance will have the name specified by the DefaultInstanceName constant. func NewWorkspace(templateVars map[string]any, @@ -287,8 +296,10 @@ func (workspace *TerraformWorkspace) teardownFs() error { workspace.State = bytes - if err := os.RemoveAll(workspace.dir); err != nil { - return err + if !viper.GetBool(leaveWorkspaceDirectoryConfigKey) { + if err := os.RemoveAll(workspace.dir); err != nil { + return err + } } workspace.dir = ""