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

Docs: spelling #19

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: spellcheck
name: Spell Checker
on:
pull_request:
types:
Expand Down
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ terraform.rc
###
# enf of gitignore Terraform
###

###
# gitignore devcontainer
###

devcontainer.env

###
# enf of gitignore devcontainer
###
16 changes: 14 additions & 2 deletions .wordlist.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
autocompletion
bash
BTP
btp
btptfexporter
CLA
config
DCO
dependabot
devcontainer
faq
html
https
Github
github
Golang
html
https
json
JSON
macOS
md
Pre
PowerShell
powershell
README
resourceFileName
spf
subaccount
Subaccount
subaccounts
subaccount's
subcommands
Terraform
terraform
tf
toolchain
UIs
UI
VS
YAML
yaml
yml
zsh
11 changes: 11 additions & 0 deletions DEVELOPER-GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Developer Guide

TBD

## Generate markdown documentation

We can generate the markdown documentation via the make file:

```bash
make docs
```
120 changes: 74 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,112 @@

The *Terraform Exporter for SAP BTP* is a tool that helps export resources from a BTP Global Account. It can generate Terraform scripts for the resources and import those resources into a Terraform state file.

## Requirements and Setup
## Setup

You have two options to setup the CLI:

1. Local build
1. Download the pre-built binary

The following sections describe the details for the two options.


### Pre-built binary

