• This repository has been archived on 06/Mar/2022
  • Stars
    star
    230
  • Rank 174,053 (Top 4 %)
  • Language HCL
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Run (exec) a command in shell and capture the output (stdout, stderr) and status code (exit status)

no longer maintained

and

-

-

-

-

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"

  # mark outputs (stdout & stderr) as sensitive
  # sensitive_outputs = true
}

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

Windows support

This module also supports being run on Windows machines (assuming they support Powershell). If the command_windows and/or command_when_destroy_windows inputs are specified, they will be used instead of command/command_when_destroy when Terraform is run on Windows. If they are not specified, the command/command_when_destroy commands will be run regardless of the operating system.

Additional examples

See tests and examples

Related issues:

More Repositories

1

terraform-shell-outputs

HCL
33
star
2

http-doom

JavaScript
29
star
3

k3sup-multipass

Shell
18
star
4

google-cloud-run-shell

Shell
15
star
5

gcr-pruner

Shell
13
star
6

awesome-kontena

A curated list of awesome Kontena resources.
11
star
7

PottisJS

JavaScript Library for SVG Interaction
JavaScript
10
star
8

superbara

Capybara CLI on Steroids
Ruby
10
star
9

kommando

Ruby
9
star
10

k8s-prestop-sidecar

Go
8
star
11

activeredis

ActiveModel based object persistance library for Redis
Ruby
6
star
12

async-nats

Ruby
5
star
13

reittihaku

Ruby
5
star
14

kontena-stacks

My stacks
Shell
5
star
15

docker-freedos

Shell
5
star
16

terraform-google-kubernetes-node-pool

HCL
5
star
17

terraform-module-depends_on

HCL
5
star
18

buildtagpush

Shell
5
star
19

gifufy

Converts movies to GIFs with ffmpeg and gifsicle
CoffeeScript
4
star
20

terraform-google-compute-instance

HCL
4
star
21

ws-doom

JavaScript
4
star
22

terraform-external-urlparse

HCL
4
star
23

gbuild

Google Cloud Build that does not hurt
Ruby
3
star
24

ruby2exe

Ruby
3
star
25

contena

Shell
3
star
26

LatteG

Experimental LatteX implementation
JavaScript
2
star
27

eksler

Shell
2
star
28

claudiaweb

Claudia Research Web
JavaScript
2
star
29

gem2exe

Ruby
2
star
30

terraform-example-provisioner-if-file-exists-or-has-changed

HCL
2
star
31

vagrant-lambda

Shell
2
star
32

terraform-json-yaml

HCL
2
star
33

web2videolol

JavaScript
2
star
34

svg-in-ie-mayhem

JavaScript
2
star
35

PcapReduce

ruby script to analyze and filter pcap files
Ruby
2
star
36

tktltiki

2010 edition
Shell
2
star
37

superscript

Ruby
2
star
38

dell-xps-15-9560-macos

2
star
39

k8s-node-watchdog

Shell
2
star
40

PenJS

PechaKucha Night JavaScript Library
JavaScript
2
star
41

harderdns

Go
2
star
42

gommando

Go
2
star
43

doc

Shell
1
star
44

terraform-kupo-google-workbench

HCL
1
star
45

r3blog

blog.mpa.fi created with Rails 3 and hosted in Heroku
JavaScript
1
star
46

aktivator

1
star
47

docker-ffmpeg

Dockerfile
1
star
48

terraform-google-gce-image-upload

HCL
1
star
49

lnx

Shell
1
star
50

sinatro

Ruby
1
star
51

swsdev

Ruby
1
star
52

depot_v

Ruby
1
star
53

eytest

Ruby
1
star
54

matti.github.com

My github page
1
star
55

webdriver

Ruby
1
star
56

cs.helsinki.fi-u-paksula

university homepage
1
star
57

kontena-rocks

Shell
1
star
58

java2100

Kevรครคn 2010 Ohjelmoinnin perusteiden ja jatkokurssin materiaalit
JavaScript
1
star
59

ecq

Ruby
1
star
60

dotfiles

Shell
1
star
61

kontena-watchdog

Ruby
1
star
62

terraform-json-map

HCL
1
star
63

vh-s10

Java
1
star
64

kontena-heroku

Shell
1
star
65

sukka

Go
1
star
66

pottisjs-website

HTML
1
star
67

wdbomber

Ruby
1
star
68

lattex.com

lattex.com
Ruby
1
star
69

repro-terraform-provider-google-issue-1046

HCL
1
star
70

FrontEndFinlandJSMeetUp2010

JavaScript
1
star
71

wad-exercises

Ruby
1
star
72

helmer

Shell
1
star
73

lolbear

dropbear with any password and any user auth
C
1
star
74

trackerapp

JavaScript
1
star
75

lattex

Cafe Latte + Tex
JavaScript
1
star
76

svg-viennajs-20100728

JavaScript
1
star
77

terraform-ssh-remove-known-hosts

HCL
1
star
78

terraform-kontena-gcp

HCL
1
star
79

tailscale_cleaner

Ruby
1
star
80

kindol

Shell
1
star
81

NXJExplorer

First test of Lego mindstorms NXJ, heavily based on Lejos tutorial
Java
1
star
82

refinery_paas_comparison

Ruby
1
star
83

kontena-faq

1
star
84

producer-consumer-mq

Ruby
1
star