nicholasjackson / terraform-aws-open-faas-nomad

Example Terraform configuration to create OpenFaas on Nomad for AWS
8 stars 3 forks source link
nomad openfaas terraform terraform-modules

Simple OpenFaas instance Running on Nomad in AWS

This module will create a Nomad cluster with Consul, VPC, and ALB for Nomad server and the OpenFaaS gateway

1. Set Environment variables for AWS

export AWS_ACCESS_KEY_ID=xxxxxxxxxxxxxxxxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export AWS_REGION=eu-west-1

2. Install Nomad and faas-cli

$ brew install faas-cli
$ brew install nomad
$ brew install terraform

3. Add the module to your Terraform config

The below configuration will create a single node Nomad cluster with 3 agents.

module "open-faas-nomad" {
  source = "nicholasjackson/open-faas-nomad/aws"

  min_agents = "3"
}

4. Create environment

$ terraform init  
$ terraform plan  
$ terraform apply

5. Set Nomad and OpenFaaS environment variables

$ export NOMAD_ADDR=http://$(terraform output nomad_alb):4646/  
$ export GATEWAY=http://$(terraform output faas_alb):8080/

6. Run OpenFaaS on the Nomad cluster

$ curl https://raw.githubusercontent.com/hashicorp/faas-nomad/master/faas.hcl -o faas.hcl
$ nomad run faas.hcl

7. Deploy a function to OpenFaaS

$ faas-cli deploy --gateway=$GATEWAY --image=functions/nodeinfo:latest --name=info --handler=node main.js

8. Test function

$ faas-cli invoke --name=info

The OpenFaaS UI is also available at http://$(terraform output faas_alb):8081

$ open http://$(terraform output faas_alb):8081

Please see example/terraform.tf for usage with all configurable options and openfaas.com for more details on OpenFaaS.