commit
7abe835aee
8 changed files with 114 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
*~ |
||||
*.bak |
||||
*.tfstate* |
||||
|
||||
**/.envrc |
||||
**/.terraform* |
@ -0,0 +1,15 @@
|
||||
# Example shell provider prototype |
||||
|
||||
An example of using the [shell_resource]https://github.com/scottwinkler/terraform-provider-shell/blob/master/examples/test/scripts/read.sh) provider |
||||
to quickly prototype up a new Terraform provider and resource with full support |
||||
for: |
||||
|
||||
- Create |
||||
- Delete |
||||
- Update (in-place) |
||||
- Read |
||||
|
||||
The missing piece of documentation from the [shell provider](https://github.com/scottwinkler/terraform-provider-shell/blob/master/examples/test/scripts/read.sh) is the fact that the "previous output" is fed as input to the shell scripts |
||||
that implement Read, Update and Delete. |
||||
|
||||
See: https://github.com/scottwinkler/terraform-provider-shell/issues/96 |
@ -0,0 +1,17 @@
|
||||
resource "shell_script" "helloworld" { |
||||
lifecycle_commands { |
||||
create = file("${path.module}/shell_resources/helloworld/create.sh") |
||||
read = file("${path.module}/shell_resources/helloworld/read.sh") |
||||
update = file("${path.module}/shell_resources/helloworld/update.sh") |
||||
delete = file("${path.module}/shell_resources/helloworld/delete.sh") |
||||
} |
||||
|
||||
environment = { |
||||
NAME = "World" |
||||
} |
||||
} |
||||
|
||||
output "hello" { |
||||
sensitive = true |
||||
value = shell_script.helloworld.output |
||||
} |
@ -0,0 +1,8 @@
|
||||
terraform { |
||||
required_providers { |
||||
shell = { |
||||
source = "scottwinkler/shell" |
||||
version = "1.7.7" |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,17 @@
|
||||
#!/bin/sh |
||||
|
||||
set -e |
||||
|
||||
echo "Creating $NAME ..." |
||||
|
||||
id="$(echo "$NAME" | sha256sum | cut -f 1 -d ' ')" |
||||
|
||||
cat > "$id" <<EOF |
||||
Hello ${NAME}! |
||||
EOF |
||||
|
||||
cat <<EOF |
||||
{ |
||||
"id": "$id" |
||||
} |
||||
EOF |
@ -0,0 +1,11 @@
|
||||
#!/bin/sh |
||||
|
||||
set -e |
||||
|
||||
# Read previous state into a temporary file |
||||
IN="$(cat)" |
||||
|
||||
id="$(echo "$IN" | jq -r '.id')" |
||||
|
||||
echo "Deleting $id ..." >&2 |
||||
rm -f "$id" |
@ -0,0 +1,13 @@
|
||||
#!/bin/sh |
||||
|
||||
set -e |
||||
|
||||
echo "Reading $NAME ..." >&2 |
||||
|
||||
id="$(echo "$NAME" | sha256sum | cut -f 1 -d ' ')" |
||||
|
||||
cat <<EOF |
||||
{ |
||||
"id": "$id" |
||||
} |
||||
EOF |
@ -0,0 +1,27 @@
|
||||
#!/bin/sh |
||||
|
||||
set -e |
||||
|
||||
echo "Updating $NAME ..." >&2 |
||||
|
||||
IN="$(cat)" |
||||
oldId="$(echo "$IN" | jq -r '.id')" |
||||
newId="$(echo "$NAME" | sha256sum | cut -f 1 -d ' ')" |
||||
|
||||
if [ "$oldId" = "$newId" ]; then |
||||
echo "Nothing to do..." >&2 |
||||
exit 0 |
||||
fi |
||||
|
||||
echo "Removing $oldId ..." >&2 |
||||
rm -rf "$oldId" |
||||
|
||||
cat > "$newId" <<EOF |
||||
Hello ${NAME}! |
||||
EOF |
||||
|
||||
cat <<EOF |
||||
{ |
||||
"id": "$newId" |
||||
} |
||||
EOF |
Loading…
Reference in new issue