Skip to content

Commit 10685b5

Browse files
feat: [Terraform] Parameter Add: Cloud Provider Access for Azure (#1343)
1 parent d7bb3be commit 10685b5

26 files changed

+841
-415
lines changed

.github/workflows/acceptance-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ jobs:
385385
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
386386
SKIP_TEST_EXTERNAL_CREDENTIALS: ${{ vars.SKIP_TEST_EXTERNAL_CREDENTIALS }}
387387
MONGODB_ATLAS_USERNAME_CLOUD_DEV: ${{ vars.MONGODB_ATLAS_USERNAME_CLOUD_DEV }}
388+
AZURE_ATLAS_APP_ID: ${{vars.AZURE_ATLAS_APP_ID}}
389+
AZURE_SERVICE_PRINCIPAL_ID: ${{vars.AZURE_SERVICE_PRINCIPAL_ID}}
390+
AZURE_TENANT_ID: ${{vars.AZURE_TENANT_ID}}
388391
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
389392
TF_LOG: ${{ vars.LOG_LEVEL }}
390393
TF_ACC: 1
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# MongoDB Atlas Provider -- Cloud Provider Access Role with AWS
2+
This example shows how to perform authorization for a cloud provider AWS role.
3+
4+
## Dependencies
5+
6+
* Terraform MongoDB Atlas Provider v1.10.0
7+
* A MongoDB Atlas account
8+
* An AWS account
9+
10+
11+
```
12+
Terraform v1.5.2
13+
+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.10.0
14+
```
15+
16+
## Usage
17+
18+
**1\. Ensure your AWS and MongoDB Atlas credentials are set up.**
19+
20+
This can be done using environment variables:
21+
22+
```bash
23+
export MONGODB_ATLAS_PUBLIC_KEY="xxxx"
24+
export MONGODB_ATLAS_PRIVATE_KEY="xxxx"
25+
```
26+
27+
``` bash
28+
$ export AWS_SECRET_ACCESS_KEY='your secret key'
29+
$ export AWS_ACCESS_KEY_ID='your key id'
30+
```
31+
32+
... or the `~/.aws/credentials` file.
33+
34+
```
35+
$ cat ~/.aws/credentials
36+
[default]
37+
aws_access_key_id = your key id
38+
aws_secret_access_key = your secret key
39+
```
40+
... or follow as in the `variables.tf` file and create **terraform.tfvars** file with all the variable values, ex:
41+
```
42+
access_key = "<AWS_ACCESS_KEY_ID>"
43+
secret_key = "<AWS_SECRET_ACCESS_KEY>"
44+
public_key = "<MONGODB_ATLAS_PUBLIC_KEY>"
45+
private_key = "<MONGODB_ATLAS_PRIVATE_KEY>"
46+
```
47+
48+
**2\. Review the Terraform plan.**
49+
50+
Execute the below command and ensure you are happy with the plan.
51+
52+
``` bash
53+
$ terraform plan
54+
```
55+
This project currently supports the below deployments:
56+
57+
- An AWS Policy
58+
- An AWS Role
59+
- Confiture Atlas to use your AWS Role
60+
61+
**3\. Execute the Terraform apply.**
62+
63+
Now execute the plan to provision the resources.
64+
65+
``` bash
66+
$ terraform apply
67+
```
68+
69+
**4\. Destroy the resources.**
70+
71+
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary Atlas charges.
72+
73+
``` bash
74+
$ terraform destroy
75+
```
76+

examples/atlas-cloud-provider-access/aws/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ terraform {
22
required_providers {
33
mongodbatlas = {
44
source = "mongodb/mongodbatlas"
5-
version = "~> 1.0"
5+
version = "~> 1.10.0"
66
}
77
aws = {
88
source = "hashicorp/aws"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# MongoDB Atlas Provider -- Cloud Provider Access Role with AZURE
2+
This example shows how to perform authorization for a cloud provider Azure Service Principal.
3+
4+
## Dependencies
5+
6+
* Terraform MongoDB Atlas Provider v1.11.0
7+
* A MongoDB Atlas account
8+
* An AZURE account
9+
10+
11+
```
12+
Terraform v1.5.2
13+
+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.11.0
14+
```
15+
16+
## Usage
17+
18+
**1\. Ensure your Azure credentials are set up.**
19+
20+
1. Install the Azure CLI by following the steps from the [official Azure documentation](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
21+
2. Run the command `az login` and this will take you to the default browser and perform the authentication.
22+
3. Once authenticated, it will print the user details as below:
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\. Ensure your MongoDB Atlas credentials are set up.**
48+
49+
This can be done using environment variables:
50+
51+
```bash
52+
export MONGODB_ATLAS_PUBLIC_KEY="xxxx"
53+
export MONGODB_ATLAS_PRIVATE_KEY="xxxx"
54+
```
55+
56+
... or follow as in the `variables.tf` file and create **terraform.tfvars** file with all the variable values, ex:
57+
```terraform
58+
public_key = "<MONGODB_ATLAS_PUBLIC_KEY>"
59+
private_key = "<MONGODB_ATLAS_PRIVATE_KEY>"
60+
```
61+
62+
**3\. Review the Terraform plan.**
63+
64+
Execute the below command and ensure you are happy with the plan.
65+
66+
``` bash
67+
$ terraform plan
68+
```
69+
This project currently supports the below deployments:
70+
71+
- An Azure Service Principal
72+
- Confiture Atlas to use your Azure Service Principal
73+
74+
**5\. Execute the Terraform apply.**
75+
76+
Now execute the plan to provision the resources.
77+
78+
``` bash
79+
$ terraform apply
80+
```
81+
82+
**6\. Destroy the resources.**
83+
84+
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary Atlas charges.
85+
86+
``` bash
87+
$ terraform destroy
88+
```
89+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Use the following block to create the Service Principal
2+
resource "azuread_service_principal" "example" {
3+
application_id = var.atlas_azure_app_id
4+
app_role_assignment_required = false
5+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
resource "mongodbatlas_cloud_provider_access_setup" "setup_only" {
2+
project_id = var.project_id
3+
provider_name = var.cloud_provider_access_name
4+
azure_config {
5+
atlas_azure_app_id = var.atlas_azure_app_id
6+
service_principal_id = azuread_service_principal.example.object_id
7+
tenant_id = var.azure_tenant_id
8+
}
9+
10+
}
11+
12+
resource "mongodbatlas_cloud_provider_access_authorization" "auth_role" {
13+
project_id = var.project_id
14+
role_id = mongodbatlas_cloud_provider_access_setup.setup_only.role_id
15+
16+
azure {
17+
atlas_azure_app_id = var.atlas_azure_app_id
18+
service_principal_id = azuread_service_principal.example.object_id
19+
tenant_id = var.azure_tenant_id
20+
}
21+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
provider "mongodbatlas" {
2+
public_key = var.public_key
3+
private_key = var.private_key
4+
}
5+
provider "azuread" {
6+
tenant_id = var.azure_tenant_id
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# mongo
2+
variable "project_id" {
3+
type = string
4+
}
5+
variable "cloud_provider_access_name" {
6+
type = string
7+
default = "AZURE"
8+
}
9+
variable "public_key" {
10+
type = string
11+
}
12+
variable "private_key" {
13+
type = string
14+
}
15+
16+
variable "azure_tenant_id" {
17+
type = string
18+
}
19+
20+
variable "atlas_azure_app_id" {
21+
type = string
22+
}
23+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
version = "~> 1.11.0"
6+
}
7+
azuread = {
8+
source = "hashicorp/azuread"
9+
version = "~> 2.15.0"
10+
}
11+
}
12+
required_version = ">= 0.13"
13+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/mwielbut/pointy v1.1.0
1515
github.com/spf13/cast v1.5.1
1616
github.com/zclconf/go-cty v1.13.2
17-
go.mongodb.org/atlas v0.31.0
17+
go.mongodb.org/atlas v0.32.0
1818
go.mongodb.org/atlas-sdk/v20230201002 v20230201002.0.0
1919
go.mongodb.org/realm v0.1.0
2020
golang.org/x/exp v0.0.0-20221208152030-732eee02a75a

0 commit comments

Comments
 (0)