After creation of a resource I would like to execute a kubectl port-forward
command with a local-exec provisioner.
Doing so will keep the resource creation in a pending (still creating) state:
Currently I’m trying:
# Terraform
# ... inside resource
provisioner "local-exec" {
interpreter = ["bash", "-c"]
working_dir = "${path.module}/../../../scripts"
command = "./execute.sh 'nohup kubectl port-forward svc/web 9500:8084 --namespace linkerd' &"
}
# Script
#! /bin/bash
eval $1
disown
I’m just messing around with combinations of background tasks & (in the script, when calling the script, …), nohub, disown, using no script, sleep 1, redirects to null, etc … Anything I could find really…
I would expect kubectl port-forward svc/web 9500:8084 --namespace linkerd &
to be sufficient, but TF is not able to finish creation of the resource.
I’m working on a Windows machine (/bin/bash as interpreter doesn’t work for me) with Terraform v1.2.5.
Is there a way to perform a port-forward and get my Terminal back?
Thanks.