BetterStackHQ / terraform-provider-better-uptime

Apache License 2.0
45 stars 12 forks source link

Allow provider "alias" parameter #59

Closed rmvangun closed 1 month ago

rmvangun commented 8 months ago

Because the BetterUptime provider requires a separate API token per team, and we prefer to define all our BetterUptime resources in a single Terraform project, we need a unique API token per team in Terraform. This means multiple provider blocks are necessary (note that this is a little unusual... most providers allow a single global API token for the service/account) . However, if I configure the alias property, I get:

│ Error: Missing required argument
│ 
│ The argument "api_token" is required, but was not set.

If I remove the alias, which requires I only use a single BetterUptime provider block, this goes away. So, maybe it is a problem of not supporting the "alias", or maybe it is a problem validating the provider block?

This works:

provider "betteruptime" {
  api_token = data.sops_file.secrets.data["betteruptime_engineering_api_key"]
}

This does not work:

provider "betteruptime" {
  api_token = data.sops_file.secrets.data["betteruptime_engineering_api_key"]
  alias          = "engineering"
}

I'm running 0.3.20 of the provider and terraform 1.5.3.

peter-hippo commented 8 months ago

@rmvangun Hi there!

This sounds strange since I've also recently started to configure our both teams in Betteruptime with Terraform.

provider "betteruptime" {
  api_token = local.betteruptime_api_token_team_1
  alias     = "team_1"
}

provider "betteruptime" {
  api_token = local.betteruptime_api_token_team_2
  alias     = "team_2"
}

and this works just fine.

We are using the provider version 0.3.17 and TF is also 1.5.3

PetrHeinz commented 1 month ago

Hello @rmvangun, @peter-hippo 👋

Thanks for reaching out and for your patience 🙏

I just wanted to say the workaround with aliases is no longer needed since we now support Global tokens. You can find them in API Tokens in your account on a separate tab:

image

Using a global token requires using team_name field with your resources.


You can still of course keep using team-bound tokens if you want the distinction.

Hope this helps 🙌