Skip to content

Commit 6407a49

Browse files
oarbusiaristosvolantolimaasthamarcosuma
authored
feat: Adds new mongodbatlas_api_key_project_assignment resource (#3461)
* [New Resource] api_key_project_assignment * fix: dots on the i for acctests and unittests * correct SDK version and minor fixes * fix check functions and improve test * changelog * data sources * fix unit test * acc test * add depends on to plural data source in test * return all in plural data source * pr comments * diags * import split * change import format in test * fix importSplit unit test * add comment with CLOUDP * get after update * fail on api key not found * doc: Adds `mongodbatlas_api_key_project_assignment` documentation, examples and migration guide (#3465) * delete old examples * example * api_key_project_assignment docs * migration guide and notes on old resource * format * format * doc * remove referende of old example * espen comments * remove duplicated * fix example * marco comments * example seo * module example and migration path * module example and migration path * comment * attach access list to api key in the example * remove unnecessary space * gen doc * Update docs/guides/project-api-key-migration.md Co-authored-by: Leo Antoli <[email protected]> * import block * table change * pr comments * Update docs/guides/project-api-key-migration.md Co-authored-by: maastha <[email protected]> * assign one api key to multiple projects example * update docs * add limitations and note on migration not being necessary * fix import * Update docs/guides/project-api-key-migration.md Co-authored-by: Marco Suma <[email protected]> * Update docs/data-sources/project_api_keys.md Co-authored-by: Marco Suma <[email protected]> * Update docs/resources/project_api_key.md Co-authored-by: Marco Suma <[email protected]> * Update docs/data-sources/project_api_key.md Co-authored-by: Marco Suma <[email protected]> * fix docs --------- Co-authored-by: Leo Antoli <[email protected]> Co-authored-by: maastha <[email protected]> Co-authored-by: Marco Suma <[email protected]> --------- Co-authored-by: aristosvo <[email protected]> Co-authored-by: Leo Antoli <[email protected]> Co-authored-by: maastha <[email protected]> Co-authored-by: Marco Suma <[email protected]>
1 parent acbe6a5 commit 6407a49

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1448
-201
lines changed

.changelog/3461.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:new-resource
2+
resource/mongodbatlas_api_key_project_assignment
3+
```
4+
5+
```release-note:new-datasource
6+
data-source/mongodbatlas_api_key_project_assignment
7+
```
8+
9+
```release-note:new-datasource
10+
data-source/mongodbatlas_api_key_project_assignments
11+
```

.github/workflows/acceptance-tests-runner.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ jobs:
307307
- 'internal/config/*.go'
308308
- 'internal/service/alertconfiguration/*.go'
309309
- 'internal/service/apikey/*.go'
310+
- 'internal/service/apikeyprojectassignment/*.go'
310311
- 'internal/service/atlasuser/*.go'
311312
- 'internal/service/cloudprovideraccess/*.go'
312313
- 'internal/service/customdbrole/*.go'
@@ -674,6 +675,7 @@ jobs:
674675
./internal/service/organization
675676
./internal/service/orginvitation
676677
./internal/service/projectapikey
678+
./internal/service/apikeyprojectassignment
677679
./internal/service/apikey
678680
./internal/service/rolesorgid
679681
./internal/service/team

contributing/development-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- Fork the repository.
1818
- Clone your forked repository locally.
1919
- We use Go Modules to manage dependencies, so you can develop outside your `$GOPATH`.
20-
- We use [golangci-lint](https://github.com/golangci/golangci-lint) to lint our code, you can install it locally via `make setup`.
20+
- We use [golangci-lint](https://github.com/golangci/golangci-lint) to lint our code, you can install it locally via `make tools`.
2121
### Building
2222
- Enter the provider directory
2323
- Run `make tools` to install the needed tools for the provider
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Data Source: mongodbatlas_api_key_project_assignment
2+
3+
`mongodbatlas_api_key_project_assignment` describes an API Key Project Assignment.
4+
5+
## Example Usages
6+
7+
```terraform
8+
resource "mongodbatlas_api_key" "this" {
9+
org_id = var.org_id
10+
description = "Test API Key"
11+
role_names = ["ORG_READ_ONLY"]
12+
}
13+
14+
resource "mongodbatlas_project" "first_project" {
15+
name = "First Project"
16+
org_id = var.org_id
17+
}
18+
19+
resource "mongodbatlas_project" "second_project" {
20+
name = "Second Project"
21+
org_id = var.org_id
22+
}
23+
24+
resource "mongodbatlas_api_key_project_assignment" "first_assignment" {
25+
project_id = mongodbatlas_project.first_project.id
26+
api_key_id = mongodbatlas_api_key.this.api_key_id
27+
roles = ["GROUP_OWNER"]
28+
}
29+
30+
resource "mongodbatlas_api_key_project_assignment" "second_assignment" {
31+
project_id = mongodbatlas_project.second_project.id
32+
api_key_id = mongodbatlas_api_key.this.api_key_id
33+
roles = ["GROUP_OWNER"]
34+
}
35+
36+
# Add IP Access List Entry to Programmatic API Key
37+
resource "mongodbatlas_access_list_api_key" "this" {
38+
org_id = var.org_id
39+
cidr_block = "0.0.0.0/1"
40+
api_key_id = mongodbatlas_api_key.this.api_key_id
41+
}
42+
```
43+
44+
<!-- schema generated by tfplugindocs -->
45+
## Schema
46+
47+
### Required
48+
49+
- `api_key_id` (String) Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
50+
- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.
51+
52+
**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
53+
54+
### Read-Only
55+
56+
- `roles` (Set of String) Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
57+
58+
For more information see: [MongoDB Atlas API - Programmatic API Keys Project Assignment](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-programmatic-api-keys) Documentation.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Data Source: mongodbatlas_api_key_project_assignments
2+
3+
`mongodbatlas_api_key_project_assignments` provides an API Key Project Assignments data source. The data source lets you list all API key project assignments for an organization.
4+
5+
## Example Usages
6+
7+
```terraform
8+
resource "mongodbatlas_api_key" "this" {
9+
org_id = var.org_id
10+
description = "Test API Key"
11+
role_names = ["ORG_READ_ONLY"]
12+
}
13+
14+
resource "mongodbatlas_project" "first_project" {
15+
name = "First Project"
16+
org_id = var.org_id
17+
}
18+
19+
resource "mongodbatlas_project" "second_project" {
20+
name = "Second Project"
21+
org_id = var.org_id
22+
}
23+
24+
resource "mongodbatlas_api_key_project_assignment" "first_assignment" {
25+
project_id = mongodbatlas_project.first_project.id
26+
api_key_id = mongodbatlas_api_key.this.api_key_id
27+
roles = ["GROUP_OWNER"]
28+
}
29+
30+
resource "mongodbatlas_api_key_project_assignment" "second_assignment" {
31+
project_id = mongodbatlas_project.second_project.id
32+
api_key_id = mongodbatlas_api_key.this.api_key_id
33+
roles = ["GROUP_OWNER"]
34+
}
35+
36+
# Add IP Access List Entry to Programmatic API Key
37+
resource "mongodbatlas_access_list_api_key" "this" {
38+
org_id = var.org_id
39+
cidr_block = "0.0.0.0/1"
40+
api_key_id = mongodbatlas_api_key.this.api_key_id
41+
}
42+
```
43+
44+
<!-- schema generated by tfplugindocs -->
45+
## Schema
46+
47+
### Required
48+
49+
- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.
50+
51+
**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
52+
53+
### Read-Only
54+
55+
- `results` (Attributes List) List of documents that MongoDB Cloud returns for this request. (see [below for nested schema](#nestedatt--results))
56+
57+
<a id="nestedatt--results"></a>
58+
### Nested Schema for `results`
59+
60+
Read-Only:
61+
62+
- `api_key_id` (String) Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
63+
- `project_id` (String) Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.
64+
65+
**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.
66+
- `roles` (Set of String) Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
67+
68+
For more information see: [MongoDB Atlas API - Programmatic API Keys Project Assignment](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-programmatic-api-keys) Documentation.

docs/data-sources/project_api_key.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
`mongodbatlas_project_api_key` describes a MongoDB Atlas Project API Key. This represents a Project API Key that has been created.
44

5+
~> **IMPORTANT NOTE** The use of `mongodbatlas_project_api_key` data source is no longer the recommended approach. For new configurations, we recommend using the `mongodbatlas_api_key` resource and the `mongodbatlas_api_key_project_assignment` resource to assign the API Keys to projects. This approach is more flexible and aligns with best practices. For existing configurations, the migration to the new pattern is **not required**. If you want to migrate, see the [Migration Guide](../guides/project-api-key-migration.md) for step-by-step instructions on migrating from `mongodbatlas_project_api_key` to the new pattern.
6+
57
~> **IMPORTANT WARNING:** Managing Atlas Programmatic API Keys (PAKs) with Terraform will expose sensitive organizational secrets in Terraform's state. We suggest following [Terraform's best practices](https://developer.hashicorp.com/terraform/language/state/sensitive-data). You may also want to consider managing your PAKs via a more secure method, such as the [HashiCorp Vault MongoDB Atlas Secrets Engine](https://developer.hashicorp.com/vault/docs/secrets/mongodbatlas).
68

79
-> **NOTE:** You may find project_id in the official documentation.

docs/data-sources/project_api_keys.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Data Source: mongodbatlas_api_keys
1+
# Data Source: mongodbatlas_project_api_keys
22

3-
`mongodbatlas_api_keys` describes all API Keys. This represents API Keys that have been created.
3+
`mongodbatlas_project_api_keys` describes all API Keys. This represents API Keys that have been created.
4+
5+
~> **IMPORTANT NOTE** The use of `mongodbatlas_project_api_keys` data source is no longer the recommended approach. For new configurations, we recommend using the `mongodbatlas_api_key` resource and the `mongodbatlas_api_key_project_assignment` resource to assign the API Keys to projects. This approach is more flexible and aligns with best practices. For existing configurations, the migration to the new pattern is **not required**. If you want to migrate, see the [Migration Guide](../guides/project-api-key-migration.md) for step-by-step instructions on migrating from `mongodbatlas_project_api_key` to the new pattern.
46

57
~> **IMPORTANT WARNING:** Managing Atlas Programmatic API Keys (PAKs) with Terraform will expose sensitive organizational secrets in Terraform's state. We suggest following [Terraform's best practices](https://developer.hashicorp.com/terraform/language/state/sensitive-data). You may also want to consider managing your PAKs via a more secure method, such as the [HashiCorp Vault MongoDB Atlas Secrets Engine](https://developer.hashicorp.com/vault/docs/secrets/mongodbatlas).
68

0 commit comments

Comments
 (0)