-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTMDB-454: New Data Source to GET Org Id (#973)
* Add support for mongodbatlas_roles_org_id * Add Documentation for roles_org_id * Update go library * Add mongodbatlas_roles_org_id to datasource and resource to provide org_id * doc clean up / link to new API docs * formatting fix + update links to new API docs * formatting + update link to new API docs * formatting Co-authored-by: Zuhair Ahmed <[email protected]>
- Loading branch information
1 parent
c78a274
commit e14172c
Showing
9 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
matlas "go.mongodb.org/atlas/mongodbatlas" | ||
) | ||
|
||
func dataSourceMongoDBAtlasOrgID() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMongoDBAtlasOrgIDRead, | ||
Schema: map[string]*schema.Schema{ | ||
"org_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMongoDBAtlasOrgIDRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
// Get client connection. | ||
conn := meta.(*MongoDBClient).Atlas | ||
|
||
var ( | ||
err error | ||
root *matlas.Root | ||
) | ||
|
||
options := &matlas.ListOptions{} | ||
apiKeyOrgList, _, err := conn.Root.List(ctx, options) | ||
if err != nil { | ||
return diag.Errorf("error getting API Key's org assigned (%s): ", err) | ||
} | ||
|
||
if err := d.Set("org_id", apiKeyOrgList.APIKey.Roles[0].OrgID); err != nil { | ||
return diag.Errorf(errorProjectSetting, `org_id`, root.APIKey.ID, err) | ||
} | ||
|
||
for _, role := range apiKeyOrgList.APIKey.Roles { | ||
if strings.HasPrefix(role.RoleName, "ORG_") { | ||
d.SetId(apiKeyOrgList.APIKey.Roles[0].OrgID) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccConfigDSOrgID_basic(t *testing.T) { | ||
var ( | ||
dataSourceName = "data.mongodbatlas_roles_org_id.test" | ||
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID") | ||
name = fmt.Sprintf("test-acc-%[email protected]", acctest.RandString(10)) | ||
initialRole = []string{"ORG_OWNER"} | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testAccCheckMongoDBAtlasOrgInvitationDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceMongoDBAtlasOrgIDConfig(orgID, name, initialRole), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "org_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceMongoDBAtlasOrgIDConfig(orgID, username string, roles []string) string { | ||
return (` | ||
data "mongodbatlas_roles_org_id" "test" { | ||
} | ||
output "org_id" { | ||
value = data.mongodbatlas_roles_org_id.test.org_id | ||
}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
layout: "mongodbatlas" | ||
page_title: "MongoDB Atlas: roles_org_id" | ||
sidebar_current: "docs-mongodbatlas-datasource-roles-org-id" | ||
description: |- | ||
Describes a Roles Org ID. | ||
--- | ||
|
||
# Data Source: mongodbatlas_project | ||
|
||
`mongodbatlas_project` describes a MongoDB Atlas Roles Org ID. This represents a Roles Org ID. | ||
|
||
## Example Usage | ||
|
||
### Using project_id attribute to query | ||
```terraform | ||
data "mongodbatlas_roles_org_id" "test" { | ||
} | ||
output "org_id" { | ||
value = data.mongodbatlas_roles_org_id.test.org_id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* No parameters required | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `org_id` - The ID of the organization you want to retrieve associated to an API Key. | ||
|
||
See [MongoDB Atlas API - Role Org ID](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Root/operation/getSystemStatus) - Documentation for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters