terraform-provider-iterative icon indicating copy to clipboard operation
terraform-provider-iterative copied to clipboard

Common method for command execution

Open 0x2b3bfa0 opened this issue 2 years ago • 0 comments

It would be nice[^1] to have an Execute method to run commands in any of the active instances.

https://github.com/iterative/terraform-provider-iterative/blob/57625b6db38238a18dd10797ac239710c5f94f8a/task/task.go#L37-L47

Loose ends

  • How to deal with parallelism?
    • Run the command on every instance and return a slice of results.
    • Allow users to specify an index in the range [0, parallelism[ and return an error if there aren't enough instances running to satisfy the requested index.
    • Allow users to list the running instances for a given task and select one of them to run the command on.
    • ~Pick a random instance every time.~ I had to include it. 😂

Draft proposal

  • Execute(instance uint16, input string, command ...string) (Result, error)

    • instance represents the instance index in the range [0, parallelism[; maybe we can use a string identifier instead.
    • input optionally, the standard input to feed the remote command with; "" will disable this function.
    • command is the slice of exec–like arguments; “no arguments” can default to sh or bash if appropriate.
    • Result is a struct containing
      • Standard output
      • Standard error
      • Exit code
  • ExecuteTTY(instance uint16, streams Streams, command ...string) error Same as above but with TTY and interactive streams, so it behaves like an ordinary SSH session. See kubectl exec for an example implementation.

[^1]: Not necessary because #237 eliminates the need of SSH by implementing #126

0x2b3bfa0 avatar Nov 24 '21 16:11 0x2b3bfa0