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 –

  1. Navigate to your account on the Instaclustr Console.
  2. Click on the settings cog on the top right hand corner.
  3. Click on “Cluster Resources”.
  4. 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:

[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:

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:

[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:

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:

The script could also be used as follows to provide the necessary environment variables while executing it:

Windows environments

For Windows users, an equivalent Powershell script is available for which the usage definition is: 

The script could also be used as follows to provide the necessary environment variables while executing it:

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:

The script could also be used as follows to provide the necessary environment variables while executing it:

Windows environments

For Windows environments, the following equivalent Powershell script can be used with the usage definition:

The script could also be used as follows to provide the necessary environment variables while executing it:

Additional Resources: 

By Instaclustr Support
Need Support?
Experiencing difficulties on the website or console?
Already have an account?
Need help with your cluster?
Contact Support
Why sign up?
To experience the ease of creating and managing clusters via the Instaclustr Console
Spin up a cluster in minutes