Banyan Terraform Import Tool

  • Updated on Nov 07, 2023
  • 5 minutes to read

Note: This script may cause changes to or have unintended consequences in your environment and we advise you to reach out to your Banyan customer success representative to guide you through it.

Banyan Terraform Import Tool Overview

The Banyan Terraform Import Tool is a command-line utility that allows you to import resources from the Banyan API and generate Terraform configuration files for managing those resources. This tool simplifies the process of managing Banyan resources via Terraform, making it easier to automate your infrastructure setup.

Prerequisites

Before using this tool, ensure that you have the following installed on your system:

Install Banyan Terraform Import Tool

1. Clone this repository to your local machine:

`git clone https://github.com/banyansecurity/terraform-resource-importer.git`

2. Navigate to the project directory:

`cd terraform-resource-importer`

3. Install the required Python packages using pip:

`pip install -r requirements.txt`

Use the Terraform Import Tool

To use the Banyan Terraform Import Tool, complete the following steps:

Step 1: Generate configuration files based on imported resources

1.1 Open a Terminal window, and navigate to the project directory.

1.2 Run the tool using the following command:

 python main.py --help
Usage: main.py [OPTIONS] API_KEY

Arguments:
  API_KEY  [required]

Options:
  --resource [service|policy|role|all]
                                  resource to be imported  [required]
  --resource-type [all|web|db|k8s|rdp|ssh|tcp|infra|tunnel]
                                  Type of selected resource to be imported,
                                  for --resource service options are [all,
                                  web, db, k8s, rdp, ssh, tcp] for --resource
                                  policy options are [all, web, infra, tunnel]
                                  for --resource role need not set this option
                                  or can provide value [all]   [required]
  --console [net|preview|release]
                                  [default: net]
  --folder TEXT
  --module / --no-module          [default: no-module]
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.
  --help                          Show this message and exit.

The tool will generate the necessary configuration files based on the imported resources. Next, use Terraform to apply or manage the infrastructure as needed.

Step 2: Execute Terraform commands to manage your resources

Note: Once you import your Banyan resources into Terraform, you may now use the import.tf file as well as the generated.tf or separated Terraform code files in your Terraform code. Ensure that your code uses the Banyan Terraform Provider v1.2.5 or above.

2.1 Run the following commands:

terraform init

terraform plan

terraform apply

Note: The command terraform plan should display the number of resources being imported, and NOT the number of added or updated or removed.

Examples

Here are some example commands to use the Banyan Terraform Import Tool:

Import services with separate configuration files

python main.py --api-key <banyan_api_key> --resource service --resource-type web --console net --separate-files

Import policies with a single configuration file

python main.py --api-key <banyan_api_key> --resource policy --resource-type infra --console release

Support

If you encounter any issues or have questions, please open an issue on the GitHub repository.