flaupretre/terraform-ssh-tunnel

Running terraform apply from plan out.

Closed this issue · 2 comments

When running terraform apply from a plan output this module with not work. Do you have any work arounds?
Example
terraform plan -input=false -out tf.plan
terraform apply -input=false -auto-approve tf.plan

When running terraform apply from a plan output this module with not work. Do you have any work arounds? Example terraform plan -input=false -out tf.plan terraform apply -input=false -auto-approve tf.plan

Unfortunately I don't think there is a workaround for this. We have a similar setup to this module, just adjusted to use AWS SSM and it suffers from the same problem. If you plan and apply in two separate steps, then in the apply phase, the connection won't be established.

If you run it in a single command. terraform apply, then it works. However, like you I also want to generate a plan, then do an apply.

The approach in this module is based on data sources, and data sources in TF either only run during the plan or apply phase (when a computed value is required), but not both. I've tried myself to come up with a workaround, but nothing seems to work in all cases.

Either there needs to be native support in TF for establishing tunnels (aside from the TF Cloud Agent), or there needs to be a new kind of block in TF that runs during both the plan and apply phase.

I agree with @seanamos' comment. I have no solution for this at the moment. A future solution may come from changes in the way terraform handles data sources or, maybe, from the transformation of this module into a provider. Anyway, it is not planned yet.