Closed nhoughto closed 6 years ago
Soo i don't think you will merge this now, but more FYI because i've learnt a bunch while doing it.
Latest changes do resolve most of your points but likely create some new ones, new example TF has two forms and some new properties, looks like:
Supports destroy and create without update workflow via recreate_triggers
, a property that is set via some means (in this example its a data shell script, could be hash of file, env value etc) that drives TF to destroy and recreate.
data "shell_script" "test_state" {
lifecycle_commands {
read = <<EOF
kubectl convert --local -o jsonpath="{.spec.template.spec.containers[*].image}" -f pod.yml >&3
EOF
}
}
resource "shell_script" "test" {
recreate_triggers {
key = "${data.shell_script.test_state.extraout}"
}
lifecycle_commands {
create = <<EOF
kubectl apply -f pod.yml
EOF
delete = <<EOF
kubectl delete --ignore-not-found -f pod.yml
EOF
}
}
Support inplace updates workflow via update_trigger
, in this flow you set read() and update() as before, there is also an extra idempotent
property that means you can exclude update as create/update would be identical.
data "shell_script" "test_state" {
lifecycle_commands {
read = <<EOF
kubectl convert --local -o jsonpath="{.spec.template.spec.containers[*].image}" -f pod.yml >&3
EOF
}
}
resource "shell_script" "test" {
update_trigger = "${data.shell_script.test_state.extraout}"
lifecycle_commands {
#idempotent = true
read = <<EOF
kubectl get deploy -o jsonpath="{.items[*].spec.template.spec.containers[*].image}" >&3
EOF
create = <<EOF
kubectl apply -f pod.yml
EOF
update = <<EOF
kubectl apply -f pod.yml
EOF
delete = <<EOF
kubectl delete --ignore-not-found -f pod.yml
EOF
}
}
Also opted to use file rather than a fd pipe as pipe isn't platform agnostic, will work on linux but not windows (probably, untested). I did test a unix pipe and it didn't work immediately so I scrapped it. Agree though it would be cleaner.
I have started work on a new branch based on some inspiration i gained looking at your work. You can check it out here: https://github.com/scottwinkler/terraform-provider-shell/tree/feature/state. Basically I got rid of stdout, stderr and state. In my opinion, this greatly simplifies using this provider. Now all there is is outputs, which coupled with the environment variables is the "state". Also made read and update optional. The data resource is working, but haven't yet gotten the shell script resource working, hopefully tomorrow.
Not going to merge this branch because it has diverged from what I would want, but I'm happy you were able to solve your problem. Interested to see what further developments you make 👍
Cool, expected as much :+1: thanks for your help Now if there was only a simple way to use a custom provider with terraform..
Super rough WIP of what we're currently working through as an FYI
Currently using it with
kubectl
and is working well, as discussed in #1 it is a bit of a departure from your existing usage. Notably i've rejigged how passing back the state works, so rather than usingstdout
which is hard to control (having to pipe every script cmd somewhere), i've made it opt-in, you pipe important output to an extra fd via... >3&
.Process terraform goes through:
image
tag in the manifeststate
property against the local value calculated in step 1 (image tag comparison)kubectl
will re-align the imageExample usage:
pod.yml