Multai & Terraform Getting Started – Create Multai Load Balancer

How to install Spotinst plugin for Terraform

In this post, we will demonstrate how to create a load balancer using Spotinst Terraform plugin.

1. Download the binary file terraform-provider-spotinst.

Please download the proper binary file for your operating system and architecture and put it somewhere on your filesystem:

2. Configure Terraform to be able to find the binary file:

If you are on a Unix-like system, create a file named .terraformrc in your home directory:

~/.terraformrc

If you are on a Windows system, create a file named terraform.rc in the %APPDATA% directory:

%APPDATA%/terraform.rc

3. Edit the file and add the following content:

providers {
  spotinst = "/path/to/terraform-provider-spotinst"
}

4. Create a new Multai Load Balancer.

 

Save the entire configuration to a file named main.tf:

resource "spotinst_multai_balancer" "foo" {
   name = "foo"

   connection_timeouts {
      idle     = 60
      draining = 60
   }

   tags {
      env = "prod"
      app = "web"
   }
}

resource "spotinst_multai_listener" "foo" {
   balancer_id = "${spotinst_multai_balancer.foo.id}"
   protocol    = "http"
   port        = 1338

   tags {
      env = "prod"
      app = "web"
   }
}

resource "spotinst_multai_routing_rule" "foo" {
   balancer_id = "${spotinst_multai_balancer.foo.id}"
   listener_id = "${spotinst_multai_listener.foo.id}"
   route       = "Path(`/`)"

   target_set_ids = [
      "${spotinst_multai_target_set.foo.id}",
   ]

   tags {
      env = "prod"
      app = "web"
   }
}

resource "spotinst_multai_target_set" "foo" {
   balancer_id   = "${spotinst_multai_balancer.foo.id}"
   deployment_id = "dp-12345"
   name          = "foo"
   protocol      = "http"
   port          = 1337
   weight        = 1

   health_check {
      protocol            = "http"
      path                = "/"
      interval            = 30
      timeout             = 10
      healthy_threshold   = 2
      unhealthy_threshold = 2
   }

   tags {
      env = "prod"
      app = "web"
   }
}

resource "spotinst_multai_target" "foo" {
   balancer_id   = "${spotinst_multai_balancer.foo.id}"
   target_set_id = "${spotinst_multai_target_set.foo.id}"
   host          = "172.0.0.10"
   port          = "1337"
   weight        = 1

   tags {
      env = "prod"
      app = "web"
   }
}

Once you have everything setup correctly, you can execute your Terraform file and apply the changes. It should trigger an API call to Multai, and create a Load Balancer.

If you have any question or a comment, please feel free to reach us at support@spotinst.com

Best,
The Spotinst Team.