Microsoft Azure
This page documents the preview version (v2.23). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.
Prerequisites
Download and install Terraform.
Verify the installation using the terraform
command.
$ terraform
You should see output similar to the following.
Usage: terraform [--version] [--help] <command> [args]
...
Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Workspace management
fmt Rewrites config files to canonical format
Set the Azure credentials
Export the required credentials in your current shell using the following commands:
echo "Setting environment variables for Terraform"
export ARM_SUBSCRIPTION_ID="your_subscription_id"
export ARM_CLIENT_ID="your_appId"
export ARM_CLIENT_SECRET="your_password"
export ARM_TENANT_ID="your_tenant_id"
For instructions on installing Terraform and configuring it for Azure, see Quickstart: Configure Terraform in Azure Cloud Shell with Bash.
Create a Terraform configuration file
Create a Terraform configuration file named yugabyte-db-config.tf
and add the following details to it. The Terraform module can be found in the terraform-azure-yugabyte GitHub repository.
module "yugabyte-db-cluster"
{
# The source module used for creating clusters on Azure.
source = "github.com/Yugabyte/terraform-azure-yugabyte"
# The name of the cluster to be created, change as per need.
cluster_name = "test-cluster"
# key pair.
ssh_private_key = "PATH_TO_SSH_PRIVATE_KEY_FILE"
ssh_public_key = "PATH_TO_SSH_PUBLIC_KEY_FILE"
ssh_user = "SSH_USER_NAME"
# The region name where the nodes should be spawned.
region_name = "YOUR VPC REGION"
# The name of resource group in which all Azure resource will be created.
resource_group = "test-yugabyte"
# Replication factor.
replication_factor = "3"
# The number of nodes in the cluster, this cannot be lower than the replication factor.
node_count = "3"
}
output "outputs"
{
value = module.yugabyte-db-cluster
}
Create a cluster
Initialize terraform first, if you have not already done so.
$ terraform init
Now, run the following to create the instances and bring up the cluster.
$ terraform apply
After the cluster is created, you can go to the URL http://<node ip or dns name>:7000
to view the UI. You can find the node's public IP address by running the following:
$ terraform state show module.yugabyte-db-cluster.azurerm_public_ip.YugaByte_Public_IP[0]
You can access the cluster UI by going to public IP address of any of the instances at port 7000
. The IP address can be viewed by replacing 0
in the preceding command with the desired index.
You can check the state of the nodes at any point by running the following command:
$ terraform show
Verify resources created
The following resources are created by this module:
-
module.azure-yugabyte.azurerm_virtual_machine.Yugabyte-Node
The Azure VM instances.
For a cluster named
test-cluster
, the instances are namedyugabyte-test-cluster-node-1
,yugabyte-test-cluster-node-2
, andyugabyte-test-cluster-node-3
. -
module.azure-yugabyte.azurerm_network_security_group.Yugabyte-SG
The security group that allows the various clients to access the YugabyteDB cluster.
For a cluster named
test-cluster
, this security group is namedyugabyte-test-cluster-SG
, with the ports 7000, 9000, 9042, 7100, 9200, and 6379 open to all other instances in the same security group. -
module.azure-yugabyte.null_resource.create_yugabyte_universe
A local script that configures the newly created instances to form a new YugabyteDB universe.
-
module.azure-yugabyte.azurerm_network_interface.Yugabyte-NIC
The Azure network interface for VM instance.
For a cluster named
test-cluster
, the network interface is namedyugabyte-test-cluster-NIC-1
,yugabyte-test-cluster-NIC-2
, andyugabyte-test-cluster-NIC-3
.
Destroy the cluster [optional]
To destroy what you just created, you can run the following command:
$ terraform destroy