Using Terraform: ObjectiveFS on AWS EC2

This article provides an example of using Terraform to set up your ObjectiveFS filesystem on an AWS EC2 instance. This example shows the setup for an i3.xlarge instance type and uses the NVMe SSD as a disk cache.

Note

  1. Before running Terraform, you need to set the following environment varaibles:
    • TF_VAR_OBJECTIVEFS_LICENSE to your ObjectiveFS license key
    • TF_VAR_OBJECTIVEFS_PASSPHRASE to your filesystem’s passphrase
  2. Terraform will store the cloudinit user_data (including your Objectivefs license and passphrase) in terraform.tfstate. Please store this file safely to protect your credentials.

Steps

1. Add the following code in main.tf.
Note: Fill in the <DATA> field with the appropriate information.

variable "OBJECTIVEFS_PASSPHRASE" {}
variable "OBJECTIVEFS_LICENSE" {}

data "template_file" "cloudinit" {
  template         = "${file("${path.module}/cloudinit.tpl")}"
  vars {
    ofs_passphrase = "${var.OBJECTIVEFS_PASSPHRASE}"
    ofs_license    = "${var.OBJECTIVEFS_LICENSE}"
    ofs_filesystem = "<FILESYSTEM-NAME>"
  }
}

data "template_cloudinit_config" "cloudinit" {
  base64_encode    = true
  part {
    content        = "${data.template_file.cloudinit.rendered}"
  }
}

resource "aws_instance" "instance" {
  ami                    = "<AMI-ID>"
  instance_type          = "i3.xlarge"
  subnet_id              = "<SUBNET-ID>"
  vpc_security_group_ids = ["<SECURITY-GROUPS"]
  iam_instance_profile   = "<IAM-ROLE>"
  user_data         = "${data.template_cloudinit_config.cloudinit.rendered}"
}

2. Create a file called cloudinit.tpl with the following content.

#cloud-config
write_files:
  - path: "/etc/objectivefs.env/AWS_METADATA_HOST"
    content: "169.254.169.254"
    permissions: "0400"
    owner: "root"
  - path: "/etc/objectivefs.env/DISKCACHE_SIZE"
    content: "1P"
    permissions: "0400"
    owner: "root"
  - path: "/etc/objectivefs.env/DISKCACHE_PATH"
    content: "/media/ephemeral0/objectivefs"
    permissions: "0400"
    owner: "root"
  - path: "/etc/objectivefs.env/OBJECTIVEFS_LICENSE"
    content: "${ofs_license}"
    permissions: "0400"
    owner: "root"
  - path: "/etc/objectivefs.env/OBJECTIVEFS_PASSPHRASE"
    content: "${ofs_passphrase}"
    permissions: "0400"
    owner: "root"

runcmd:
  - mkdir /ofs
  - mkfs.ext4 -E nodiscard /dev/nvme0n1
  - echo /dev/nvme0n1 /media auto defaults,nofail,discard 0 2 >> /etc/fstab
  - echo ${ofs_filesystem} /ofs objectivefs _netdev,auto 0 0 >> /etc/fstab
  - mount -a

3. Running terraform apply will now create an i3.xlarge EC2 instance with ObjectiveFS and NVMe disk cache mounted.

# terraform plan
...
[ check that everything looks ok ]
# terraform apply

References

by ObjectiveFS staff, September 25, 2017
ObjectiveFS is a shared file system for Linux and OS X that automatically scales and gives you scalable cloud storage. If you have questions or article idea suggestions, please email us at support@objectivefs.com