yandex-cloud / terraform-provider-yandex

Terraform Yandex provider
https://www.terraform.io/docs/providers/yandex/
Mozilla Public License 2.0
213 stars 116 forks source link

Feature Request: Obtain YC_TOKEN running cli `yc iam create-token` if ServiceAccountKeyFileOrContent and Token not present #391

Open EnergoStalin opened 1 year ago

EnergoStalin commented 1 year ago

Currently i have workaround like this.

export YC_TOKEN=$(yc iam create-token)

terraform $@

I'd like to reduce boilerplate for small projects like remote-state where you actually don't care about proper setup and just need create SA and Bucket quckly.

I've seen this very old issue #10 that suggest similar but i'm suggesting obtain only short living token by calling yc itself.

As ready solution this would work.

if len(config.ServiceAccountKeyFileOrContent) == 0 && len(config.Token) == 0 {
  if bytes, err := exec.Command("yc", "iam", "create-token").Output(); err == nil {
    config.Token = strings.Trim(string(bytes), "\n\t ")
  }
}