Terraform for Numspot - Quickstart
Terraform is a tool that automates the creation and versioning of a cloud infrastructure.
The provider developed by Numspot acts as an interface between the definition of your infrastructure and our service in charge of creating these resources.
For more information about the available resources and how to use them, you can refer to our provider documentation on the HashiCorp registry.
Before you begin
To carry out the actions presented below, you must have:
- A Numspot account
- Terraform installed
Create and deploy Numspot resources using Terraform
For the purposes of this example, we will create a VM (Virtual Machine).
Creating the Terraform configuration file
-
Create a new file named
main.tf. -
Open the file in a code editor and paste the following block to define Numspot as the provider for this deployment: you can find the latest available version here
terraform {
required_providers {
numspot = {
source = "numspot/numspot"
version = "<PROVIDER_VERSION>"
}
}
}
- Add the following block and replace
<CLIENT_ID>,<CLIENT_SECRET>and<SPACE_ID>with the details of the project in which you want to create resources:
provider "numspot" {
numspot_host = "<Choose one of the two regions below>"
numspot_host_os = "<Choose one of the two regions below>"
client_id = "<CLIENT_ID>"
client_secret = "<CLIENT_SECRET>"
space_id = "<SPACE_ID>"
}
Standard region:
- API (Application Programming Interface): https://api.eu-west-2.numspot.com
- object storage: https://objectstorage.eu-west-2.numspot.com
Available AZ (Availability Zone):
- eu-west-2a
- eu-west-2b
- Add the following blocks to create a VPC (Virtual Private Cloud), a subnet and a VM:
resource "numspot_vpc" "net" {
ip_range = "10.0.0.0/16"
}
resource "numspot_subnet" "subnet" {
vpc_id = numspot_vpc.net.id
ip_range = "10.0.0.0/24"
availability_zone_name = "<Choose an AZ from the region>"
}
resource "numspot_vm" "vm" {
image_id = "<image ID>"
subnet_id = numspot_subnet.subnet.id
type = "<VM type>"
}
- Save your changes.
Your configuration is now ready to be deployed on the Numspot infrastructure.
Deploying your configuration using Terraform
- Open a terminal, go to the folder you have just created and run the following command to initialize Terraform in this folder:
terraform init
- Run the following command to display the actions that Terraform will perform:
terraform plan
- Check the deployment plan to make sure it matches the desired configuration.
- Run the following command to deploy your resources:
terraform apply
If you update the version of the provider you are using, you will need to run terraform init -upgrade
Once the deployment is complete, log in to the Numspot Console to view the resources you have just created.
Deleting Numspot resources using Terraform
-
Open a terminal and go to the folder containing the Terraform configuration you want to delete.
-
Run the command below to delete the resources listed in the Terraform configuration file:
terraform destroy
Only the resources created with Terraform will be deleted. This action is irreversible.
A Destroy complete! Resources: X destroyed. message appears: your Numspot resources are now deleted.