Skip to content

Commit

Permalink
chore: debug option to leave workspace on disk (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm authored Oct 3, 2024
1 parent 9095fc0 commit b169012
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ no longer marked as primary.
## Broker Service Configuration

Broker service configuration values:

| Environment Variable | Config File Value | Type | Description |
|----------------------|------|-------------|------------------|
| <tt>SECURITY_USER_NAME</tt> <b>*</b> | api.user | string | <p>Broker authentication username</p>|
Expand All @@ -86,9 +87,18 @@ Broker service configuration values:
| <tt>TLS_CERT_CHAIN</tt> | api.certCaBundle | string | <p>File path to a pem encoded certificate chain</p>|
| <tt>TLS_PRIVATE_KEY</tt> | api.tlsKey | string | <p>File path to a pem encoded private key</p>|


## Debugging
Values for debugging:

| Environment Variable | Config File Value | Type | Description |
|----------------------------------------|---------------------------|------|-------------------------------------------------------------------------------------------------|
| <tt>CSB_DEBUG_LEAVE_WORKSPACE_DIR</tt> | 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 |
|----------------------|------|-------------|------------------|----------|
| <tt>GSB_COMPATIBILITY_ENABLE_BUILTIN_BROKERPAKS</tt> <b>*</b> | compatibility.enable_builtin_brokerpaks | Boolean | <p>Load brokerpaks that are built-in to the software.</p>| "true" |
Expand Down
21 changes: 16 additions & 5 deletions pkg/providers/tf/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit b169012

Please sign in to comment.