Skip to content

Commit

Permalink
fix: changed access key env to BA_ACCESS_KEY (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
wai-wong-edb authored Feb 23, 2024
1 parent 33ec879 commit b3aaa31
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ testacc:

.PHONY: docs
unexport BA_BEARER_TOKEN
unexport EDB_TF_ACCESS_KEY
unexport BA_ACCESS_KEY
unexport BA_API_URI
docs:
go generate
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ terraform {
provider "biganimal" {
# Configuration options
ba_bearer_token = <redacted> // See Getting an API Token section for details
edb_tf_access_key = <redacted> // See Getting an Access Key section for details
ba_access_key = <redacted> // See Getting an Access Key section for details
// ba_api_uri = "https://portal.biganimal.com/api/v3" // Optional
}
```

You can also set the `BA_BEARER_TOKEN`, `EDB_TF_ACCESS_KEY` and `BA_API_URI` env vars. When those environment variables are present, you
don't need to add any configuration options to the provider block described above. Only either `BA_BEARER_TOKEN` or `EDB_TF_ACCESS_KEY` needs to be set, if both are set then `EDB_TF_ACCESS_KEY` will take priority and be used.
You can also set the `BA_BEARER_TOKEN`, `BA_ACCESS_KEY` and `BA_API_URI` env vars. When those environment variables are present, you
don't need to add any configuration options to the provider block described above. Only either `BA_BEARER_TOKEN` or `BA_ACCESS_KEY` needs to be set, if both are set then `BA_ACCESS_KEY` will take priority and be used.

```bash
export BA_BEARER_TOKEN=<redacted>
export EDB_TF_ACCESS_KEY=<redacted>
export BA_ACCESS_KEY=<redacted>
export BA_API_URI=https://portal.biganimal.com/api/v3
```

> [!WARNING]
> OAuth2 authorization and thus `BA_BEARER_TOKEN` will be deprecated in future Terraform Provider releases. It is recommended to use `EDB_TF_ACCESS_KEY` as soon as you can.
> OAuth2 authorization and thus `BA_BEARER_TOKEN` will be deprecated in future Terraform Provider releases. It is recommended to use `BA_ACCESS_KEY` as soon as you can.
### Getting an API Token

Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ see [Getting started with the BigAnimal free trial.](https://www.enterprisedb.co
# Configure the BigAnimal Provider
provider "biganimal" {
ba_bearer_token = "<redacted>"
// edb_tf_access_key: if set, this will be used instead of the ba_bearer_token above.
// ba_access_key: if set, this will be used instead of the ba_bearer_token above.
// This can also be set as an environment variable. If it is set both here and
// in an environment variable then the access key set in the environment variable
// will take priority and be used
edb_tf_access_key = "<redacted>"
ba_access_key = "<redacted>"
//ba_api_uri = "https://portal.biganimal.com/api/v3" // Optional
}
# Manage the resources
```

## Environment Variables

Credentials can be provided by using the `BA_BEARER_TOKEN` or `EDB_TF_ACCESS_KEY` and optionally `BA_API_URI` environment variables.
Credentials can be provided by using the `BA_BEARER_TOKEN` or `BA_ACCESS_KEY` and optionally `BA_API_URI` environment variables.

<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `ba_access_key` (String) BigAnimal Access Key
- `ba_api_uri` (String) BigAnimal API URL
- `ba_bearer_token` (String) BigAnimal Bearer Token
- `edb_tf_access_key` (String) BigAnimal Access Key
4 changes: 2 additions & 2 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Configure the BigAnimal Provider
provider "biganimal" {
ba_bearer_token = "<redacted>"
// edb_tf_access_key: if set, this will be used instead of the ba_bearer_token above.
// ba_access_key: if set, this will be used instead of the ba_bearer_token above.
// This can also be set as an environment variable. If it is set both here and
// in an environment variable then the access key set in the environment variable
// will take priority and be used
edb_tf_access_key = "<redacted>"
ba_access_key = "<redacted>"
//ba_api_uri = "https://portal.biganimal.com/api/v3" // Optional
}
# Manage the resources
4 changes: 2 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ type API struct {
HTTPClient http.Client
}

func NewAPI(edb_tf_access_key, ba_bearer_token, ba_api_uri, userAgent string) *API {
func NewAPI(ba_access_key, ba_bearer_token, ba_api_uri, userAgent string) *API {
httpClient := http.Client{
Timeout: 10 * time.Second,
}

api := &API{
BaseURL: ba_api_uri,
Token: ba_bearer_token,
AccessKey: edb_tf_access_key,
AccessKey: ba_access_key,
UserAgent: userAgent,
HTTPClient: httpClient,
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewSDKProvider(version string) func() *sdkschema.Provider {
Sensitive: false,
Optional: true,
},
"edb_tf_access_key": {
"ba_access_key": {
Type: sdkschema.TypeString,
Description: "BigAnimal Access Key",
Sensitive: false,
Expand Down Expand Up @@ -76,10 +76,10 @@ func configure(version string, p *sdkschema.Provider) func(context.Context, *sdk
// If the credential data are provided inside a provider block, get them first
// If they are not provided, the schema_* credentials will be empty strings
schema_ba_bearer_token := schema.Get("ba_bearer_token").(string)
schema_edb_tf_access_key := schema.Get("edb_tf_access_key").(string)
schema_ba_access_key := schema.Get("ba_access_key").(string)
schema_ba_api_uri := schema.Get("ba_api_uri").(string)

data := &providerData{BaAPIUri: &schema_ba_api_uri, BaBearerToken: &schema_ba_bearer_token, EdbTFAccessKey: &schema_edb_tf_access_key}
data := &providerData{BaAPIUri: &schema_ba_api_uri, BaBearerToken: &schema_ba_bearer_token, EdbTFAccessKey: &schema_ba_access_key}
ok, summary, detail := checkProviderConfig(data)
if !ok {
return nil, diag.Diagnostics{diag.Diagnostic{Severity: diag.Error, Summary: summary, Detail: detail}}
Expand All @@ -97,7 +97,7 @@ type bigAnimalProvider struct {
// providerData can be used to store data from the Terraform configuration.
type providerData struct {
BaBearerToken *string `tfsdk:"ba_bearer_token"`
EdbTFAccessKey *string `tfsdk:"edb_tf_access_key"`
EdbTFAccessKey *string `tfsdk:"ba_access_key"`
BaAPIUri *string `tfsdk:"ba_api_uri"`
}

Expand Down Expand Up @@ -145,15 +145,15 @@ func checkProviderConfig(data *providerData) (ok bool, summary, detail string) {
}

// access key environment variable takes precedence over access key schema field
accessKey := os.Getenv("EDB_TF_ACCESS_KEY")
accessKey := os.Getenv("BA_ACCESS_KEY")
if accessKey != "" {
data.EdbTFAccessKey = &accessKey
} else if data.EdbTFAccessKey == nil || *data.EdbTFAccessKey == "" {
data.EdbTFAccessKey = &accessKey
}

if *data.EdbTFAccessKey == "" && *data.BaBearerToken == "" {
return false, "Unable to find EDB_TF_ACCESS_KEY or BA_BEARER_TOKEN", "EDB_TF_ACCESS_KEY and BA_BEARER_TOKEN both cannot be an empty string"
return false, "Unable to find BA_ACCESS_KEY or BA_BEARER_TOKEN", "BA_ACCESS_KEY and BA_BEARER_TOKEN both cannot be an empty string"
}

if data.BaAPIUri == nil || *data.BaAPIUri == "" {
Expand All @@ -175,7 +175,7 @@ func (b bigAnimalProvider) Schema(ctx context.Context, request provider.SchemaRe
Sensitive: false,
Optional: true,
},
"edb_tf_access_key": frameworkschema.StringAttribute{
"ba_access_key": frameworkschema.StringAttribute{
MarkdownDescription: "BigAnimal Access Key",
Sensitive: false,
Optional: true,
Expand Down
2 changes: 1 addition & 1 deletion templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ see [Getting started with the BigAnimal free trial.](https://www.enterprisedb.co

## Environment Variables

Credentials can be provided by using the `BA_BEARER_TOKEN` or `EDB_TF_ACCESS_KEY` and optionally `BA_API_URI` environment variables.
Credentials can be provided by using the `BA_BEARER_TOKEN` or `BA_ACCESS_KEY` and optionally `BA_API_URI` environment variables.

{{ .SchemaMarkdown | trimspace }}

0 comments on commit b3aaa31

Please sign in to comment.