xunleii / terraform-module-k3s

Terraform module to manage a k3s cluster on given machines
https://registry.terraform.io/modules/xunleii/k3s/module
MIT License
183 stars 53 forks source link

Refresh kubeconfig when terraform state is lost #142

Closed alita1991 closed 10 months ago

alita1991 commented 10 months ago

Hi,

I have a scenario, where I need to refresh the local kubeconfig with the one from the target host. Right now, terraform does not offer a way to copy a remote file to the local host.

https://github.com/hashicorp/terraform/issues/3379

Is there a way to refresh the kubeconfig with the current module if I lose the tfstate or any other alternative solution that can be automated via terraform?

Thanks

xunleii commented 10 months ago

Hi @alita1991, the only way I can found today is using the external provider which allows you to make what you want and expose any information to Terraform (like a shell script that cat | sed the kubeconfig remotely).

alita1991 commented 10 months ago

Hi, sadly, the external provider does not allow the user to SSH directly, I decided to pick a module developed by the community called terraform-provider-ssh, which does what I need.

If there is a better solution, please let me know, if not, you can close this ticket.

xunleii commented 10 months ago

Thank you for sharing this, it will help the next ones who will ask this question. Unfortunately, I currently have a better way to do this with a Terraform module. I think the best way to handle this type of action (and others from different issues) is to migrate this module into a Terraform provider, which takes a lot more time to do and maintain.