serverless-terraform-variables

0.2.1 • Public • Published

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.

Package Sidebar

Install

npm i serverless-terraform-variables

Weekly Downloads

5

Version

0.2.1

License

MIT

Unpacked Size

8.05 kB

Total Files

4

Last publish

Collaborators

  • sbchapin