Repository: honeycombio/terraform-provider-honeycombio (language: python)

Issue:
Add HONEYCOMB_API_KEY envvar support
The Honeycomb standard has become `HONEYCOMB_API_KEY` so the provider should support it too in the name of consistency.

This will deprecate but continue to support the current `HONEYCOMBIO_APIKEY` but drop support altogether for the 1.0.0 release.


Discussion / hints:
@jharley I can take a look into this if that's alright. 
@teddylear That'd be great!

Fix patch:
diff --git a/.env b/.env
index 97732e5c..cd4a61d2 100644
--- a/.env
+++ b/.env
@@ -1,3 +1,3 @@
-#HONEYCOMBIO_APIKEY=
+#HONEYCOMB_API_KEY=
 #HONEYCOMBIO_DATASET=
 TF_ACC=1
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index fef2137f..ba28e59b 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -26,7 +26,7 @@ jobs:
 
       - name: Test
         env:
-          HONEYCOMBIO_APIKEY: ${{ secrets.HONEYCOMBIO_APIKEY }}
+          HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMBIO_APIKEY }}
           HONEYCOMBIO_DATASET: ${{ secrets.HONEYCOMBIO_DATASET }}
           TF_ACC: 1
         run: |
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 566b5384..03df420d 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -33,7 +33,7 @@ Next, **initialize the dataset**. The helper script [setup-testsuite-dataset](sc
 Finally, **run the acceptance tests** by passing the API key and dataset as environment variables:
 
 ```sh
-HONEYCOMBIO_APIKEY=<your API key> HONEYCOMBIO_DATASET=<dataset> make testacc
+HONEYCOMB_API_KEY=<your API key> HONEYCOMBIO_DATASET=<dataset> make testacc
 ```
 
 ### Using a locally built version of the provider
@@ -85,7 +85,7 @@ If you fork the repository, you can also run the tests on GitHub Actions (for fr
 
 To properly setup the GitHub Actions, add the following secrets:
 
-- `HONEYCOMBIO_APIKEY`: an API key for Honeycombio
+- `HONEYCOMB_API_KEY`: an API key for Honeycombio
 - `HONEYCOMBIO_DATASET`: name of the test dataset
 
 ## Release procedure
diff --git a/README.md b/README.md
index 7dfe87bb..c2b02b8b 100644
--- a/README.md
+++ b/README.md
@@ -7,10 +7,10 @@
 
 A Terraform provider for Honeycomb.io.
 
-📄 Check out [the documentation](https://registry.terraform.io/providers/honeycombio/honeycombio/latest/docs)  
-🏗️ Examples can be found in [example/](example/)  
-❓ Questions? Feel free to create a new issue or find us on the **Honeycomb Pollinators** Slack, channel [**#terraform-provider**](https://honeycombpollinators.slack.com/archives/C017T9FFT0D) (you can find a link to request an invite [here](https://www.honeycomb.io/blog/spread-the-love-appreciating-our-pollinators-community/))  
-🔧 Want to contribute? Check out [CONTRIBUTING.md](./CONTRIBUTING.md)  
+📄 Check out [the documentation](https://registry.terraform.io/providers/honeycombio/honeycombio/latest/docs)
+🏗️ Examples can be found in [example/](example/)
+❓ Questions? Feel free to create a new issue or find us on the **Honeycomb Pollinators** Slack, channel [**#terraform-provider**](https://honeycombpollinators.slack.com/archives/C017T9FFT0D) (you can find a link to request an invite [here](https://www.honeycomb.io/blog/spread-the-love-appreciating-our-pollinators-community/))
+🔧 Want to contribute? Check out [CONTRIBUTING.md](./CONTRIBUTING.md)
 
 ## Using the provider
 
@@ -27,7 +27,7 @@ terraform {
 }
 ```
 
-Set the API key used by Terraform setting the `HONEYCOMBIO_APIKEY` environment variable.
+Set the API key used by Terraform setting the `HONEYCOMB_API_KEY` environment variable.
 
 ## License
 
diff --git a/docs/index.md b/docs/index.md
index febc3a65..54443746 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -21,7 +21,7 @@ terraform {
 
 # Configure the Honeycomb provider
 provider "honeycombio" {
-  # You can set the API key with the environment variable HONEYCOMBIO_APIKEY
+  # You can set the API key with the environment variable HONEYCOMB_API_KEY
 }
 
 variable "dataset" {
@@ -40,14 +40,16 @@ resource "honeycombio_marker" "hello" {
 
 The Honeycomb provider requires an API key to communicate with the Honeycomb API. API keys and their permissions can be managed in _Team settings_.
 
-The key can be set with the `api_key` argument or via the `HONEYCOMBIO_APIKEY` environment variable.
+The key can be set with the `api_key` argument or via the `HONEYCOMB_API_KEY` or `HONEYCOMBIO_APIKEY` environment variable.
 
-~> **Note** Hard-coding API keys in any Terraform configuration is not recommended. Consider using the `HONEYCOMBIO_APIKEY` environment variable.
+`HONEYCOMB_API_KEY` environment variable will take priority over the `HONEYCOMBIO_APIKEY` environment variable.
+
+~> **Note** Hard-coding API keys in any Terraform configuration is not recommended. Consider using the one of the  environment variable options.
 
 ## Argument Reference
 
 Arguments accepted by this provider include:
 
-* `api_key` - (Required) The Honeycomb API key to use. It can also be set using the `HONEYCOMBIO_APIKEY` environment variable.
+* `api_key` - (Required) The Honeycomb API key to use. It can also be set using `HONEYCOMB_API_KEY` or `HONEYCOMBIO_APIKEY` environment variables.
 * `api_url` - (Optional) Override the url of the Honeycomb.io API. Defaults to `https://api.honeycomb.io`.
 * `debug` - (Optional) Enable to log additional debug information. To view the logs, set `TF_LOG` to at least debug.
diff --git a/go.mod b/go.mod
index 9b6d7e13..c4ae71b6 100644
--- a/go.mod
+++ b/go.mod
@@ -4,6 +4,7 @@ go 1.17
 
 require (
 	github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
+	github.com/hashicorp/terraform-plugin-log v0.6.0
 	github.com/hashicorp/terraform-plugin-sdk/v2 v2.19.0
 	github.com/joho/godotenv v1.4.0
 	github.com/stretchr/testify v1.8.0
@@ -31,7 +32,6 @@ require (
 	github.com/hashicorp/terraform-exec v0.17.2 // indirect
 	github.com/hashicorp/terraform-json v0.14.0 // indirect
 	github.com/hashicorp/terraform-plugin-go v0.12.0 // indirect
-	github.com/hashicorp/terraform-plugin-log v0.6.0 // indirect
 	github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
 	github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
 	github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
diff --git a/honeycombio/provider.go b/honeycombio/provider.go
index 9b2be2ab..14fbdd0c 100644
--- a/honeycombio/provider.go
+++ b/honeycombio/provider.go
@@ -6,6 +6,7 @@ import (
 	"os"
 	"strconv"
 
+	"github.com/hashicorp/terraform-plugin-log/tflog"
 	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
 	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
 	honeycombio "github.com/honeycombio/terraform-provider-honeycombio/client"
@@ -21,14 +22,25 @@ func init() {
 // overwritten during the release process.
 var providerVersion = "dev"
 
+func deprecatedEnvCheck() schema.SchemaDefaultFunc {
+	if _, ok := os.LookupEnv("HONEYCOMBIO_APIKEY"); ok {
+		ctx := context.Background()
+		tflog.Warn(ctx, "HONEYCOMBIO_APIKEY has been deprecated, please use HONEYCOMB_API_KEY instead")
+	}
+	return schema.EnvDefaultFunc("HONEYCOMBIO_APIKEY", nil)
+}
+
 func Provider() *schema.Provider {
 	provider := &schema.Provider{
 		Schema: map[string]*schema.Schema{
 			"api_key": {
-				Type:        schema.TypeString,
-				Required:    true,
-				DefaultFunc: schema.EnvDefaultFunc("HONEYCOMBIO_APIKEY", nil),
-				Sensitive:   true,
+				Type:     schema.TypeString,
+				Required: true,
+				// Tiering goes HONEYCOMB_API_KEY > HONEYCOMBIO_APIKEY > nil
+				DefaultFunc: schema.EnvDefaultFunc(
+					"HONEYCOMB_API_KEY",
+					deprecatedEnvCheck()),
+				Sensitive: true,
 			},
 			"api_url": {
 				Type:     schema.TypeString,


Test patch:
diff --git a/client/client_test.go b/client/client_test.go
index 8c46d3e4..8a944fad 100644
--- a/client/client_test.go
+++ b/client/client_test.go
@@ -15,9 +15,9 @@ func init() {
 }
 
 func newTestClient(t *testing.T) *Client {
-	apiKey, ok := os.LookupEnv("HONEYCOMBIO_APIKEY")
+	apiKey, ok := os.LookupEnv("HONEYCOMB_API_KEY")
 	if !ok {
-		t.Fatal("expected environment variable HONEYCOMBIO_APIKEY")
+		t.Fatal("expected environment variable HONEYCOMB_API_KEY")
 	}
 	_, debug := os.LookupEnv("DEBUG")
 
diff --git a/client/example_test.go b/client/example_test.go
index a2283358..12551efa 100644
--- a/client/example_test.go
+++ b/client/example_test.go
@@ -8,7 +8,7 @@ import (
 
 // This example shows how to configure and use a client to list all boards.
 func Example() {
-	apiKey, _ := os.LookupEnv("HONEYCOMBIO_APIKEY")
+	apiKey, _ := os.LookupEnv("HONEYCOMB_API_KEY")
 
 	config := &Config{
 		APIKey: apiKey,
diff --git a/honeycombio/provider_test.go b/honeycombio/provider_test.go
index c43be407..a5a219d2 100644
--- a/honeycombio/provider_test.go
+++ b/honeycombio/provider_test.go
@@ -16,8 +16,8 @@ func init() {
 
 func testAccPreCheck(t *testing.T) func() {
 	return func() {
-		if _, ok := os.LookupEnv("HONEYCOMBIO_APIKEY"); !ok {
-			t.Fatalf("environment variable HONEYCOMBIO_APIKEY must be set to run acceptance tests")
+		if _, ok := os.LookupEnv("HONEYCOMB_API_KEY"); !ok {
+			t.Fatalf("environment variable HONEYCOMB_API_KEY must be set to run acceptance tests")
 		}
 		if _, ok := os.LookupEnv("HONEYCOMBIO_DATASET"); !ok {
 			t.Fatalf("environment variable HONEYCOMBIO_DATASET must be set to run acceptance tests")
@@ -33,7 +33,7 @@ var testAccProviderFactories = map[string]func() (*schema.Provider, error){
 
 func testAccClient(t *testing.T) *honeycombio.Client {
 	cfg := &honeycombio.Config{
-		APIKey: os.Getenv("HONEYCOMBIO_APIKEY"),
+		APIKey: os.Getenv("HONEYCOMB_API_KEY"),
 	}
 	c, err := honeycombio.NewClient(cfg)
 	if err != nil {
diff --git a/scripts/setup-testsuite-dataset b/scripts/setup-testsuite-dataset
index cf7e4314..435bd99f 100755
--- a/scripts/setup-testsuite-dataset
+++ b/scripts/setup-testsuite-dataset
@@ -24,7 +24,7 @@ log () {
 dataset_exists() {
   local name="$1"
 
-  curl -sf -H "x-honeycomb-team: $HONEYCOMBIO_APIKEY" \
+  curl -sf -H "x-honeycomb-team: $HONEYCOMB_API_KEY" \
     -X GET "${DATASETS_API}/${HONEYCOMBIO_DATASET}" >/dev/null
 }
 
@@ -32,7 +32,7 @@ create_dataset_if_missing () {
   local name="$1"
 
   if ! dataset_exists "$name"; then
-    curl -sf -H "x-honeycomb-team: $HONEYCOMBIO_APIKEY" \
+    curl -sf -H "x-honeycomb-team: $HONEYCOMB_API_KEY" \
       -X POST "${DATASETS_API}" \
       -d '{"name": "'"$name"'"}' >/dev/null
     status_code=$?
@@ -47,7 +47,7 @@ create_dataset_if_missing () {
 column_exists () {
   local name="$1"
 
-  curl -sf -H "x-honeycomb-team: $HONEYCOMBIO_APIKEY" \
+  curl -sf -H "x-honeycomb-team: $HONEYCOMB_API_KEY" \
     -X GET "${COLUMNS_API}/${HONEYCOMBIO_DATASET}?key_name=${name}" >/dev/null
 }
 
@@ -56,7 +56,7 @@ create_column_if_missing () {
   local type="$2"
 
   if ! column_exists "$name"; then
-    curl -sf -H "x-honeycomb-team: $HONEYCOMBIO_APIKEY" \
+    curl -sf -H "x-honeycomb-team: $HONEYCOMB_API_KEY" \
       -X POST "${COLUMNS_API}/${HONEYCOMBIO_DATASET}" \
       -d '{"key_name": "'"$name"'", "type": "'"$type"'"}' >/dev/null
     status_code=$?
@@ -68,8 +68,8 @@ create_column_if_missing () {
   fi
 }
 
-if [ -z "${HONEYCOMBIO_APIKEY+x}" ]; then
-  echo "HONEYCOMBIO_APIKEY is not set"
+if [ -z "${HONEYCOMB_API_KEY+x}" ]; then
+  echo "HONEYCOMB_API_KEY is not set"
   exit 255
 fi