Skip to content

Commit dc5ebe3

Browse files
martinstibbeZuhairahmedthemantissa
authored
INTMDB-533: Feature Add: Programmatically Create Organizations (#1176)
* Initial version * Acceptance testing issue for org creation * Add initial examples of org creation * skip tests for moment on organization resource * Add documentation * typo * terraform fmt * lint * go mod tidy * Documentation updates PR feedback * update TF version * Update variables.tf * Add additional Readme to show how to apply 2 step example * Update docs * Update examples/atlas-organization/Readme.md Co-authored-by: Zuhair Ahmed <[email protected]> * Update examples/atlas-organization/Readme.md * Update examples/atlas-organization/organization-step-1/Readme.md * Update examples/atlas-organization/organization-step-2/Readme.md Co-authored-by: Melissa Plunkett <[email protected]> * Update website/docs/r/organization.html.markdown * Update website/docs/d/organizations.html.markdown * Update go SDK add Org Update * Fix broken tests * Add isDeleted * Update go.sum --------- Co-authored-by: Zuhair Ahmed <[email protected]> Co-authored-by: Melissa Plunkett <[email protected]>
1 parent f14eb01 commit dc5ebe3

23 files changed

+1167
-3
lines changed

examples/atlas-organization/Readme.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
2+
# Example - A basic example to create and Orgnization with MongoDB Atlas and Terraform
3+
4+
This project aims to provide a very straight-forward example of setting up a MongoDB Atlas Organization with Terraform. This will create the following resources in MongoDB Atlas:
5+
6+
- MongoDB Atlas organization
7+
- Private Key
8+
- Public Key
9+
- Organization ID
10+
- MongoDB Atlas Project
11+
12+
## Dependencies
13+
14+
* Terraform v0.15 or greater
15+
* A MongoDB Atlas account
16+
* provider.mongodbatlas: version = "~> 1.10.0"
17+
* [Cross-organization billing](https://www.mongodb.com/docs/atlas/billing/#cross-organization-billing) enabled and the requesting API Key's organization must be a paying organization.
18+
* Some users (see [here](https://github.com/mongodb/terraform-provider-mongodbatlas/issues/1083)) have reported issues deploying this starter example with Mac M1 CPU. you encounter this issue, try deploying instead on x86 linux if possible. See list of supported binaries [here](https://github.com/mongodb/terraform-provider-mongodbatlas/releases/tag/v1.8.1)
19+
20+
## Usage
21+
**1\. change working directry to folder organization-step-1.**
22+
23+
**2\. Ensure your MongoDB Atlas credentials are set up.**
24+
25+
This can be done using environment variables:
26+
27+
```bash
28+
export MONGODB_ATLAS_PUBLIC_KEY="xxxx"
29+
export MONGODB_ATLAS_PRIVATE_KEY="xxxx"
30+
```
31+
32+
... or utilize the `variables.tf` file and create **terraform.tfvars** file with all the variable values and make sure **not to commit it**.
33+
34+
35+
> **IMPORTANT** Hard-coding your MongoDB Atlas programmatic API key pair into a Terraform configuration is not recommended. Consider the risks, especially the inadvertent submission of a configuration file containing secrets to a public repository.
36+
37+
38+
**3\. Review the Terraform plan.**
39+
40+
Execute the below command and ensure you are happy with the plan.
41+
42+
``` bash
43+
$ terraform plan
44+
```
45+
46+
This example currently creates the following:
47+
48+
- Atlas organization
49+
- Private Key
50+
- Public Key
51+
- Organization ID
52+
53+
**4\. Execute the Terraform apply.**
54+
55+
Now execute the plan to provision the MongoDB Atlas resources.
56+
57+
``` bash
58+
$ terraform apply
59+
```
60+
61+
**Output:**
62+
63+
mongodbatlas_organization.test: Creating...
64+
mongodbatlas_organization.test: Creation complete after 1s [id=b3fff2lk:NjffffyMmE2M2fffffffOTkwM2I0]
65+
66+
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
67+
68+
Outputs:
69+
70+
org_id = "647ffffffe9903b4"
71+
org_private_key = "a6300e-ffffffff-8c1168f0"
72+
org_public_key = "yqffje"
73+
74+
**5\. Retain values for org_private_key and org_public_key for next stage of example as new API key has access to create resources in new organization.**
75+
76+
**6\. change working directry to folder organization-step-2.**
77+
78+
**7\. Ensure your MongoDB Atlas credentials are set up to use new public and private key.**
79+
80+
This can be done using environment variables:
81+
82+
```bash
83+
export MONGODB_ATLAS_PUBLIC_KEY="xxxx"
84+
export MONGODB_ATLAS_PRIVATE_KEY="xxxx"
85+
```
86+
87+
... or utilize the `variables.tf` file and create **terraform.tfvars** file with all the variable values and make sure **not to commit it**.
88+
89+
90+
> **IMPORTANT** Hard-coding your MongoDB Atlas programmatic API key pair into a Terraform configuration is not recommended. Consider the risks, especially the inadvertent submission of a configuration file containing secrets to a public repository.
91+
92+
93+
**8\. Review the Terraform plan.**
94+
95+
Execute the below command and ensure you are happy with the plan.
96+
97+
``` bash
98+
$ terraform plan
99+
```
100+
101+
This example currently creates the following:
102+
103+
- Atlas Project
104+
105+
**9\. Execute the Terraform apply.**
106+
107+
Now execute the plan to provision the MongoDB Atlas resources.
108+
109+
``` bash
110+
$ terraform apply
111+
```
112+
mongodbatlas_project.project: Creating...
113+
mongodbatlas_project.project: Creation complete after 4s [id=647fe6baffffffdcaee72]
114+
115+
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
116+
117+
Outputs:
118+
119+
project_name = "testnew"
120+
121+
**9\. Destroy the resources.**
122+
123+
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary charges.
124+
125+
``` bash
126+
$ terraform destroy
127+
```
128+
129+
130+
**Output:**
131+
- project_name = "testnew" -> null
132+
133+
Do you really want to destroy all resources?
134+
Terraform will destroy all your managed infrastructure, as shown above.
135+
There is no undo. Only 'yes' will be accepted to confirm.
136+
137+
Enter a value: yes
138+
139+
mongodbatlas_project.project: Destroying... [id=647fe6ba6fc6fc0efdcaee72]
140+
mongodbatlas_project.project: Destruction complete after 0s
141+
142+
Destroy complete! Resources: 1 destroyed.
143+
144+
cd ../organization-step-1
145+
146+
``` bash
147+
$ terraform destroy
148+
```
149+
150+
151+
mongodbatlas_organization.test: Destroying... [id=b3JnX2lk:NjQ3ZfffffNWU2NzNlOTkwM2I0]
152+
mongodbatlas_organization.test: Destruction complete after 9s
153+
154+
Destroy complete! Resources: 1 destroyed.
155+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Example - A basic example to create a MongoDB Atlas Organization with Terraform
2+
3+
This project aims to provide a very straight-forward example of setting up a MongoDB Atlas Organization with Terraform. This will create the following resources in MongoDB Atlas:
4+
5+
- Atlas organization
6+
- Private Key
7+
- Public Key
8+
- Organization ID
9+
10+
## Dependencies
11+
12+
* Terraform v0.15 or greater
13+
* A MongoDB Atlas account
14+
* provider.mongodbatlas: version = "~> 1.10.0"
15+
* [Cross-organization billing](https://www.mongodb.com/docs/atlas/billing/#cross-organization-billing) enabled and the requesting API Key's organization must be a paying organization.
16+
* Some users (see [here](https://github.com/mongodb/terraform-provider-mongodbatlas/issues/1083)) have reported issues deploying this starter example with Mac M1 CPU. you encounter this issue, try deploying instead on x86 linux if possible. See list of supported binaries [here](https://github.com/mongodb/terraform-provider-mongodbatlas/releases/tag/v1.8.1)
17+
18+
## Usage
19+
20+
**1\. Ensure your MongoDB Atlas credentials are set up.**
21+
22+
This can be done using environment variables:
23+
24+
```bash
25+
export MONGODB_ATLAS_PUBLIC_KEY="xxxx"
26+
export MONGODB_ATLAS_PRIVATE_KEY="xxxx"
27+
```
28+
29+
... or utilize the `variables.tf` file and create **terraform.tfvars** file with all the variable values and make sure **not to commit it**.
30+
31+
32+
> **IMPORTANT** Hard-coding your MongoDB Atlas programmatic API key pair into a Terraform configuration is not recommended. Consider the risks, especially the inadvertent submission of a configuration file containing secrets to a public repository.
33+
34+
35+
**2\. Review the Terraform plan.**
36+
37+
Execute the below command and ensure you are happy with the plan.
38+
39+
``` bash
40+
$ terraform plan
41+
```
42+
43+
This example currently creates the following:
44+
45+
- Atlas organization
46+
- Private Key
47+
- Public Key
48+
- Organization ID
49+
50+
**3\. Execute the Terraform apply.**
51+
52+
Now execute the plan to provision the MongoDB Atlas resources.
53+
54+
``` bash
55+
$ terraform apply
56+
```
57+
58+
**4\. Destroy the resources.**
59+
60+
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary charges.
61+
62+
``` bash
63+
$ terraform destroy
64+
```
65+
66+
**Output:**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "mongodbatlas_organization" "test" {
2+
org_owner_id = var.org_owner_id
3+
name = "testCreateORG"
4+
description = "test API key from Org Creation Test"
5+
role_names = ["ORG_OWNER"]
6+
}
7+
8+
output "org_id" {
9+
value = mongodbatlas_organization.test.org_id
10+
}
11+
12+
output "org_public_key" {
13+
value = nonsensitive(mongodbatlas_organization.test.public_key)
14+
}
15+
16+
output "org_private_key" {
17+
value = nonsensitive(mongodbatlas_organization.test.private_key)
18+
}
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
variable "public_key" {
2+
type = string
3+
description = "Public Programmatic API key to authenticate to Atlas"
4+
}
5+
variable "private_key" {
6+
type = string
7+
description = "Private Programmatic API key to authenticate to Atlas"
8+
}
9+
variable "org_owner_id" {
10+
type = string
11+
description = "MongoDB Organization Owner ID"
12+
}
13+
14+
15+
16+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
}
6+
}
7+
required_version = ">= 0.13"
8+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Example - A basic example to start with the MongoDB Atlas and Terraform
2+
3+
This project aims to provide a very straight-forward example of setting up Terraform with MongoDB Atlas. This will create the following resources in MongoDB Atlas:
4+
5+
- Atlas Project
6+
7+
## Dependencies
8+
9+
* Terraform v0.15 or greater
10+
* A MongoDB Atlas account
11+
* provider.mongodbatlas: version = "~> 1.10.0"
12+
* Some users (see [here](https://github.com/mongodb/terraform-provider-mongodbatlas/issues/1083)) have reported issues deploying this starter example with Mac M1 CPU. you encounter this issue, try deploying instead on x86 linux if possible. See list of supported binaries [here](https://github.com/mongodb/terraform-provider-mongodbatlas/releases/tag/v1.8.1)
13+
14+
## Usage
15+
16+
**1\. Ensure your MongoDB Atlas credentials are set up.**
17+
18+
This can be done using environment variables:
19+
20+
```bash
21+
export MONGODB_ATLAS_PUBLIC_KEY="xxxx"
22+
export MONGODB_ATLAS_PRIVATE_KEY="xxxx"
23+
```
24+
25+
... or utilize the `variables.tf` file and create **terraform.tfvars** file with all the variable values and make sure **not to commit it**.
26+
27+
28+
> **IMPORTANT** Hard-coding your MongoDB Atlas programmatic API key pair into a Terraform configuration is not recommended. Consider the risks, especially the inadvertent submission of a configuration file containing secrets to a public repository.
29+
30+
31+
**2\. Review the Terraform plan.**
32+
33+
Execute the below command and ensure you are happy with the plan.
34+
35+
``` bash
36+
$ terraform plan
37+
```
38+
39+
This project currently creates the below deployments:
40+
41+
- Atlas Project
42+
43+
**3\. Execute the Terraform apply.**
44+
45+
Now execute the plan to provision the MongoDB Atlas resources.
46+
47+
``` bash
48+
$ terraform apply
49+
```
50+
51+
**4\. Destroy the resources.**
52+
53+
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary charges.
54+
55+
``` bash
56+
$ terraform destroy
57+
```
58+
59+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
resource "mongodbatlas_project" "project" {
2+
name = var.project_name
3+
org_id = var.org_id
4+
}
5+
output "project_name" {
6+
value = mongodbatlas_project.project.name
7+
}
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "public_key" {
2+
type = string
3+
description = "Public Programmatic API key to authenticate to Atlas"
4+
}
5+
variable "private_key" {
6+
type = string
7+
description = "Private Programmatic API key to authenticate to Atlas"
8+
}
9+
variable "org_id" {
10+
type = string
11+
description = "MongoDB Organization ID"
12+
}
13+
variable "project_name" {
14+
type = string
15+
description = "The MongoDB Atlas Project Name"
16+
}
17+
18+
19+
20+
21+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
required_providers {
3+
mongodbatlas = {
4+
source = "mongodb/mongodbatlas"
5+
}
6+
}
7+
required_version = ">= 0.13"
8+
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ require (
9191
github.com/modern-go/reflect2 v1.0.2 // indirect
9292
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
9393
github.com/oklog/run v1.0.0 // indirect
94-
github.com/openlyinc/pointy v1.2.0 // indirect
9594
github.com/pmezard/go-difflib v1.0.0 // indirect
9695
github.com/pquerna/otp v1.3.0 // indirect
9796
github.com/russross/blackfriday/v2 v2.1.0 // indirect

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,9 +555,8 @@ github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
555555
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
556556
github.com/onsi/ginkgo/v2 v2.9.1 h1:zie5Ly042PD3bsCvsSOPvRnFwyo3rKe64TJlD6nu0mk=
557557
github.com/onsi/gomega v1.27.4 h1:Z2AnStgsdSayCMDiCU42qIz+HLqEPcgiOCXjAU/w+8E=
558+
github.com/openlyinc/pointy v1.1.2 h1:LywVV2BWC5Sp5v7FoP4bUD+2Yn5k0VNeRbU5vq9jUMY=
558559
github.com/openlyinc/pointy v1.1.2/go.mod h1:w2Sytx+0FVuMKn37xpXIAyBNhFNBIJGR/v2m7ik1WtM=
559-
github.com/openlyinc/pointy v1.2.0 h1:vbb/WoPbshyTH8j3/XYu3enlZfv+NHxAD15qTm1zbk0=
560-
github.com/openlyinc/pointy v1.2.0/go.mod h1:JodZOTJoBNaAQHeU0F/SwA4PL0lg4pKF7fYFpX291P0=
561560
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
562561
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
563562
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)