Skip to main content

Creating resources

Create the Access Keys

To start deploying with Terraform on NodeShift you need to get Access Keys (Please the doc how to do it).

Creating a provider

In Terraform, you specify "providers" for your cloud environment. A "provider" (such as NodeShift) hosts your infrastructure resources.

Create a file named with the following content:

# Define providers and set versions
terraform {
required_providers {
nodeshift = {
source = "deweb-services/nodeshift"

provider "nodeshift" {
access_key = "ACCESS_KEY"
secret_access_key = "SECRET_ACCESS_KEY"

You now need to initialize your workspace in order to download the provider plugins:

terraform init

Creating an instance

In Terraform, a "resource" is a component of your infrastructure. This can be an Compute VM, GPU VM, storage bucket or network delivered by the NodeShift provider.

For example purposes, we will create a simple GPU VM instance on latest ubuntu with RTX 3080 gpu. Add the following lines to a file named

# Creating the instance
resource "nodeshift_gpu" "example_terraform_instance" {
gpu_name = "RTX 3080"
image = "ubuntu:latest"
region = "Europe"
ssh_key = "ssh-rsa ..."
gpu_count = 1

To see what will be added/created/deleted in your infrastructure, you can execute:

terraform plan

You can enter the following command to create your first instance:

terraform apply

Output should be like this:

➜  terraform apply         

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create

Terraform will perform the following actions:

# nodeshift_gpu.example_terraform_instance will be created
+ resource "nodeshift_gpu" "example_terraform_instance" {
+ gpu_count = 1
+ gpu_name = "RTX 3080"
+ image = "ubuntu:latest"
+ region = "Europe"
+ ssh_key = "ssh-ed25519 AAAA..."
+ uuid = (known after apply)

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

nodeshift_gpu.example_terraform_instance: Creating...
nodeshift_gpu.example_terraform_instance: Creation complete after 3s

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Now, log in to the NodeShift Platform and go to the GPU VMs section. As you can see, your GPU instance is created.


Note that creating a second, identical instance with terraform apply will not work. Terraform applies change only if it recognises a difference in your configuration files or a new file.

Deleting an infrastructure

To remove every resource created through Terraform, you can enter the following command:

terraform destroy