Skip to content

Commit 1ed59b7

Browse files
feat: Add support for MONGODB_ATLAS_PUBLIC_API_KEY and MONGODB_ATLAS_PRIVATE_API_KEY to TF (#3505)
1 parent 1980fa7 commit 1ed59b7

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

.changelog/3505.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:note
2+
New environment variables: We added support for the `MONGODB_ATLAS_PUBLIC_API_KEY` and `MONGODB_ATLAS_PRIVATE_API_KEY` environment variables which are widely used across the MongoDB ecosystem.
3+
```

docs/index.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ You can use any the following methods:
4949
### Environment Variables
5050

5151
You can also provide your credentials via the environment variables,
52-
`MONGODB_ATLAS_PUBLIC_KEY` and `MONGODB_ATLAS_PRIVATE_KEY`,
52+
`MONGODB_ATLAS_PUBLIC_API_KEY` and `MONGODB_ATLAS_PRIVATE_API_KEY`,
5353
for your public and private MongoDB Atlas programmatic API key pair respectively:
5454

5555
```terraform
@@ -59,14 +59,13 @@ provider "mongodbatlas" {}
5959
Usage (prefix the export commands with a space to avoid the keys being recorded in OS history):
6060

6161
```shell
62-
$ export MONGODB_ATLAS_PUBLIC_KEY="<ATLAS_PUBLIC_KEY>"
63-
$ export MONGODB_ATLAS_PRIVATE_KEY="<ATLAS_PRIVATE_KEY>"
62+
$ export MONGODB_ATLAS_PUBLIC_API_KEY="<ATLAS_PUBLIC_KEY>"
63+
$ export MONGODB_ATLAS_PRIVATE_API_KEY="<ATLAS_PRIVATE_KEY>"
6464
$ terraform plan
6565
```
6666

67-
As an alternative to `MONGODB_ATLAS_PUBLIC_KEY` and `MONGODB_ATLAS_PRIVATE_KEY`
68-
if you are using [MongoDB CLI](https://docs.mongodb.com/mongocli/stable/)
69-
then `MCLI_PUBLIC_API_KEY` and `MCLI_PRIVATE_API_KEY` are also supported.
67+
We recommend that you use the `MONGODB_ATLAS_PUBLIC_API_KEY` and `MONGODB_ATLAS_PRIVATE_API_KEY` environment variables because they are compatible with other MongoDB tools, such as Atlas CLI.
68+
You can still use `MONGODB_ATLAS_PUBLIC_KEY` and `MONGODB_ATLAS_PRIVATE_KEY` as alternative keys in your local environment. However, these environment variables are not guaranteed to work across all tools in the MongoDB ecosystem.
7069

7170
### AWS Secrets Manager
7271
AWS Secrets Manager (AWS SM) helps to manage, retrieve, and rotate database credentials, API keys, and other secrets throughout their lifecycles. See [product page](https://aws.amazon.com/secrets-manager/) and [documentation](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) for more details.

internal/provider/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ func setDefaultValuesWithValidations(ctx context.Context, data *tfMongodbAtlasPr
352352

353353
if data.PublicKey.ValueString() == "" {
354354
data.PublicKey = types.StringValue(MultiEnvDefaultFunc([]string{
355+
"MONGODB_ATLAS_PUBLIC_API_KEY",
355356
"MONGODB_ATLAS_PUBLIC_KEY",
356357
"MCLI_PUBLIC_API_KEY",
357358
}, "").(string))
@@ -362,6 +363,7 @@ func setDefaultValuesWithValidations(ctx context.Context, data *tfMongodbAtlasPr
362363

363364
if data.PrivateKey.ValueString() == "" {
364365
data.PrivateKey = types.StringValue(MultiEnvDefaultFunc([]string{
366+
"MONGODB_ATLAS_PRIVATE_API_KEY",
365367
"MONGODB_ATLAS_PRIVATE_KEY",
366368
"MCLI_PRIVATE_API_KEY",
367369
}, "").(string))

internal/provider/provider_sdk2.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ func setDefaultsAndValidations(d *schema.ResourceData) diag.Diagnostics {
351351
}
352352

353353
if err := setValueFromConfigOrEnv(d, "public_key", []string{
354+
"MONGODB_ATLAS_PUBLIC_API_KEY",
354355
"MONGODB_ATLAS_PUBLIC_KEY",
355356
"MCLI_PUBLIC_API_KEY",
356357
}); err != nil {
@@ -361,6 +362,7 @@ func setDefaultsAndValidations(d *schema.ResourceData) diag.Diagnostics {
361362
}
362363

363364
if err := setValueFromConfigOrEnv(d, "private_key", []string{
365+
"MONGODB_ATLAS_PRIVATE_API_KEY",
364366
"MONGODB_ATLAS_PRIVATE_KEY",
365367
"MCLI_PRIVATE_API_KEY",
366368
}); err != nil {

0 commit comments

Comments
 (0)