The easiest way to get the binary is to download from the [releases section](https://github.com/SAP/terraform-exporter-btp/releases) of this repository. Select the version you want to use and download the binary that fits your operating system from the `assets` of the release. We recommend using the latest version.


### Local build

If you want to build the binary from scratch, follow these steps:

1. Open this repository inside VS Code Editor
1. We have setup a devcontainer, so open the repository using devcontainer.
1. Build the binary: From the terminal in VS Code run `make build` & `make install`
1. A file (binary) `btptfexporter` will be found in the default binary path of your Go installation.
1. Make it executable: `chomd +x btptfexporter`.
1. We have setup a devcontainer, so reopen the repository in the devcontainer.
1. Open a terminal in VS Code and build the binary by running

### Pre-built binary
```bash
make build
make install
```

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

> **Note** - You find the value of the GOPATH via `go env GOPATH`

1. You must make the executable executable via the command:

Please go to the releases section of this repository and download the binary for your system.
```bash
chomd +x btptfexporter
```

## Usage

1. [Download](https://github.tools.sap/BTP-Terraform/btptfexporter/releases/tag/v0.0.3-poc) or build the binary to a local path/folder.
1. Create the following required environment variables: `BTP_USERNAME`, `BTP_PASSWORD`, `BTP_GLOBALACCOUNT`
Optionally, you can set the following parameters: `BTP_CLIENT_SERVER_URL`, `BTP_IDP`, `BTP_TLS_CLIENT_CERTIFICATE`, `BTP_TLS_CLIENT_KEY`, `BTP_TLS_IDP_URL`. Please refer the [BTP Terraform Provider documentation](https://registry.terraform.io/providers/SAP/btp/latest/docs) to learn more about these parameters.
After executing the [setup](#setup) of the CLI you must set some required environment variables needed for authentication.

> **Note** - You can also define a `.env` file with the content of the parameters and export this file via `export $(xargs <.env)`.
1. Set the environment variable `BTP_GLOBALACCOUNT` which specifies the *subdomain* of your SAP BTP global account.
1. Depending on the authentication flow, set the following environment variables:

1. use the `--help` flag to know more.
- Basic Authentication: set the environment variable `BTP_USERNAME` and `BTP_PASSWORD`
- X509 Authentication: set the envionment variables `BTP_TLS_CLIENT_CERTIFICATE`, `BTP_TLS_CLIENT_KEY`, `BTP_TLS_IDP_URL`

## Commands
1. In addition you can set the following optional parameters as environment variables, depending on your requirements:

### resource : Export specific btp resources from a subaccount
- 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`

Use this command to create terraform configuration for all the resources of a subaccount or specific resource using the subcommands

```bash
btptfexporter resource [command]
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)

Example:
How to set the parameters depends on your setup and is OS-specific:

btptfexporter resource all --subaccount <subaccount-id>
- On Windows (example):

Available Commands:
```powershell
$env:BTP_USERNAME=<MY SAP BTP USERNAME>
```

all export all resources of a subaccount
entitlements export entitlements of a subaccount
environment-instances export environment instance of a subaccount
from-file export resources from a json file.
subaccount export subaccount
subscriptions export subscriptions of a subaccount
trust-configurations export trust configurations of a subaccount
- On MacOS and Linux (example):

```
```bash
export BTP_USERNAME=<MY SAP BTP USERNAME>
```

### generate-resources-list : Store the list of resources from btp subaccount into a json file
- In a devcontainer:
- Create a file `devcontainer.env` in the `.devcontainer` directory
- Add the environment variables in the file. Here is an example:

Use this command to get the list of resources from a subaccont and store it in a json file.
```txt
BTP_USERNAME='<MY SAP BTP USERNAME>'
BTP_PASSWORD='<MY SAP BTP PASSWORD>'
BTP_GLOBALACCOUNT='<MY SAP BTP GLOBAL ACCOUNT SUBDOMAIN>'
```
- Start the devcontainer variant `Terraform exporter for SAP BTP - Development (with env file)`. The environment variables defined in the .`devcontainer.env` filewill be automatically injected.

```bash
btptfexporter generate-resources-list [flags]
- Alternative via `.env` file (available on MacOS and Linux only):
- Create a file `.env` in the root of the project
- Add the environment variables in the file. Here is an example:

Example:
```txt
BTP_USERNAME='<MY SAP BTP USERNAME>'
BTP_PASSWORD='<MY SAP BTP PASSWORD>'
BTP_GLOBALACCOUNT='<MY SAP BTP GLOBAL ACCOUNT SUBDOMAIN>'
```
- Execute the following command in a terminal:

btptfexporter generate-resources-list --resources=entitlements,subscriptions --subaccount=<subacount_id>
```
```bash
export $(xargs <.env)`
```
> **Note** - There is no predefined fucntionality in PowerShell to achieve the same. A custom script would be needed.

Valid resources are:
- subaccount
- entitlements
- subscriptions
- environment-instances
- trust-configurations
1. use the `--help` flag to know more.

## Commands

### Generate markdown documentation
The CLI offers several commands for the export of Terraform configurations of SAP BTP. You find a comprehensive overview of the commands and the options in the [documentation](./docs/btptfexporter.md).

We can generate the markdown documentation via the make file:
## Developer Guide

```bash
make docs
```
If you want to contribute to the code of the Terraform Exporter for SAP BTP, please check our [Contribution Guidelines](CONTRIBUTING.md). The technical setup and how to get started are described in the [Developer Guide](DEVELOPER-GUIDE.md)

## Support, Feedback, Contributing

Expand Down
6 changes: 3 additions & 3 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ var exportCmd = &cobra.Command{
Short: "Export specific btp resources from a subaccount",
Long: `
This command is used when you need to export specific resources.
By default,tt will generate the <resource_name>_import.tf (import file) and resources.tf (resource file) files.
The resources.tf file can be renamed by using the --resourceFileName.
The command will fail if a reource file file already exists`,
By default, it will generate the <resource_name>_import.tf (import file) and resources.tf (resource file) files.
The resources.tf file can be renamed by using the flag --resourceFileName.
The command will fail if a resource file already exists`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Invalid command\n\nUse 'btptfexporter export --help' for syntax instructions.\n\nERROR")
//fmt.Println("please provide the resource to be imported with this commnad. Supported resources are subaccount, entilements, environment-instances, subscriptions, trust-configurations")
Expand Down
2 changes: 1 addition & 1 deletion cmd/exportAll.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var exportAllCmd = &cobra.Command{
Short: "export all resources of a subaccount",
Long: `export all will export all the resources from a subaccount. Currently only few resources are supported.

exportAll is a single command to export btp_subaccount, btp_subaccount_entitlements, btp_subaccount_instances, btp_subaccount_subscriptions,
export all is a single command to export btp_subaccount, btp_subaccount_entitlements, btp_subaccount_instances, btp_subaccount_subscriptions,
btp_subaccount_trust_configurations `,
Run: func(cmd *cobra.Command, args []string) {
subaccount, _ := cmd.Flags().GetString("subaccount")
Expand Down
2 changes: 1 addition & 1 deletion cmd/exportEnvironmentInstances.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var exportEnvironmentInstancesCmd = &cobra.Command{
Use: "environment-instances",
Short: "export environment instance of a subaccount",
Long: `exportEnvironmentInstance will export all the environment instance of the given subaccount and gererate resource configuration for it`,
Long: `export environment-instance will export all the environment instance of the given subaccount and generate resource configuration for it`,
Run: func(cmd *cobra.Command, args []string) {
subaccount, _ := cmd.Flags().GetString("subaccount")
resourceFileName, _ := cmd.Flags().GetString("resourceFileName")
Expand Down
2 changes: 1 addition & 1 deletion cmd/exportSubaccountEntitlements.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var exportSubaccountEntitlementsCmd = &cobra.Command{
Use: "entitlements",
Short: "export entitlements of a subaccount",
Long: `exportSubaccountEntitlements will export all the entitlements of the given subaccount and gererate resource configuration for it`,
Long: `export entitlements will export all the entitlements of the given subaccount and generate resource configuration for it`,
Run: func(cmd *cobra.Command, args []string) {
subaccount, _ := cmd.Flags().GetString("subaccount")
resourceFileName, _ := cmd.Flags().GetString("resourceFileName")
Expand Down
2 changes: 1 addition & 1 deletion cmd/exportSubaccountSubscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var exportSubaccountSubscriptionsCmd = &cobra.Command{
Use: "subscriptions",
Short: "export subscriptions of a subaccount",
Long: `exportSubaccountSubscriptions will export subscriptions of the given subaccount and gererate resource configuration for it`,
Long: `export subscriptions will export subscriptions of the given subaccount and generate resource configuration for it`,
Run: func(cmd *cobra.Command, args []string) {
subaccount, _ := cmd.Flags().GetString("subaccount")
resourceFileName, _ := cmd.Flags().GetString("resourceFileName")
Expand Down
2 changes: 1 addition & 1 deletion cmd/exportTrustConfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
var exportTrustConfigurationsCmd = &cobra.Command{
Use: "trust-configurations",
Short: "export trust configurations of a subaccount",
Long: `exportTrustConfigurations will export trust configurations of the given subaccount and gererate resource configuration for it`,
Long: `export trust-configurations will export trust configurations of the given subaccount and generate resource configuration for it`,
Run: func(cmd *cobra.Command, args []string) {
subaccount, _ := cmd.Flags().GetString("subaccount")
resourceFileName, _ := cmd.Flags().GetString("resourceFileName")
Expand Down
6 changes: 3 additions & 3 deletions cmd/generateConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func configureProvider() {
username := os.Getenv("BTP_USERNAME")
password := os.Getenv("BTP_PASSWORD")
enableSSO := os.Getenv("BTP_ENABLE_SSO")
clientServerURL := os.Getenv("BTP_CLIENT_SERVER_URL")
cliServerURL := os.Getenv("BTP_CLI_SERVER_URL")
globalAccount := os.Getenv("BTP_GLOBALACCOUNT")
idp := os.Getenv("BTP_IDP")
tlsClientCertificate := os.Getenv("BTP_TLS_CLIENT_CERTIFICATE")
Expand All @@ -93,8 +93,8 @@ func configureProvider() {
providerContent = providerContent + "globalaccount = \"" + globalAccount + "\"\n"
}

if len(strings.TrimSpace(clientServerURL)) != 0 {
providerContent = providerContent + "cli_server_url=\"" + clientServerURL + "\"\n"
if len(strings.TrimSpace(cliServerURL)) != 0 {
providerContent = providerContent + "cli_server_url=\"" + cliServerURL + "\"\n"
}

if len(strings.TrimSpace(idp)) != 0 {
Expand Down
7 changes: 5 additions & 2 deletions cmd/generateFIle.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
var getCmd = &cobra.Command{
Use: "generate-resources-list",
Short: "Store the list of resources in a subaccount into a json file",
Long: `generate-resources-list command will get all the resource list or specified resource list in a sub account.
Long: `generate-resources-list command will get all the resource list or specified resource list in a subaccount.
It will then store this list into a file.

For example:

btptfexporter generate-resources-list --resources=subacount,entitlements -s <subaccount-id>
btptfexporter generate-resources-list --resources=subaccount,entitlements -s <subaccount-id>
btptfexporter generate-resources-list --resources=all -s <subaccount-id> -j <file-name.json>

Valid resources are:
Expand All @@ -25,8 +25,11 @@ Valid resources are:
- subscriptions
- environment-instances
- trust-configurations

OR

- all

Mixing "all" with other resources will throw an error.
`,
Run: func(cmd *cobra.Command, args []string) {
Expand Down
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var rootCmd = &cobra.Command{
Use: "btptfexporter",
Short: "Terraform exporter for BTP",
Long: `btptfexporter is a utility to generate configuration for existing btp resources that are created manually and not managed by terraform. btptfexporter help to generate configuration which then can be used by terrraform to bring that resorce under terraform state.
Long: `btptfexporter is a utility to generate configuration for existing btp resources that are created manually and not managed by terraform. btptfexporter help to generate configuration which then can be used by Terraform to bring that resource under terraform state.
`,
}

Expand All @@ -32,8 +32,8 @@ func init() {
}

var docCmd = &cobra.Command{
Use: "gendoc",
Short: "Generate markdown documentation",
Use: "gendoc",
Short: "Generate markdown documentation",
Hidden: true, // Hide the command from the official CLI
Run: func(cmd *cobra.Command, args []string) {
docsDir := "./docs"
Expand All @@ -47,6 +47,8 @@ var docCmd = &cobra.Command{
fmt.Println("Error generating documentation:", err)
os.Exit(1)
}

fmt.Println("Documentation generated successfully in", docsDir)

},
}
4 changes: 2 additions & 2 deletions docs/btptfexporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Terraform exporter for BTP

### Synopsis

btptfexporter is a utility to generate configuration for existing btp resources that are created manually and not managed by terraform. btptfexporter help to generate configuration which then can be used by terrraform to bring that resorce under terraform state.
btptfexporter is a utility to generate configuration for existing btp resources that are created manually and not managed by terraform. btptfexporter help to generate configuration which then can be used by Terraform to bring that resource under terraform state.


### Options
Expand All @@ -20,4 +20,4 @@ btptfexporter is a utility to generate configuration for existing btp resources
* [btptfexporter generate-resources-list](btptfexporter_generate-resources-list.md) - Store the list of resources in a subaccount into a json file
* [btptfexporter resource](btptfexporter_resource.md) - Export specific btp resources from a subaccount

###### Auto generated by spf13/cobra on 10-Sep-2024
###### Auto generated by spf13/cobra on 11-Sep-2024
2 changes: 1 addition & 1 deletion docs/btptfexporter_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ See each sub-command's help for details on how to use the generated script.
* [btptfexporter completion powershell](btptfexporter_completion_powershell.md) - Generate the autocompletion script for powershell
* [btptfexporter completion zsh](btptfexporter_completion_zsh.md) - Generate the autocompletion script for zsh

###### Auto generated by spf13/cobra on 10-Sep-2024
###### Auto generated by spf13/cobra on 11-Sep-2024
2 changes: 1 addition & 1 deletion docs/btptfexporter_completion_bash.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ btptfexporter completion bash

* [btptfexporter completion](btptfexporter_completion.md) - Generate the autocompletion script for the specified shell

###### Auto generated by spf13/cobra on 10-Sep-2024
###### Auto generated by spf13/cobra on 11-Sep-2024
Loading
Loading