Science and technology

Use Terraform to handle TrueNAS

Sometimes combining completely different open supply tasks can have advantages. The synergy of utilizing Terraform with TrueNAS is an ideal instance.

TrueNAS is an OpenBSD-based working system that gives network-attached storage (NAS) and community companies. One of its major strengths is leveraging the ZFS file system, which is thought for enterprise-level reliability and fault tolerance. Terraform is a provisioning and deployment software embodying the idea of infrastructure as code.

TrueNAS

TrueNAS has a really good net consumer interface (UI) for its administration and an utility programming interface (API). Terraform may be built-in with the API to supply configuration administration of your NAS, as I’ll exhibit beneath.

To start, I used Virtual Machine Manager to configure a digital machine after which put in the most recent model, TrueNAS 13.0. The solely crucial enter was to enter the foundation password. Once it reboots, the primary menu seems. You will even see the HTTP administration deal with. You can entry this deal with out of your native net browser.

(Alan Formy-Duval, CC BY-SA 4.0)

Terraform

Terraform must be put in the place it could possibly entry the TrueNAS administration URL. I’m benefiting from tfenv, a software for managing Terraform variations.

$ tfenv list-remote
$ tfenv set up 1.2.0
$ tfenv use 1.2.0
$ terraform -version
Terraform v1.2.0
on linux_amd64

Next, create a working listing, corresponding to ~/code/terraform/truenas, to comprise the configuration information related along with your TrueNAS occasion.

$ mkdir ~/code/terraform/truenas
$ cd ~/code/terraform/truenas

Create the preliminary terraform configuration file and add the mandatory directives to outline the TrueNAS supplier.

$ vi major.tf

The supplier will seem like this, the place the deal with and API key on your TrueNAS occasion will have to be appropriately specified.

$ cat major.tf

terraform {
  required_providers {
    truenas = {
      supply = "dariusbakunas/truenas"
      model = "0.9.0"
    }
  }
}

supplier "truenas" {
  api_key = "1-61pQpp3WyfYwg4dHToTHcOt7QQzVrMtZnkJAe9mmA0Z2w5MJsDB7Bng5ofZ3bbyn"
  base_url = "http://192.168.122.139/api/v2.0"
}

The TrueNAS API secret is created within the Web UI. Log in and click on the small gear within the higher right-hand nook.

(Alan Formy-Duval, CC BY-SA 4.0)

This UI part allows you to create the API key. Once generated, copy it to the major.tf file.

Initialize

In your TrueNAS Terraform listing, you might have the major.tf file. The first step is to initialize utilizing the command terraform init, which ought to generate the next consequence:

Initializing the backend...

Initializing supplier plugins...
- Finding dariusbakunas/truenas variations matching "0.9.0"...
- Installing dariusbakunas/truenas v0.9.0...
- Installed dariusbakunas/truenas v0.9.0 (self-signed, key ID E44AF1CA58555E96)

Partner and neighborhood suppliers are signed by their builders.
If you'd prefer to know extra about supplier signing, you may examine it right here:
https://www.terraform.io/docs/cli/plugins/signing.html

Terraform has created a lock file .terraform.lock.hcl to document the supplier
picks it made above. Include this file in your model management repository
in order that Terraform can assure to make the identical picks by default when
you run "terraform init" sooner or later.

Terraform has been efficiently initialized!

You might now start working with Terraform. Try working "terraform plan" to see
any adjustments which can be required on your infrastructure. All Terraform instructions
ought to now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working listing. If you overlook, different instructions will detect it and remind you to take action if crucial.

A profitable initialization means you are prepared to begin including sources. Any TrueNAS merchandise, corresponding to a storage pool, community file system (NFS) share, or cron job, is a useful resource.

Add a ZFS dataset

The following instance useful resource directive defines a ZFS dataset. For my instance, I’ll add it to the major.tf file.

useful resource "truenas_dataset" "pictures" {
  pool = "storage-pool"
  identify = "pictures"
  feedback = "Terraform created dataset for Pictures"
 }

Run the command terraform validate to examine the configuration.

Success! The configuration is legitimate.

Running terraform plan will describe the actions that Terraform will carry out. Now, add the brand new dataset with terraform apply.

Terraform used the chosen suppliers to generate the next execution plan. Resource actions are indicated with the next symbols:
  + create

Terraform will carry out the next actions:

  # truenas_dataset.footage will probably be created
  + useful resource "truenas_dataset" "pictures" {
      + acl_mode             = (recognized after apply)
      + acl_type             = (recognized after apply)
      + atime                = (recognized after apply)
      + case_sensitivity     = (recognized after apply)
      + feedback             = "Terraform created dataset for Pictures"
      + compression          = (recognized after apply)
      + copies               = (recognized after apply)
      + dataset_id           = (recognized after apply)
      + deduplication        = (recognized after apply)
      + encrypted            = (recognized after apply)
      + encryption_algorithm = (recognized after apply)
      + encryption_key       = (delicate worth)
      + exec                 = (recognized after apply)
      + generate_key         = (recognized after apply)
      + id                   = (recognized after apply)
      + managed_by           = (recognized after apply)
      + mount_point          = (recognized after apply)
      + identify                 = "pictures"
      + pbkdf2iters          = (recognized after apply)
      + pool                 = "storage-pool"
      + quota_bytes          = (recognized after apply)
      + quota_critical       = (recognized after apply)
      + quota_warning        = (recognized after apply)
      + readonly             = (recognized after apply)
      + record_size          = (recognized after apply)
      + ref_quota_bytes      = (recognized after apply)
      + ref_quota_critical   = (recognized after apply)
      + ref_quota_warning    = (recognized after apply)
      + share_type           = (recognized after apply)
      + snap_dir             = (recognized after apply)
      + sync                 = (recognized after apply)
    }

Plan: 1 so as to add, 0 to alter, 0 to destroy.

Do you wish to carry out these actions?
  Terraform will carry out the actions described above.
  Only 'sure' will probably be accepted to approve.

  Enter a worth:

Type sure to verify and hit Enter.

truenas_dataset.footage: Creating...
truenas_dataset.footage: Creation full after 0s [id=storage-pool/pictures]

Apply full! Resources: 1 added, 0 modified, 0 destroyed.

That’s it. You can examine for this new dataset within the TrueNAS Web UI.

(Alan Formy-Duval, CC BY-SA 4.0)

Do extra with TrueNAS and Terraform

The TrueNAS supplier for Terraform permits you to handle many extra facets of your TrueNAS machine. For occasion, you might share this new dataset as an NFS or server message block (SMB) share. You may create further datasets, cron jobs, and zvols.

Click to comment

Leave a Reply

Your email address will not be published.

Most Popular

breakingExpress.com features the latest multimedia technologies, from live video streaming to audio packages to searchable archives of news features and background information. The site is updated continuously throughout the day.

Copyright © 2017 Breaking Express, Green Media Corporation

To Top