Terraform Code Generation
The Instaclustr API and Terraform Provider v2 provides a convenient method to import resources that have been provisioned on Instaclustr. The Terraform Code Generation API allows users to download a ZIP of a collection of Terraform (.tf
) files containing the HCL (HashiCorp Configuration Language) definitions for all of the resources created on Instaclustr that is supported by the Instaclustr Terraform Provider v2.
Download Terraform resources through the Console
To download a ZIP of the Terraform resources for your account –
- Navigate to your account on the Instaclustr Console.
- Click on the settings cog on the top right hand corner.
- Click on “Cluster Resources”.
- Navigate to the “Terraform” tab and click on the “Download” button.
The downloaded ZIP will contain .tf
files containing the Terraform code for the resources created under the account. See Using the “Import All” Script below on instructions on using the packaged script to automatically import the resources and generate a Terraform state.
Download and import Terraform resources through a script
To automatically download the HCL code for Instaclustr resources and import all of the Terraform resources that are compatible with the Instaclustr Terraform Provider v2, the Auto Import script script can be used.
The Auto Import script is best suited for users who have already created resources on Instaclustr through the Instaclustr Console or API and wish to start using the Instaclustr Terraform Provider v2 with minimal effort. This script is also useful for users who do not have a specific requirement in structuring Terraform files.
Alternatively, the Download script can be used to easily download the ZIP file containing the Terraform files to a preferred location. This script is useful for users who have a specific requirement in structuring Terraform resources, and for those who have set naming conventions for Terraform resource names. The Download script and the Terraform Code Generation API offers a benefit to such users by providing the exact HCL code that represents the provisioned Instaclustr resources.
Using the Auto Import Script
For customers who are migrating to Terraform, or for those who do not have specific requirements in structuring Terraform code representing Instaclustr resource, the Auto Import script provides a “on-command” solution to conveniently generate and import Terraform code for Instaclustr resources in an automated manner.
Executing the Auto Import script will automatically download the ZIP containing all of the Terraform files representing Terraform Provider v2 compatible resources provisioned through Instaclustr, unzip the files and automatically import all of the generated resources and produce a Terraform state file. Instaclustr supports using the Auto Import script on Unix and Windows based environments.
The script depends on the existence of the environment variables IC_USERNAME
and IC_API_KEY
. You may configure these environment variables in your preferred method of choosing to meet necessary security requirements and avoid committing your Instaclustr API Key into your terminal’s history.
Unix based environments
For Unix based environments, the “auto import” shell script file can be downloaded from the Instaclustr Terraform Provider’s Github repository. The usage definition of the command is as follows:
1 |
./instaclustr-auto-tf-import.sh <destination_directory> [auto-approve] |
[auto-approve]
is an optional argument which will skip the confirmation prompt about emptying the directory provided by <destination_directory>
.
The script could also be used as follows to provide the necessary environment variables while executing it:
1 |
IC_USERNAME=<instaclustr_username> IC_API_KEY=<instaclustr_provisioning_api_key> ./instaclustr-auto-tf-import.sh <destination_directory> [auto-approve] |
Windows environments
For Windows based environments, the “auto import” Powershell script can be downloaded from the Instaclustr Terraform Provider’s Github repository. The usage definition of the command is as follows:
1 |
./instaclustr-auto-tf-import.ps1 <destination_directory> [auto-approve] |
[auto-approve]
is an optional argument which will skip the confirmation prompt about emptying the directory provided by <destination_directory>
.
The script could also be used as follows to provide the necessary environment variables while executing it:
1 2 3 4 5 |
$env:IC_USERNAME="<instaclustr_username>"; $env:IC_API_KEY="<instaclustr_provisioning_api_key>"; ./instaclustr-auto-tf-import.ps1 <destination_directory> [auto-approve]; Remove-Item Env:IC_USERNAME; Remove-Item Env:IC_API_KEY; |
Using the Download Script
For customers who have specific requirements in structuring Terraform code across multiple modules or specific naming conventions for Terraform resources, the Download script provides a convenient method to download the ZIP file containing the Terraform files from the Instaclustr API.
The scripts below depend on the existence of the environment variables IC_USERNAME
and IC_API_KEY
. You may configure these environment variables in your preferred method of choosing to meet necessary security requirements and avoid committing your Instaclustr API Key into your terminal’s history.
Unix based environments
For Unix based environments, a shell script file is made available for which the usage definition is:
1 |
./instaclustr-download-tf-import.sh <path_to_output_file> |
The script could also be used as follows to provide the necessary environment variables while executing it:
1 |
IC_USERNAME=<instaclustr_username> IC_API_KEY=<instaclustr_provisioning_api_key> ./instaclustr-download-tf-import.sh <path_to_output_file> |
Windows environments
For Windows users, an equivalent Powershell script is available for which the usage definition is:
1 |
./instaclustr-download-tf-import.ps1 <path_to_output_file> |
The script could also be used as follows to provide the necessary environment variables while executing it:
1 2 3 4 5 |
$env:IC_USERNAME="<instaclustr_username>"; $env:IC_API_KEY="<instaclustr_provisioning_api_key>"; ./instaclustr-download-tf-import.ps1 <path_to_output_file>; Remove-Item Env:IC_USERNAME; Remove-Item Env:IC_API_KEY; |
Using the “Import All” Script
The downloaded ZIP contains an executable script “import-all” which has all of the import commands to be executed for the generated Terraform code.
Unix based environments
For Unix based environments, the “import-all” script for which the usage definition is as follows:
1 |
sh import-all.sh |
The script could also be used as follows to provide the necessary environment variables while executing it:
1 |
IC_USERNAME=<instaclustr_username> IC_API_KEY=<instaclustr_provisioning_api_key> sh import-all.sh |
Windows environments
For Windows environments, the following equivalent Powershell script can be used with the usage definition:
1 |
./import-all.ps1 |
The script could also be used as follows to provide the necessary environment variables while executing it:
1 2 3 4 5 |
$env:IC_USERNAME="<instaclustr_username>"; $env:IC_API_KEY="<instaclustr_provisioning_api_key>"; ./import-all.ps1; Remove-Item Env:IC_USERNAME; Remove-Item Env:IC_API_KEY; |
Additional Resources:
- Instaclustr Terraform Provider Github: https://github.com/instaclustr/terraform-provider-instaclustr
- Instaclustr Terraform Registry (Additional Documentation): https://registry.terraform.io/providers/instaclustr/instaclustr/latest/docs
- Instaclustr Provisioning API Documentation: https://www.instaclustr.com/support/api-integrations/api-reference/provisioning-api/
- Instaclustr Open Source Project Status: https://www.instaclustr.com/support/documentation/announcements/instaclustr-open-source-project-status/