terraform-plugin-sdk
terraform-plugin-sdk copied to clipboard
Ability to write to Terraform UI from resource
Currently it looks like impossible to write any kind of text to the CLI from TF resource during read/update/delete/etc function. As it doesn't receive terraform.UIOutput
This block's me from the proper AWS ECS Service deployment implementation (where we're waiting for the successful deployment).
This also might be really useful for any resource that has complicated create/delete/update process so it's useful to show some information about the process to the user.
TF version: 0.11.7
@apparentlymart Hi! Will it work for you if I'll try to send PR for this?
Hi @StyleT! Thanks for sharing this use-case.
The ability to show progress to the user is a good idea for resource types where operations can last for a long time and have several steps. We'll want to think about this a little though, since ideally I'd want to see this output be more structured than just arbitrary text logs so that future iterations of the UI can potentially aggregate the output for better readability.
For example, perhaps we could allow a provider to report the beginning and end of various sub-actions, and perhaps to optionally report percentage completion that the UI might be able to show as a progress bar when running in an interactive terminal.
Looking further out, we'd ideally like to eventually support machine-readable output to allow more graphical UIs to be overlayed, and so having the progress output be structured would be helpful in that context too.
The current UI output mechanism is going to need to be rebuilt for our current work to replace the net/rpc plugin protocol with a new grpc-based protocol, so it's likely that our initial pass of that won't have any channel for providers to provide output, but we can potentially add that back in later when we have a better idea of how it would work.
I would suggest not attempting a PR for this right now because we're in the process of making some significant changes to the protocol, starting in hashicorp/terraform#18297. To avoid conflicting with that work, I think it'd be best to hold on this until that work completes (planned for the next major release).
Ok, thank you for your prompt response. I would also ask you to consider use case when you need to stream sort of log to the user. In my case I need to stream events log from ECS service to display deployment process. So in my case it will be hard to structure it.
Passing through, but there's a few use-cases where this'd be useful in Azure-land:
- interactive (e.g. 2FA/device-code) authentication
- "soft delete" where a resource has been deleted but can kick around for N days
- logging of additional nested workflows (e.g. restarting VM's, deleting os/data disks attached to a vm etc)
Just so other similar provider-based UI ideas/concepts are linked:
- https://github.com/hashicorp/terraform-plugin-sdk/issues/86
- https://github.com/hashicorp/terraform/issues/27550