Using the Instaclustr Terraform Provider v2
What Is Terraform?
Terraform is an open-source platform that allows you to create, manage, and delete cloud resources in different cloud providers. It allows you to manage your cloud resources via command line interface (CLI) and code rather than having to log into a cloud provider like AWS and manually provision resources through their dashboard.
Instaclustr provides what is known as a “Terraform Provider” that allows users to interact with their Instaclustr resources through Terraform without having to write custom API scripts themselves. It acts as a wrapper that makes provisioning resources in the customer’s Instaclustr account a plug-and-play experience.
What Is a Terraform Provider?
In technical terms, a Terraform provider is a logical abstraction of an upstream API. Instead of having to write custom API calls, you can use a Terraform provider. In other terms, you can use a provider to use Terraform to interact with an API without writing any of the API calls yourself.
There is a list of Terraform providers that are used for common platforms such as GCP, AWS, Azure, Kubernetes, and more that can be viewed here.
What Can You Do with Instaclustr’s Terraform Provider v2?
Instaclustr provides a Terraform Provider that allows users to interact directly with and provision cloud resources for their Instaclustr infrastructure via Terraform without writing their own code to connect the APIs together. This makes it simpler for customers to integrate Instaclustr provisioning and management into their current workflows. It is also easier and quicker to do all the actions needed such as creating and deleting clusters.
NOTE: Since Instaclustr Terraform Provider v1 has been deprecated, the focus of this documentation further on will be on the Instaclustr Terraform Provider v2.
Currently, the Instaclustr Terraform Provider v2 works with all three major cloud providers: AWS, Azure, and GCP. The different clouds can be switched by changing the cloud_provider
variable within the Terraform code.
Our Terraform Provider works with open-source technologies we currently offer, including Apache Cassandra, Apache Kafka, OpenSearch, Redis, Apache ZooKeeper, Cadence, and Kafka add-ons.
The Instaclustr Terraform Provider v2 works by making use of the Instaclustr Provisioning API, and makes the necessary calls to be able to provision and manage resources through Terraform.
Migrating from v1 to v2 of the Instaclustr Terraform Provider
If you have been using the first version of Instaclustr Terraform Provider and want to migrate to Instaclustr Terraform Provider v2, please refer to the Github documentation.
Examples and How-To
The Instaclustr Terraform Provider v2 is easy to install and start using with Terraform. Below we have a few code snippets so you can quickly get started with it. For additional information please see the Github repository as well as the Instaclsutr Terraform Provider v2 registry for additional configuration information.
Installing the Instaclustr Terraform Provider v2
To install the Instaclustr Terraform Provider v2, paste this code into your Terraform configuration and run Terraform in it:
1 2 3 4 5 6 7 8 |
terraform { required_providers { instaclustr = { source = "instaclustr/instaclustr" version = ">= 2.0.0, < 3.0.0" } } } |
Authentication
To authenticate with Instaclustr, you first need to obtain your API key. It can be found within your Instaclustr account under the Account Settings ⇒ API Keys page; then locate the Provisioning role and click the Add button to generate a key.
In order to keep the api_key variable secret in your environment, instead of stored in your Terraform file like the username variable, use the following method:
1. Export the desired variable:
1 |
export api_key=<update-with-your-instaclustr-provisioning-api-key> |
2. Create a variable in your Terraform file:
1 2 3 4 |
variable "api_key" { type = string default = "xxx" } |
Your username and key can then be placed in the following snippet as an example:
1 2 3 |
provider "instaclustr" { terraform_key = "Instaclustr-Terraform <update-with-your-username>:${var.api_key}" } |
When running terraform operations, pipe in the variables as follows:
1 |
terraform apply -var="api_key=$api_key" |
AWS Example
Below is a quick example of how the Instaclustr Terraform Provider v2 can be used with AWS to provision an Instaclustr for Apache Kafka cluster – see the Instaclustr Terraform Provider v2 registry | instaclustr_kafka_cluster_v2 (Resource).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
resource "instaclustr_kafka_cluster_v2" "example" { auto_create_topics = true client_to_cluster_encryption = true pci_compliance_mode = false data_centre { cloud_provider = "AWS_VPC" name = "AWS_VPC_US_EAST_1" network = "10.0.0.0/16" node_size = "KFK-PRD-r6g.large-250" number_of_nodes = 3 region = "US_EAST_1" } dedicated_zookeeper { zookeeper_node_count = 3 zookeeper_node_size = "KDZ-PRD-m6g.large-80" } default_replication_factor = 3 private_network_cluster = false kafka_version = "[x.y.z]" default_number_of_partitions = 3 name = "MyKafkaCluster" sla_tier = "NON_PRODUCTION" allow_delete_topics = true } |
Multi-Data Centre Provisioning
It is possible to provision resources on multiple data centres in a single call. For multi-data centre provisioning, follow the pattern shown in the Instaclustr Terraform Provider v2 registry | instaclustr_cassandra_cluster_v2 (Resource).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
resource "instaclustr_cassandra_cluster_v2" "example" { pci_compliance_mode = false data_centre { client_to_cluster_encryption = true cloud_provider = "AWS_VPC" continuous_backup = true name = "MyTestDataCentre1" network = "10.0.0.0/16" node_size = "CAS-PRD-m6g.large-120" number_of_nodes = 3 private_ip_broadcast_for_discovery = true region = "US_EAST_1" replication_factor = 3 } data_centre { client_to_cluster_encryption = true cloud_provider = "AWS_VPC" continuous_backup = true debezium { kafka_cdc_id = "[some CDC ID]" kafka_topic_prefix = "MyTopicPrefix" kafka_vpc_type = "VPC_PEERED" version = "[x.y.z]" } name = "MyTestDataCentre2" network = "10.1.0.0/16" node_size = "CAS-PRD-m6g.large-120" number_of_nodes = 3 private_ip_broadcast_for_discovery = true region = "US_EAST_2" replication_factor = 3 } private_network_cluster = false cassandra_version = "[x.y.z]" lucene_enabled = true password_and_user_auth = true name = "MyTestCluster" two_factor_delete { } sla_tier = "NON_PRODUCTION" } |
Conclusion
Instaclustr Terraform Provider v2 allows you to use Terraform to provision and manage your Instaclustr resources without needing to use the Console. This lets you easily integrate Instaclustr resource provisioning and managing into your current Terraform setup. In this blog we’ve covered how to quickly get started; for additional information please see the resources below.
Additional Resources:
- Instaclustr Terraform Provider Github Repository
- Instaclustr Terraform Registry | Instaclustr Documentation
- Instaclustr Provisioning API Documentation
- Instaclustr Open Source Project Status