Giter Club home page Giter Club logo

terraform-shell-resource's Introduction

terraform-shell-resource

Build Status

A workaround for hashicorp/terraform#610 <-- please ๐Ÿ‘, meanwhile:

This module runs a command as a null_resource and makes the stdout, stderr and exit status available as outputs (stored in triggers map). See an external data source version with more features at https://github.com/matti/terraform-shell-outputs (that runs on every apply, this one only runs once when the resource is created and if command is changed).

Usage

module "files" {
  source  = "matti/resource/shell"
  command = "ls -l"
}

output "my_files" {
  value = module.files.stdout
}
...
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.

Outputs:

my_files = total 16
-rw-r--r--  1 mpa  staff   112 Feb  9 09:06 main.tf
-rw-r--r--  1 mpa  staff  1007 Feb  9 09:07 terraform.tfstate

Full usage

module "first" {
  source = "matti/resource/shell"

  command = ">/tmp/first echo I was here first"
}

module "greeting" {
  source = "matti/resource/shell"

  # workaround for missing depends_on in modules
  depends = [
    module.first.id
  ]

  environment = {
    GREETING = "hello"
  }

  command              = "echo $GREETING world from $(pwd) where /tmp/first has content: $(cat /tmp/first)"
  command_when_destroy = "echo $GREETING and good bye from $(pwd)"

  # runs on every apply
  trigger = timestamp()

  working_dir = "/tmp"
}

output "greeting" {
  value = module.greeting.stdout
}
Apply complete! Resources: 6 added, 0 changed, 0 destroyed.

Outputs:

greeting = hello world from /private/tmp where /tmp/first has content: I was here first

Additional examples

See tests and examples

Related issues:

terraform-shell-resource's People

Contributors

matti avatar userhas404d avatar nitrocode avatar ferdinand-beyer avatar gableroux avatar sodre avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.