Skip to content

Commit 1d4cc6c

Browse files
doc: Add azure federated database instance example and docs (#3521)
* Add aws directory to federated database instance examples * Add azure cloud provider example to data federated instance resource * Modify minimal example and add README * Add documentation for azure cloud provider in federated database instances * Decrease mongodbatlas version provider for tests * Correct format * Add newline to example files * Add computed attributes on docs for azure cloud provider resouce * Update outdated provider source path for example * Fix indentation for attributes and add format to avoid spaces on field values * Address PR review comments for wording * Follow-up to correct wording on README example
1 parent c0c7cdb commit 1d4cc6c

File tree

14 files changed

+266
-17
lines changed

14 files changed

+266
-17
lines changed

docs/data-sources/federated_database_instance.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
```terraform
1212
data "mongodbatlas_federated_database_instance" "test" {
13-
project_id = "PROJECT ID"
13+
project_id = "<PROJECT_ID>"
1414
name = "TENANT NAME OF THE FEDERATED DATABASE INSTANCE"
1515
}
1616
```
@@ -19,8 +19,8 @@ data "mongodbatlas_federated_database_instance" "test" {
1919

2020
```terraform
2121
data "mongodbatlas_federated_database_instance" "test" {
22-
project_id = "PROJECT ID"
23-
name = "TENANT NAME OF THE FEDERATED DATABASE INSTANCE"
22+
project_id = "<PROJECT_ID>"
23+
name = "<TENANT_NAME_OF_THE_FEDERATED_DATABASE_INSTANCE>"
2424
cloud_provider_config {
2525
aws {
2626
test_s3_bucket = "Amazon S3 Bucket Name"
@@ -29,6 +29,20 @@ data "mongodbatlas_federated_database_instance" "test" {
2929
}
3030
```
3131

32+
## Example of Azure Blob Storage as storage database
33+
34+
```terraform
35+
data "mongodbatlas_federated_database_instance" "test" {
36+
project_id = "<PROJECT_ID>"
37+
name = "<TENANT_NAME_OF_THE_FEDERATED_DATABASE_INSTANCE>"
38+
cloud_provider_config {
39+
azure {
40+
role_id = "<AZURE_ROLE_ID>"
41+
}
42+
}
43+
}
44+
```
45+
3246
## Argument Reference
3347

3448
* `project_id` - (Required) The unique ID for the project to create a Federated Database Instance.
@@ -97,9 +111,15 @@ In addition to all arguments above, the following attributes are exported:
97111
* `iam_user_arn` - Amazon Resource Name (ARN) of the user that the Federated Database Instance assumes when accessing S3 Bucket data stores.
98112
* `external_id` - Unique identifier associated with the IAM Role that the Federated Database Instance assumes when accessing the data stores.
99113
* `role_id` - Unique identifier of the role that the data lake can use to access the data stores.
100-
### `data_process_region` - The cloud provider region to which the Federated Instance routes client connections for data processing.
101-
* `cloud_provider` - Name of the cloud service provider. Atlas Federated Database only supports AWS.
102-
* `region` - Name of the region to which the Federanted Instnace routes client connections for data processing.
103114

115+
#### `azure` - Microsoft Azure provider of the cloud service where the Federated Database Instance can access Blob Storage.
116+
* `atlas_azure_app_id` - Unique identifier of the Azure Active Directory application associated with the service principal.
117+
* `service_principal_id` - Unique identifier of the Azure service principal that the Federated Database instance uses to access Azure Blob Storage.
118+
* `tenant_id` - Unique identifier of the Azure Active Directory tenant where the service principal resides.
119+
* `role_id` - Unique identifier of the role that the Federated Database Instance can use to access the data stores.
120+
121+
### `data_process_region` - The cloud provider region to which the Federated Instance routes client connections for data processing.
122+
* `cloud_provider` - Name of the cloud service provider. Supported providers: `AWS`, `AZURE`.
123+
* `region` - Name of the region to which the Federated Instance routes client connections for data processing.
104124

105-
See [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation) Documentation for more information.
125+
To learn more, see the [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation) documentation.

docs/data-sources/federated_database_instances.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Data Source: mongodbatlas_federated_database_instances
22

3-
`mongodbatlas_federated_database_instancess` provides a Federated Database Instance data source.
3+
`mongodbatlas_federated_database_instances` provides a Federated Database Instance data source.
44

55
-> **NOTE:** Groups and projects are synonymous terms. You may find group_id in the official documentation.
66

@@ -87,8 +87,15 @@ In addition to all arguments above, the following attributes are exported:
8787
* `iam_user_arn` - Amazon Resource Name (ARN) of the user that the Federated Database Instance assumes when accessing S3 Bucket data stores.
8888
* `external_id` - Unique identifier associated with the IAM Role that the Federated Database Instance assumes when accessing the data stores.
8989
* `role_id` - Unique identifier of the role that the data lake can use to access the data stores.
90-
#### `data_process_region` - The cloud provider region to which the Federated Instance routes client connections for data processing.
91-
* `cloud_provider` - Name of the cloud service provider. Atlas Federated Database only supports AWS.
92-
* `region` - Name of the region to which the Federanted Instnace routes client connections for data processing.
90+
91+
#### `azure` - Azure provider of the cloud service where the Federated Database Instance can access Blob Storage.
92+
* `atlas_azure_app_id` - Unique identifier of the Azure Active Directory application associated with the service principal.
93+
* `service_principal_id` - Unique identifier of the Azure service principal that the Federated Database instance uses to access Azure Blob Storage.
94+
* `tenant_id` - Unique identifier of the Azure Active Directory tenant where the service principal resides.
95+
* `role_id` - Unique identifier of the role that the Federated Database Instance can use to access the data stores.
96+
97+
### `data_process_region` - The cloud provider region to which the Federated Instance routes client connections for data processing.
98+
* `cloud_provider` - Name of the cloud service provider. Supported providers: `AWS`, `AZURE`.
99+
* `region` - Name of the region to which the Federated Instance routes client connections for data processing.
93100

94101
See [MongoDB Atlas API](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation) Documentation for more information.

docs/resources/federated_database_instance.md

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,52 @@ resource "mongodbatlas_federated_database_instance" "test" {
8585
}
8686
```
8787

88+
## Example of Azure Blob Storage as storage database
89+
90+
```terraform
91+
resource "mongodbatlas_federated_database_instance" "test" {
92+
project_id = "<PROJECT_ID>"
93+
name = "<TENANT_NAME_OF_THE_FEDERATED DATABASE_INSTANCE>"
94+
95+
cloud_provider_config {
96+
azure {
97+
role_id = "<AZURE_ROLE_ID>"
98+
}
99+
}
100+
101+
storage_databases {
102+
name = "VirtualDatabase0"
103+
collections {
104+
name = "NAME OF THE COLLECTION"
105+
data_sources {
106+
collection = "COLLECTION IN THE CLUSTER"
107+
database = "DB IN THE CLUSTER"
108+
store_name = "CLUSTER NAME"
109+
}
110+
data_sources {
111+
store_name = "AZURE BLOB STORAGE NAME"
112+
path = "AZURE BLOB PATH"
113+
}
114+
}
115+
}
116+
117+
storage_stores {
118+
name = "STORE NAME"
119+
cluster_name = "CLUSTER NAME"
120+
project_id = "PROJECT ID"
121+
provider = "atlas"
122+
read_preference {
123+
mode = "secondary"
124+
}
125+
}
126+
127+
storage_stores {
128+
name = "AZURE BLOB STORAGE NAME"
129+
provider = "azure"
130+
}
131+
}
132+
```
133+
88134
## Example specifying data process region and provider
89135
```terraform
90136
resource "mongodbatlas_federated_database_instance" "test" {
@@ -103,12 +149,14 @@ resource "mongodbatlas_federated_database_instance" "test" {
103149
* `project_id` - (Required) The unique ID for the project to create a Federated Database Instance.
104150
* `name` - (Required) Name of the Atlas Federated Database Instance.
105151
* `cloud_provider_config` - (Optional) Cloud provider linked to this data federated instance.
106-
* `cloud_provider_config.aws` - (Required) AWS provider of the cloud service where the Federated Database Instance can access the S3 Bucket. Note this parameter is only required if using `cloud_provider_config` since AWS is currently the only supported Cloud vendor on this feature at this time.
152+
* `cloud_provider_config.aws` - AWS provider of the cloud service where the Federated Database Instance can access the S3 Bucket.
107153
* `cloud_provider_config.aws.role_id` - (Required) Unique identifier of the role that the Federated Instance can use to access the data stores. If necessary, use the Atlas [UI](https://docs.atlas.mongodb.com/security/manage-iam-roles/) or [API](https://docs.atlas.mongodb.com/reference/api/cloud-provider-access-get-roles/) to retrieve the role ID. You must also specify the `test_s3_bucket`.
108154
* `cloud_provider_config.aws.test_s3_bucket` - (Required) Name of the S3 data bucket that the provided role ID is authorized to access. You must also specify the `role_id`.
155+
* `cloud_provider_config.azure` - Microsoft Azure provider of the cloud service where the Federated Database Instance can access Blob Storage.
156+
* `cloud_provider_config.azure.role_id` - (Required) Unique identifier of the role that the Federated Database Instance can use to access the data stores.
109157
* `data_process_region` - (Optional) The cloud provider region to which the Federated Instance routes client connections for data processing.
110-
* `data_process_region.cloud_provider` - (Required) Name of the cloud service provider. Atlas Federated Database only supports AWS.
111-
* `data_process_region.region` - (Required) Name of the region to which the Federanted Instnace routes client connections for data processing. See the [documention](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation/operation/createFederatedDatabase) for the available region.
158+
* `data_process_region.cloud_provider` - (Required) Name of the cloud service provider. Supported providers: `AWS`, `AZURE`.
159+
* `data_process_region.region` - (Required) Name of the region to which the Federated Instance routes client connections for data processing. See the [documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Data-Federation/operation/createFederatedDatabase) for the available region.
112160
* `storage_databases` - Configuration details for mapping each data store to queryable databases and collections. For complete documentation on this object and its nested fields, see [databases](https://docs.mongodb.com/datalake/reference/format/data-lake-configuration#std-label-datalake-databases-reference). An empty object indicates that the Federated Database Instance has no mapping configuration for any data store.
113161
* `storage_databases.#.name` - Name of the database to which the Federated Database Instance maps the data contained in the data store.
114162
* `storage_databases.#.collections` - Array of objects where each object represents a collection and data sources that map to a [stores](https://docs.mongodb.com/datalake/reference/format/data-lake-configuration#mongodb-datalakeconf-datalakeconf.stores) data store.
@@ -167,10 +215,13 @@ In addition to all arguments above, the following attributes are exported:
167215
* `s3:GetObjectVersion`
168216

169217
For more information on S3 actions, see [Actions, Resources, and Condition Keys for Amazon S3](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html).
170-
* `iam_user_arn` - Amazon Resource Name (ARN) of the user that the Federated Database Instance assumes when accessing S3 Bucket data stores.
171-
* `external_id` - Unique identifier associated with the IAM Role that the Federated Database Instance assumes when accessing the data stores.
172-
218+
* `iam_user_arn` - Amazon Resource Name (ARN) of the user that the Federated Database Instance assumes when accessing S3 Bucket data stores.
219+
* `external_id` - Unique identifier associated with the IAM Role that the Federated Database Instance assumes when accessing the data stores.
173220

221+
* `cloud_provider_config.azure` - Microsoft Azure cloud service configuration.
222+
* `atlas_azure_app_id` - Unique identifier of the Azure Active Directory application associated with the service principal.
223+
* `service_principal_id` - Unique identifier of the Azure service principal that the Federated Database instance uses to access Azure Blob Storage.
224+
* `tenant_id` - Unique identifier of the Azure Active Directory tenant where the service principal resides.
174225

175226
## Import
176227

File renamed without changes.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Example - MongoDB Atlas Federated Database Instance with Microsoft Azure Blob Storage and MongoDB Cluster as storage databases
2+
3+
This project aims to provide an example of using [MongoDB Atlas Federated Database Instance](https://www.mongodb.com/docs/atlas/data-federation/overview/).
4+
5+
## Dependencies
6+
7+
* Terraform MongoDB Atlas Provider v1.39.0
8+
* A MongoDB Atlas account
9+
* An Azure account
10+
11+
```
12+
Terraform v1.39.0
13+
+ provider registry.terraform.io/mongodb/mongodbatlas v1.39.0
14+
```
15+
16+
## Usage
17+
18+
**1\. Set up your Azure credentials.**
19+
20+
1. Install the Azure CLI by following the steps from the [Azure documentation](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
21+
2. Run the command `az login`. This takes you to the default browser where you can authenticate with Azure.
22+
3. Once authenticated, it will print the user details as follows:
23+
24+
```
25+
⇒ az login
26+
You have logged in. Now let us find all the subscriptions to which you have access...
27+
The following tenants don't contain accessible subscriptions. Use 'az login --allow-no-subscriptions' to have tenant level access.
28+
XXXXX
29+
[
30+
{
31+
"cloudName": "AzureCloud",
32+
"homeTenantId": "XXXXX",
33+
"id": "XXXXX",
34+
"isDefault": true,
35+
"managedByTenants": [],
36+
"name": "Pay-As-You-Go",
37+
"state": "Enabled",
38+
"tenantId": "XXXXX",
39+
"user": {
40+
"name": "[email protected]",
41+
"type": "user"
42+
}
43+
}
44+
]
45+
```
46+
47+
**2\. Set up your MongoDB Atlas credentials.**
48+
49+
You can use environment variables to set up credentials for Atlas as follows:
50+
51+
```bash
52+
export MONGODB_ATLAS_PUBLIC_KEY="<ATLAS_PUBLIC_KEY>"
53+
export MONGODB_ATLAS_PRIVATE_KEY="<ATLAS_PRIVATE_KEY>"
54+
```
55+
56+
... or create a **terraform.tfvars** file with all variable values:
57+
58+
```terraform
59+
public_key = "<MONGODB_ATLAS_PUBLIC_KEY>"
60+
private_key = "<MONGODB_ATLAS_PRIVATE_KEY>"
61+
project_id = "<ATLAS_PROJECT_ID>"
62+
azure_atlas_app_id = "<AZURE_ATLAS_APP_ID>"
63+
azure_service_principal_id = "<AZURE_SERVICE_PRINCIPAL_ID>"
64+
azure_tenant_id = "<AZURE_TENANT_ID>"
65+
```
66+
67+
**3\. Review the Terraform plan.**
68+
69+
Run the following command and review the plan you created.
70+
71+
``` bash
72+
$ terraform plan
73+
```
74+
This project currently supports the following deployments:
75+
76+
- MongoDB Atlas Cloud Provider Access Setup for Azure
77+
- MongoDB Atlas Cloud Provider Access Authorization
78+
- MongoDB Atlas Federated Database Instance with Azure cloud provider configuration
79+
80+
**5\. Run the Terraform apply command to apply the plan.**
81+
82+
Now run the plan to provision the resources.
83+
84+
``` bash
85+
$ terraform apply
86+
```
87+
88+
**6\. Destroy the resources.**
89+
90+
Once you are finished with our testing, ensure you destroy the resources to avoid unnecessary Atlas charges.
91+
92+
``` bash
93+
$ terraform destroy
94+
```

0 commit comments

Comments
 (0)