Source: https://blog.digitalocean.com/introducing-the-digitalocean-terraform-provider/
Source: https://blog.digitalocean.com/introducing-the-digitalocean-terraform-provider/

Prerequisites

  • DigitalOcean Account
  • DigitalOcean Personal Access Token (PAT)

Install Terraform

  • Update & Upgrade Package
    sudo apt update && sudo apt upgrade -y
  • Install Unzip
    sudo apt install unzip
  • Download Terraform
    wget https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip
    unzip terraform_0.11.11_linux_amd64.zip
    mv terraform /usr/local/bin/
  • Verify
    terraform version

    Expected Output: Terraform v0.11.11
    Your version of Terraform is out of date! The latest version
    is 0.12.10. You can update by downloading from www.terraform.io/downloads.html

Create DigitalOcean Personal Access Token (PAT)

Untuk bisa mengakses cloud DO melalui platform lain diperlukan sebuah token. Untuk generate token pada DO bisa dilihat disini.

Provisioning Droplets using Terraform

  • Buat provider.tf
    vim provider.tf

    provider "digitalocean" {
        token = "${var.do_token}"
    }
  • Buat variable.tf
    vim variable.tf

    variable "do_token" {
        default="{DIGITAL_OCEAN_PAT}"
    }
  • Buat droplet.tf
    vim droplet.tf

    resource "digitalocean_droplet" "droplet" {
        image  = "ubuntu-18-04-x64"
        name   = "web-1"
        region = "sgp1"
        size   = "s-1vcpu-1gb"
    }
  • Apply configuration.
    terraform init
    terraform validate
    terraform providers
    terraform plan
    terraform apply
    terraform show

    Expected Output: digitalocean_droplet.droplet:
    id = 162936435
    backups = false
    created_at = 2019-10-14T11:31:04Z
    disk = 25
    image = ubuntu-18-04-x64
    ipv4_address = 68.183.179.222
    ipv4_address_private =
    ipv6 = false
    ipv6_address =
    locked = false
    memory = 1024
    monitoring = false
    name = web-1
    price_hourly = 0.00744
    price_monthly = 5
    private_networking = false
    region = sgp1
    resize_disk = true
    size = s-1vcpu-1gb
    status = active
    tags.# = 0
    urn = do:droplet:162936435
    vcpus = 1
    volume_ids.# = 0

  • Check Droplet.
    Jika tidak ada error, maka droplet sudah provisioning.

Last modified: October 14, 2019

Author

Comments

Write a Reply or Comment

Your email address will not be published.