Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add debug configuration #27

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug CLI command",
"type": "go",
"request": "launch",
"mode": "debug",
"preLaunchTask": "Build CLI",
"program": "${workspaceFolder}/main.go",
"args": "${input:cliArgs}",
"console": "integratedTerminal",
"env": {
"BTP_USERNAME": "",
"BTP_ENABLE_SSO": "true",
"BTP_GLOBALACCOUNT": ""
},
//"envFile": "${workspaceFolder}/.env"
},
],
"inputs": [
{
"id": "cliArgs",
"type": "promptString",
"description": "Args for launching btptfexporter CLI. Use --cwd to set the working directory.",
"default": "resource all -s"
}
]
}
29 changes: 29 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build CLI",
"detail": "Builds the CLI make build",
"command": "make",
"type": "shell",
"args": [
"build"
],
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": "$gcc",
"presentation": {
"echo": true,
"reveal": "silent",
"panel": "shared",
"showReuseMessage": false,
"clear": true
}
}
]
}
3 changes: 3 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
autocompletion
breakpoint
BTP
btp
btptfexporter
Expand Down Expand Up @@ -26,6 +27,8 @@ powershell
README
resourceFileName
spf
SSO
sso
subaccount
Subaccount
subaccounts
Expand Down
41 changes: 40 additions & 1 deletion DEVELOPER-GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,48 @@

TBD

## Debug the CLI

We provide a configuration for debugging the btptfexporter commands in VS Code. The configuration is available in the `.vscode` directory as `launch.json`

Here is an example on how to debug the command `btptfexporter resource all`:

1. Set a breakpoint in the file `cmd/exportAll.go` in the run section of the command:

<img src="assets/devguide-pics/debug0.png" alt="Set a breakpoint in VS Code" width="600px">

1. Adjust the `launch.json` configuration to consider your environment variable values. The default are single variables using SSO in the root of the repository:

<img src="assets/devguide-pics/debug0b.png" alt="VS Code Debug launch configuration" width="600px">

> [!WARNING]
> The environment values will be displayed as clear text in the debug console. If you are using your password as environment paramater this will become visible when you start debugging. We therefore highly recommend to use the SSO option.

1. Open the debug perspective in the VS Code side bar:

<img src="assets/devguide-pics/debug1.png" alt="VS Code Side bar" width="50px">

1. Select the configuration `Debug CLI command`:

<img src="assets/devguide-pics/debug2.png" alt="VS Code debug configuration options" width="600px">

1. Run the selection by pressing the green triangle:

<img src="assets/devguide-pics/debug3.png" alt="Run debug configuration" width="600px">

1. VS Code will prompt you for the command via the command palette. It defaults to `resource all -s`. Enter the command and the parameters you want to use for the command execution. In our case we add a subaccount ID and confirm by pressing `Enter`:

<img src="assets/devguide-pics/debug4.png" alt="Prompt for parameters in debug configuration" width="600px">

1. The debugger will start and hit the breakpoint:

<img src="assets/devguide-pics/debug5.png" alt="VS Code hitting breakpoint" width="600px">

Happy debugging!

## Generate markdown documentation

We can generate the markdown documentation via the make file:
When updating command descriptions you must generate the markdown documentation via the make file:

```bash
make docs
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ If you want to build the binary from scratch, follow these steps:

1. The system will store the binary as `btptfexporter` (`btptfexporter.exe` in case of Windows) in the default binary path of your Go installation `$GOPATH/bin`.

> **Note** - You find the value of the GOPATH via `go env GOPATH`
> > [!TIP]
> You find the value of the GOPATH via `go env GOPATH`

#### Troubleshooting

##### Binary not executable (MacOS or Linux)

In case you get an error that the binary is not executable, naviigate to the location of the binary and execute the following command:
In case you get an error that the binary is not executable, navigate to the location of the binary and execute the following command:

```bash
chomd +x btptfexporter
Expand All @@ -63,6 +64,7 @@ After executing the [setup](#setup) of the CLI you must set some required enviro

- Specify a custom IdP for the authentication via `BTP_IDP`
- Specify a URL of the BTP CLI server (SAP internal only) via `BTP_CLI_SERVER_URL`
- Specify the login using SSO via `BTP_ENABLE_SSO` (true/false)

The parameters correspond to the Terraform provider configuration options you find in the [BTP Terraform Provider documentation](https://registry.terraform.io/providers/SAP/btp/latest/docs)

Expand Down Expand Up @@ -104,10 +106,11 @@ How to set the parameters depends on your setup and is OS-specific:
- Execute the following command in a terminal:

```bash
export $(xargs <.env)`
export $(xargs <.env)
```

> **Note** - There is no predefined fucntionality in PowerShell to achieve the same. A custom script would be needed.
> > [!IMPORTANT]
> There is no predefined functionality in PowerShell to achieve the same. A custom script would be needed.

## Commands

Expand Down
Binary file added assets/devguide-pics/debug0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/devguide-pics/debug0b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/devguide-pics/debug1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/devguide-pics/debug2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/devguide-pics/debug3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/devguide-pics/debug4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/devguide-pics/debug5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions generated_configurations/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions generated_configurations/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
terraform {
required_providers {
btp = {
source = "SAP/btp"
version = "1.6.0"
}
}
}

provider "btp" {
globalaccount = "terraformintprod"
}
Loading