Unleash / terraform-provider-unleash

Terraform provider for unleash, the Open-source feature management solution
https://www.getunleash.io
Apache License 2.0
7 stars 1 forks source link

feat: allow configuring auth token using UNLEASH_AUTH_TOKEN env #106

Closed JonasBak closed 10 months ago

JonasBak commented 10 months ago

About the changes

This change introduces the possibility of configuring the auth token using UNLEASH_AUTH_TOKEN, instead of AUTH_TOKEN. This is useful when using a bunch of providers, to be able to more easily keep track of which env variables are used where, and avoid conflicts with other providers.

Closes #90

Important files

Discussion points

To avoid a breaking change I changed the configValue so it cloud take multiple values for env variables, and "selects" the first non-empty one. I also saw that configValue.ValueString() returns "" when configValue.IsNull() == true (for the case where no env variable is set and configValue.IsNull() == true), so I think it still keeps its old behaviour.

Maybe the more "specific" UNLEASH_AUTH_TOKEN should be before AUTH_TOKEN so the more specific version if prioritized, in case another provider uses the AUTH_TOKEN variable?

Tymek commented 10 months ago

@JonasBak Thanks you!

Can we unit-test it? This would better document the expected behavior.

func Test_provider_configValue(t *testing.T) {
    t.Setenv("FOO", "foo")
    t.Setenv("BAR", "bar")
    t.Setenv("BAZ", "baz")
    assert.Equal(t, "foo", configValue(types.StringValue("foo"), "bar"))
    assert.Equal(t, "", configValue(types.StringValue(""), "SOME_ENV"))
    assert.Equal(t, "bar", configValue(types.StringValue(""), "BAR"))
    assert.Equal(t, "baz", configValue(types.StringValue(""), "QUX", "BAZ"))
}
JonasBak commented 10 months ago

Thanks for the feedback 🙌 I added a test as you suggested.