Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make workspace optional #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
serverless-terraform-outputs
============================

Provides variable substitution resolution from Terraform outputs with workspace support:
Provides variable substitution resolution from Terraform outputs:

```
${terraform:sqs_queue_stuff.value.arn}
```
# Usage
```yaml
provider:
environment:
SQS_QUEUE: ${terraform:sqs_queue_stuff.value.url}
```

## Workspace support
```
${terraform:app-stage:sqs_queue_stuff.value.arn}
```
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ class ServerlessTerraformOpts {
}

async _getValue(variable: string) {
const [workspace, path] = variable.split(':')
const items = variable.split(':')
const path = items.length > 1 ? items[1] : items[0]
const workspace = items.length > 1 ? items[0] : undefined

const outputs = await TFOutputs.Load(workspace, this.serverless)
const outputs = await TFOutputs.Load(this.serverless, workspace)

const value = outputs.getValueAtPath(path)

Expand Down
6 changes: 3 additions & 3 deletions src/terraform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {exec} from './async'


export async function output(workspace: string, serverless: any): Promise<any> {
export async function output(serverless: any, workspace?: string): Promise<any> {
const pluginOptions = ((serverless.service || {}).custom || {}).terraformOutputs || {}

const options = {
Expand All @@ -25,9 +25,9 @@ export class TFOutputs {
* Use Terraform command to fetch outputs and construct TFOutputs instance.
* @param workspace Name of Terraform workspace to use
*/
static async Load(workspace: string, serverless: any) {
static async Load(serverless: any, workspace?: string) {
if(!this.resp)
this.resp = output(workspace, serverless)
this.resp = output(serverless, workspace)
const outputs = await this.resp
return new TFOutputs(outputs, serverless)
}
Expand Down