Skip to content

Commit 4332e60

Browse files
feat: support for new mongodbatlas_atlas_user and mongodbatlas_atlas_users data sources (#1432)
* feat: support for new mongodbatlas_atlas_user and mongodbatlas_atlas_users data sources * remove fetching user before execution of tf acceptance test to avoid error when running ==> Checking that code complies with gofmt requirements... go test $(go list ./... | grep -v /integrationtesting) -timeout=30s -parallel=4 ? github.com/mongodb/terraform-provider-mongodbatlas [no test files] ? github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/conversion [no test files] ? github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/testutils [no test files] ? github.com/mongodb/terraform-provider-mongodbatlas/version [no test files] ok github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas 1.120s ok github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas/framework/validator (cached) * fix prechecks * verify values of user using result from external api call * avoid running test in parallel when doing checks over existing user * doc: add documentation and examples for both new atlas user data sources * addressing some PR comments * doc: addressing comments related to docs and examples * include fetching of users by org id to verify data source values in acceptance test * fix format in date-time attributes defined in atlas user data sources
1 parent 7de22b9 commit 4332e60

22 files changed

+1255
-3
lines changed

.github/workflows/acceptance-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
- 'mongodbatlas/data_source_mongodbatlas_organization*.go'
8787
- 'mongodbatlas/data_source_mongodbatlas_project_api_key*.go'
8888
- 'mongodbatlas/data_source_mongodbatlas_team*.go'
89+
- 'mongodbatlas/fw_data_source_mongodbatlas_atlas_user*.go'
8990
- 'mongodbatlas/data_source_mongodbatlas_third_party_integration*.go'
9091
- 'mongodbatlas/resource_mongodbatlas_api_key*.go'
9192
- 'mongodbatlas/fw_resource_mongodbatlas_alert_configuration*.go'
@@ -411,6 +412,7 @@ jobs:
411412
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.MONGODB_ATLAS_PRIVATE_KEY_CLOUD_DEV_NETWORK }}
412413
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV_NETWORK }}
413414
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
415+
MONGODB_ATLAS_PROJECT_OWNER_ID: ${{ vars.MONGODB_ATLAS_PROJECT_OWNER_ID }}
414416
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
415417
MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }}
416418
AZURE_ATLAS_APP_ID: ${{vars.AZURE_ATLAS_APP_ID}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Example - MongoDB Atlas User Data Source
2+
3+
This project provides a straight-forward example for using the Atlas User Data Source.
4+
5+
Variables Required to be set:
6+
- `public_key`: Atlas Programmatic API public key
7+
- `private_key`: Atlas Programmatic API private key
8+
- `user_id`: User ID of the Atlas User to return
9+
- `username`: Username of the Atlas User to return
10+
11+
12+
This example shows the two ways that you can use the data source, either providing the `user_id` or `username` attribute.
13+
14+
For additional documentation, see [MongoDB Atlas API - Get User By ID](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/MongoDB-Cloud-Users/operation/getUser) and [MongoDB Atlas API - Get User By Username](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/MongoDB-Cloud-Users/operation/getUserByUsername) respectively.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
data "mongodbatlas_atlas_user" "test_user_by_username" {
2+
username = var.username
3+
}
4+
5+
data "mongodbatlas_atlas_user" "test_user_by_id" {
6+
user_id = var.user_id
7+
}
8+
9+
# example making use of data sources
10+
output "user_firstname" {
11+
value = data.mongodbatlas_atlas_user.test_user_by_username.first_name
12+
}
13+
14+
output "user_lastname" {
15+
value = data.mongodbatlas_atlas_user.test_user_by_id.last_name
16+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
variable "public_key" {
2+
description = "Public API key to authenticate to Atlas"
3+
type = string
4+
}
5+
variable "private_key" {
6+
description = "Private API key to authenticate to Atlas"
7+
type = string
8+
}
9+
10+
variable "user_id" {
11+
description = "Atlas User ID"
12+
type = string
13+
}
14+
15+
variable "username" {
16+
description = "Atlas Username"
17+
type = string
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
version = "~> 1.12"
6+
}
7+
}
8+
required_version = ">= 1.0"
9+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Example - MongoDB Atlas Users Data Source
2+
3+
This project provides a straight-forward example for using the Atlas Users Data Source.
4+
5+
Variables Required to be set:
6+
- `public_key`: Atlas Programmatic API public key
7+
- `private_key`: Atlas Programmatic API private key
8+
- `org_id`: Org ID that identifies the organization whose users you want to return
9+
- `project_id`: Project ID that identifies the project whose users you want to return
10+
- `team_id`: Team ID that identifies the team whose users you want to return
11+
12+
The example demonstrates the three ways you can use this data source to obtain users from an Atlas organization, project, or team.
13+
14+
For additional documentation, see:
15+
16+
- For obtaining users of an Organization: [MongoDB Atlas API - List Organization Users](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Organizations/operation/listOrganizationUsers)
17+
- For obtaining users of a Project: [MongoDB Atlas API - List Project Users](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Projects/operation/listProjectUsers)
18+
- For obtaining users of a Team: [MongoDB Atlas API - List Team Users](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Teams/operation/listTeamUsers)
19+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
data "mongodbatlas_atlas_users" "test_org_users" {
2+
org_id = var.org_id
3+
}
4+
5+
data "mongodbatlas_atlas_users" "test_project_users" {
6+
project_id = var.project_id
7+
}
8+
9+
data "mongodbatlas_atlas_users" "test_team_users" {
10+
team_id = var.team_id
11+
org_id = var.org_id
12+
}
13+
14+
# example making use of data sources
15+
output "org_user_count" {
16+
value = data.mongodbatlas_atlas_users.test_org_users.total_count
17+
}
18+
19+
output "project_user_count" {
20+
value = data.mongodbatlas_atlas_users.test_project_users.total_count
21+
}
22+
23+
output "team_user_count" {
24+
value = data.mongodbatlas_atlas_users.test_team_users.total_count
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
variable "public_key" {
2+
description = "Public API key to authenticate to Atlas"
3+
type = string
4+
}
5+
variable "private_key" {
6+
description = "Private API key to authenticate to Atlas"
7+
type = string
8+
}
9+
variable "org_id" {
10+
description = "Atlas Organization ID"
11+
type = string
12+
}
13+
14+
variable "project_id" {
15+
description = "Atlas Project ID"
16+
type = string
17+
}
18+
19+
variable "team_id" {
20+
description = "Atlas Team ID"
21+
type = string
22+
}

0 commit comments

Comments
 (0)