Actually, this article is a little bit spoiler about openSUSE Asia Summit 2019 which is will be held on next week. On the second days, I will explain to the participant about how to spin up some instance in one of the most popular public cloud providers without touching more to the Web Console Wizard.

Especially, we will collaborate Linode with Terraform.

So What is Terraform?

Terraform is a tool to deploy, manage your infrastructure as a code. Just imagine, you are a public cloud consumer. And then, you want to create some instance. You will do some steps to create them, such as opening the web console, then specify the size of your instance. And Finally, your instance created. You got the remote access for your instance.

Terraform do the same things. But as a code. The benefits are, you will know what your infrastructure is made of with the code. You also can versioning the code with the versioning control like a git or etc.

Terraform using HCL (High Configuration Language) to manage and deploy the instance. It’s like a big JSON. And has a format

<BLOCK TYPE> "<BLOCK LABEL>" "<BLOCK LABEL>" {
  # Block body
  <IDENTIFIER> = <EXPRESSION> # Argument
}

So, in this article. I want to introduce you to the first steps how to create the instance using your code.

Before we are going more further:

  1. Make sure you already have a verified Linode Account
  2. You have a Teks Editor (such as Visual Studio Code, vim, or etc)
  3. You have already installed the terraform (it’s easy, you can find it on google)
  4. And, you have to create a Linode API with full access or instance only (find it on Linode dashboard (Go to https://cloud.linode.com | API Tokens | Create New API | and make sure you keep them)

First of all, create a folder to place your Terraform code and i will give the named linode-test.

mkdir linode-test/
cd linode-test/

Create a file with .tf file format, it is a default format for Terraform. And give the first code with determining the providers.

provider "linode" {
    token = "YOUR TOKEN HERE"
}

Above code is to define your Linode provider with your Token API.

Then, create some code for the resources.

resource "linode_instance" "terraformtest" {
    label = "linode-test"
    region = "ap-south"
    image = "linode/opensuse15.1"
    type = "g6-nanode-1"
    root_pass = "openSUS3"
}

How to determine and get the value? read the docs, and you will know. https://www.terraform.io/docs/providers/linode/index.html.

it means, you will create the instance with:

Name/label on your dashboard: linode-test
Region: Singapore (ap-south)
Image/operating-system: openSUSE 15.1
Type: Nanode
Root Password: openSUS3

So, your code is:

provider "linode" {
    token = "YOUR TOKEN HERE"
}

resource "linode_instance" "terraformtest" {
    label = "linode-test"
    region = "ap-south"
    image = "linode/opensuse15.1"
    type = "g6-nanode-1"
    root_pass = "openSUS3"
}

Save the file, and run terraform init for the first time to initialize your provider plugins.

Then, run below command to create the instance:

terraform plan
terraform apply

terraform plan is a command to show your detail of instance without creating them in the Linode. This command will make sure that your instance configuration is good.

terraform init is a command to execute and create the instance using the terraform. Just wait for a second, And your instance will be created.

That’s it for the article. In the next article we will use terraform with the variable on the code. Thank you 🙂


Dhenandi Putra

Hi, I'm dhenandi, Mac and openSUSE user. An office boy, typist, and man behind this blog. I also write on another blog https://dhenandi.web.id/ in Bahasa Indonesia.

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.