JSPM

serverless-terraform-variables

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q24943F
  • License MIT

Serverless plugin to retrieve terraform output variables for interpolation in serverless configuration.

Package Exports

  • serverless-terraform-variables

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (serverless-terraform-variables) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

serverless-terraform-variables

Build Status dependencies Status devDependencies Status npm

Interpolation of terraform output variables into a serverless configuration variable source.

Use terraform to manage the breadth of your networking, data, and auth layers, while using serverless to keep the quickly moving pieces moving quickly.

Simply stated, it allows this:

main.tf:

resource "aws_sqs_queue" "terraform_queue" {
  name = "terraform-example-queue"
}
output "sqs_id" { // <- !!!
  value = "${aws_sqs_queue.terraform_queue.id}"
}

serverless.yml:

plugins:
  - serverless-terraform-variables
functions:
  compute:
    handler: handler.compute
    events:
      - sqs: ${terraform:sqs_id} # <- !!!

Usage

To install this to your project...

npm install --save serverless-terraform-variables

...then add to serverless.yml:

# ...
plugins:
  - serverless-terraform-variables
# ...

To use it in your project...

Create some terraform:

// Optionally configure your state storage:
terraform {
  backend "consul" {}
}
// Create resources
resource "aws_s3_bucket" "serverless_deployment" {
  bucket = "yournamespace.serverless"
}
// Expose them to serverless via output variables
output "serverless_bucket" {
  value = "${aws_s3_bucket.serverless_deployment.id}"
}

...initialize and update state:

terraform init
terraform apply
# ...or...
terraform state pull

...then use the outputs in your serverless.yml:

# ...
provider:
  name: aws
  runtime: nodejs8.10
  deploymentBucket: ${terraform:serverless_bucket}
# ...

See the github project for a more comprehensive README and an example project.