{"id":14156599,"url":"https://github.com/sbchapin/serverless-terraform-variables","last_synced_at":"2025-08-06T03:30:49.236Z","repository":{"id":81503216,"uuid":"152843532","full_name":"sbchapin/serverless-terraform-variables","owner":"sbchapin","description":"Retrieve terraform output variables for interpolation in serverless configuration","archived":false,"fork":false,"pushed_at":"2019-05-21T08:56:43.000Z","size":178,"stargazers_count":9,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-16T02:19:27.028Z","etag":null,"topics":["infrastructure","interpolation","serverless","serverless-terraform-variables","terraform"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sbchapin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-13T06:43:02.000Z","updated_at":"2024-06-15T00:01:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"50aa51fb-eec3-41d1-925f-f05291398ec5","html_url":"https://github.com/sbchapin/serverless-terraform-variables","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"ed26ed400dec49c6e3e6bf0fae1e10999978ef53"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbchapin%2Fserverless-terraform-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbchapin%2Fserverless-terraform-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbchapin%2Fserverless-terraform-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbchapin%2Fserverless-terraform-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbchapin","download_url":"https://codeload.github.com/sbchapin/serverless-terraform-variables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228835539,"owners_count":17979162,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["infrastructure","interpolation","serverless","serverless-terraform-variables","terraform"],"created_at":"2024-08-17T08:06:55.978Z","updated_at":"2024-12-09T04:30:40.939Z","avatar_url":"https://github.com/sbchapin.png","language":"JavaScript","funding_links":[],"categories":["terraform"],"sub_categories":[],"readme":"# serverless-terraform-variables\n[![Build Status](https://travis-ci.org/sbchapin/serverless-terraform-variables.svg?branch=master)](https://travis-ci.org/sbchapin/serverless-terraform-variables)\n[![dependencies Status](https://david-dm.org/sbchapin/serverless-terraform-variables/status.svg)](https://david-dm.org/sbchapin/serverless-terraform-variables)\n[![devDependencies Status](https://david-dm.org/sbchapin/serverless-terraform-variables/dev-status.svg)](https://david-dm.org/sbchapin/serverless-terraform-variables?type=dev)\n[![npm](https://img.shields.io/npm/v/serverless-terraform-variables.svg)](https://www.npmjs.com/package/serverless-terraform-variables)\n\n\nInterpolation of [terraform output variables](https://www.terraform.io/intro/getting-started/outputs.html) into a [serverless configuration variable source](https://serverless.com/framework/docs/providers/aws/guide/variables#current-variable-sources).\n\nUse terraform to manage the breadth of your networking, data, and auth layers, while using serverless to keep the quickly moving pieces moving quickly.\n\n\nSimply stated, it allows this:\n\n`main.tf`:\n```hcl\nresource \"aws_sqs_queue\" \"terraform_queue\" {\n  name = \"terraform-example-queue\"\n}\noutput \"sqs_id\" { // \u003c- !!!\n  value = \"${aws_sqs_queue.terraform_queue.id}\"\n}\n```\n\n`serverless.yml`:\n```yml\nplugins:\n  - serverless-terraform-variables\nfunctions:\n  compute:\n    handler: handler.compute\n    events:\n      - sqs: ${terraform:sqs_id} # \u003c- !!!\n```\n\n## Usage\n\n#### To **install** this to your project...\n```sh\nnpm install --save serverless-terraform-variables\n```\n...then add to `serverless.yml`:\n```yaml\n# ...\nplugins:\n  - serverless-terraform-variables\n# ...\n```\n\n#### To **use** it in your project...\nCreate some terraform:\n```hcl\n// Optionally configure your state storage:\nterraform {\n  backend \"consul\" {}\n}\n// Create resources\nresource \"aws_s3_bucket\" \"serverless_deployment\" {\n  bucket = \"yournamespace.serverless\"\n}\n// Expose them to serverless via output variables\noutput \"serverless_bucket\" {\n  value = \"${aws_s3_bucket.serverless_deployment.id}\"\n}\n```\n...initialize and update state:\n```sh\nterraform init\nterraform apply\n# ...or...\nterraform state pull\n```\n...then use the outputs in your `serverless.yml`:\n```yaml\n# ...\nprovider:\n  name: aws\n  runtime: nodejs8.10\n  deploymentBucket: ${terraform:serverless_bucket}\n# ...\n```\n\n#### To **develop** the plugin...\n**Fork** it, **git** it, **commit** it, **PR** it:\n```sh\n# Setup:\ngit clone git@github.com:sbchapin/serverless-terraform-variables.git\ncd ./serverless-terraform-variables/plugin/\nnpm install\n\n# Test:\nnpm test\n```\n\n## Example\n\nThe quickest way to get the idea is to see the example.  Contained in `./example/` is a stand-alone Ping/Pong HTTP GET lambda function.  It contains the terraform necessary to create the network infrastructure and code deployment bucket, so make sure the terraform state is available before invoking serverless.  Or don't, and see the meaningful error messages.\n\n```sh\n# Setup:\ngit clone git@github.com:sbchapin/serverless-terraform-variables.git\ncd ./serverless-terraform-variables/example/\nnpm install\n\n# Deploy:\nterraform init\nterraform apply # !!!WARNING!!! will create a VPC, subnet, and gateway using _your_ AWS Account.\nserverless deploy # !!!WARNING!!! will create lambdas, cloudwatch log groups, and API gateway endpoints using _your_ AWS Account.\n\n# Experiment:\nserverless invoke -f ping\ncurl -XGET https://deployment_specific_ApiGatewayRestApi_token_goes_here.execute-api.us-west-2.amazonaws.com/dev/ping\n\n# Cleanup:\nserverless remove\nterraform destroy\n# note that you may need to clear the objects serverless has deployed for you:\n# aws s3 rm --profile ${aws_profile} --recursive s3://${namespace}.serverless/serverless/serverless-terraform-variables-simple-http-endpoint/dev/\n```\n\n## Gotchas\n- [ ] **Serverless cli must be installed** (`npm install -g serverless`).\n- [ ] **Terraform cli must be installed** ([`brew install terraform`, probably](https://learn.hashicorp.com/terraform/getting-started/install.html)).\n- [ ] **Terraform must be initialized in the directory Serverless is executed in.** (`terraform init` should have been executed before any `serverless` command)\n- [ ] **Terraform must be able to show outputs referenced by Serverless.** (`terraform show` should execute successfully)\n\n# Currently a *high-functioning proof-of-concept*.\n\nThis code represents a rough implementation of a good idea.  Not suggested for production usage, existent only to show the potential of what _could_ be.\n\nIf it wasn't immediately obvious, **this plugin shells out to use terraform directly to parse state**.  It does not do any destructive or constructive terraform operations - that's up to you.  You can find the details of what terraform commands are used under `./plugin/src/terraform-client.js`.\n\nIf your operators can provide a consistent operations environment where `terraform` and `serverless` are both versioned and consistent...  There's a future for this project with you involved.\n\n# Why?\n\n**Terraform** and **Serverless** *can* serve the same purpose, but they do so with varying levels of success.\n\n##### **Terraform** _is great at large multi-team shared infrastructure._  \n\nTerraform's functionality of shared \u0026 saved state along with its module referencing powers allow it to be used for the majority of a company's provisioned dev ops, and its declarative and configuration-based approach allow it to be easily understood from a high level.  However, terraform is not incredibly easy to pivot and iterate with.\n\n##### **Serverless** _is great at deploying functionality consistently and quickly._\n\nServerless' highly targeted platform-based approach allows it to be very efficient for any serverless platform, lessening the deploy time and upping the iteration.  In addition, serverless is not restricted to the bounds of configuration - with a rich plugin ecosystem, you can code and do a lot of things with high efficiency.  However, serverless is not terribly easy roll a full infrastructure with (especially with server-ful components).\n\n##### **Serverless-terraform-variables** _allows you to migrate any piece of terraform state forward into serverless._\n\n\nServerless-terraform-variables is great at integrating any terraform solution with a serverless solution - you get the both of best worlds while still remaining platform agnostic.  You can take advantage of terraform to inject existing ops-managed infrastructure into a dev-owned environment of lambdas, managing just the deployment of your code with serverless while leaning on terraform to fetch and update any changes of infrastructure state that may affect your deployment.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbchapin%2Fserverless-terraform-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbchapin%2Fserverless-terraform-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbchapin%2Fserverless-terraform-variables/lists"}