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

[Feature]: add add_token_to_env provider argument

Open simonostendorf opened this issue 1 year ago • 3 comments

What whould you like to see?

I think it would be helpful to add the token to the env var HCLOUD_TOKEN if not already present.

This would help when using external scripts (e.g. terraform_data resource with local provisioner) that require a Hetzner Cloud API Token.

My usecase: I am checking if a hcloud snapshot exists (using the hcloud_images data source), if not I am calling the hcloud-upload-image binary using a terraform_data resource. So it would be helpful to use the same token as the provider and therefor the token must/should be exported as HCLOUD_TOKEN.

See example add_address_to_env from terraform-provider-vault

simonostendorf avatar Oct 07 '24 14:10 simonostendorf

This issue has been marked as stale because it has not had recent activity. The bot will close the issue if no further action occurs.

github-actions[bot] avatar Jan 06 '25 12:01 github-actions[bot]

Not stale.

simonostendorf avatar Jan 07 '25 08:01 simonostendorf

I am not sure if this would work. As far as I understood, os.Setenv() can only modify the environment variables of the currently running process. As terraform spawns a new process for each provider (and restarts them quite often), even if we were to add the token to the environment it would not be visible to any other provider or to terraform itself.

apricote avatar Mar 04 '25 15:03 apricote