-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
INTMDB-301: Feature add: Add support for managment of federated authe…
…ntication configuration (#742) * Add support for federated settings * Refactor for service pattern change * Refactor options and plural singular names * Update go SDK version * Add initial federated website docs * Provide examples for Federated settings * Sync go.mod to contain breaking change SDK change * Fix examples for lint error sync SDK to master * Add menu items for federation settings and upgrade guides * Remove Federated Docs from PR * PR Review updates * Add support for datasource tests * Fix lint fmt * Add identity_provider_id variable * Move identity_provider_id * Add role mappings datasource test * Add additional tests for federated resources * Lint check * Add additional datasources and tests * Remove unused function * Add support for role mappings and update tests and examples * Fix role mapping import to fit new style of parameters * Remove commented code * go mod tidy * Remove extra parameter user_conflicts * Add missing parameters and refactor name of variables * Update example * Update mongodbatlas/resource_mongodbatlas_federated_settings_identity_provider.go Co-authored-by: Andrea Angiolillo <[email protected]> * go fmt * Add support for import tests * Add federated settings env variables to README remove upgrade guide * Remove cloud prefix from federated examples and resources idp_id to okta_idp_id * Add new sort to role mapping * Add README for federated example * Refactor alias mongodbatlas to matlas dead code removal import spaces Co-authored-by: Andrea Angiolillo <[email protected]>
- Loading branch information
1 parent
0f04f70
commit 67ac9e8
Showing
30 changed files
with
3,261 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Example - Okta and MongoDB Atlas Federated Settings Configuration | ||
|
||
This project aims to provide an example of using Okta and MongoDB Atlas together. | ||
|
||
|
||
## Dependencies | ||
|
||
* Terraform v0.13 | ||
* Okta account | ||
* A MongoDB Atlas account | ||
|
||
``` | ||
Terraform v0.13.0 | ||
+ provider registry.terraform.io/terraform-providers/mongodbatlas v1.4.0 | ||
``` | ||
|
||
## Usage | ||
|
||
**1\. Ensure your Okta/Mongodb Atlas Federal settings configuration is set up to have a working set of organizations, verified domains, and identity providers.** | ||
|
||
**2\. TFVARS** | ||
|
||
Now create **terraform.tfvars** file with all the variable values and make sure **not to commit it**. | ||
|
||
**3\. Review the Terraform plan. ** | ||
|
||
Execute the below command and ensure you are happy with the plan. | ||
|
||
``` bash | ||
$ terraform plan | ||
``` | ||
This project currently does the below deployments: | ||
|
||
- MongoDB Atlas Federated Settings Organizational Role Mapping | ||
- MongoDB Atlas Federated Settings Organizational Identity Provider | ||
- MongoDB Atlas Federated Settings Organizational configuration | ||
|
||
**4\. Execute the Terraform import for 2 resources that do not support create.** | ||
``` bash | ||
$ terraform import mongodbatlas_federated_settings_identity_provider.identity_provider 6287a67f7f7f7f7f441c6c-0oad7f7f7f7fk1297 | ||
terraform import mongodbatlas_federated_settings_org_config.org_connections_import 6287a67f7f7f7f7f441c6c-627a96837f7f7f7f7e306f14 | ||
|
||
``` | ||
|
||
**5\. Execute the Terraform apply.** | ||
|
||
Now execute the plan to provision the Federated settings resources. | ||
|
||
``` bash | ||
$ terraform apply | ||
``` | ||
|
||
**6\. Destroy the resources.** | ||
|
||
Once you are finished your testing, ensure you destroy the resources to avoid unnecessary Atlas charges. | ||
|
||
``` bash | ||
$ terraform destroy | ||
``` |
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,50 @@ | ||
data "mongodbatlas_federated_settings" "federated_settings" { | ||
org_id = var.org_id | ||
} | ||
data "mongodbatlas_federated_settings_identity_providers" "identity_provider" { | ||
federation_settings_id = data.mongodbatlas_federated_settings.federated_settings.id | ||
} | ||
|
||
data "mongodbatlas_federated_settings_org_configs" "org_configs_ds" { | ||
federation_settings_id = data.mongodbatlas_federated_settings.federated_settings.id | ||
} | ||
|
||
data "mongodbatlas_federated_settings_org_role_mappings" "org_role_mapping" { | ||
federation_settings_id = data.mongodbatlas_federated_settings.federated_settings.id | ||
org_id = var.org_id | ||
} | ||
resource "mongodbatlas_federated_settings_org_role_mapping" "org_role_mapping" { | ||
federation_settings_id = data.mongodbatlas_federated_settings.federated_settings.id | ||
org_id = var.org_id | ||
external_group_name = "newgroup" | ||
|
||
role_assignments { | ||
group_id = var.group_id | ||
roles = ["GROUP_OWNER", "GROUP_DATA_ACCESS_ADMIN", "GROUP_SEARCH_INDEX_EDITOR", "GROUP_DATA_ACCESS_READ_ONLY"] | ||
} | ||
|
||
role_assignments { | ||
org_id = var.org_id | ||
roles = ["ORG_OWNER", "ORG_MEMBER"] | ||
} | ||
|
||
} | ||
resource "mongodbatlas_federated_settings_org_config" "org_connections_import" { | ||
federation_settings_id = data.mongodbatlas_federated_settings.federated_settings.id | ||
org_id = var.org_id | ||
identity_provider_id = var.identity_provider_id | ||
domain_restriction_enabled = false | ||
domain_allow_list = ["yourdomain.com"] | ||
} | ||
|
||
resource "mongodbatlas_federated_settings_identity_provider" "identity_provider" { | ||
federation_settings_id = data.mongodbatlas_federated_settings.federated_settings.id | ||
name = var.name | ||
associated_domains = ["yourdomain.com"] | ||
sso_debug_enabled = true | ||
status = "ACTIVE" | ||
sso_url = "https://mysso.oktapreview.com/app/mysso_terrafssotesdev_1/exk1f7f7f7fk5wp50h8/sso/saml" | ||
issuer_uri = "http://www.okta.com/exk1f716hf7f750h8" | ||
request_binding = "HTTP-POST" | ||
response_signature_algorithm = "SHA-256" | ||
} |
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,15 @@ | ||
output "federated_settings_ds" { | ||
value = data.mongodbatlas_federated_settings.federated_settings.id | ||
} | ||
|
||
output "identity_provider" { | ||
value = data.mongodbatlas_federated_settings_identity_providers.identity_provider.id | ||
} | ||
|
||
output "org_configs_ds" { | ||
value = data.mongodbatlas_federated_settings_org_configs.org_configs_ds.id | ||
} | ||
|
||
output "org_role_mapping" { | ||
value = data.mongodbatlas_federated_settings_org_role_mappings.org_role_mapping.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
provider "mongodbatlas" { | ||
public_key = var.public_key | ||
private_key = var.private_key | ||
} |
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,28 @@ | ||
variable "public_key" { | ||
type = string | ||
description = "Public Programmatic API key to authenticate to Atlas" | ||
} | ||
variable "private_key" { | ||
type = string | ||
description = "Private Programmatic API key to authenticate to Atlas" | ||
} | ||
variable "org_id" { | ||
type = string | ||
description = "MongoDB Organization ID" | ||
} | ||
variable "group_id" { | ||
type = string | ||
description = "MongoDB Group ID" | ||
} | ||
|
||
variable "name" { | ||
type = string | ||
description = "MongoDB Identity Provider Name" | ||
default = "mongodb_federation_test" | ||
} | ||
|
||
variable "identity_provider_id" { | ||
type = string | ||
description = "MongoDB Identity Provider ID" | ||
default = "5754gdhgd758" | ||
} |
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,11 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
} | ||
mongodbatlas = { | ||
source = "mongodb/mongodbatlas" | ||
} | ||
} | ||
required_version = ">= 0.13" | ||
} |
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
99 changes: 99 additions & 0 deletions
99
mongodbatlas/data_source_mongodbatlas_federated_settings.go
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,99 @@ | ||
package mongodbatlas | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
matlas "go.mongodb.org/atlas/mongodbatlas" | ||
) | ||
|
||
func dataSourceMongoDBAtlasFederatedSettings() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceMongoDBAtlasFederatedSettingsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"org_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"federated_domains": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"has_role_mappings": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"identity_provider_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"identity_provider_status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceMongoDBAtlasFederatedSettingsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
// Get client connection. | ||
conn := meta.(*MongoDBClient).Atlas | ||
|
||
orgID, orgIDOk := d.GetOk("org_id") | ||
|
||
if !orgIDOk { | ||
return diag.FromErr(errors.New("org_id must be configured")) | ||
} | ||
|
||
var ( | ||
err error | ||
org *matlas.Organization | ||
) | ||
|
||
if orgIDOk { | ||
org, _, err = conn.Organizations.Get(ctx, orgID.(string)) | ||
} | ||
|
||
if err != nil { | ||
return diag.Errorf("Error reading Organization %s %s", orgID, err) | ||
} | ||
|
||
federationSettings, _, err := conn.FederatedSettings.Get(ctx, org.ID) | ||
if err != nil { | ||
return diag.Errorf("error getting Federated settings (%s): %s", orgID, err) | ||
} | ||
|
||
if err := d.Set("org_id", org.ID); err != nil { | ||
return diag.Errorf("error getting Federated settings (%s): %s %s", `org_id`, org.ID, err) | ||
} | ||
|
||
if err := d.Set("federated_domains", federationSettings.FederatedDomains); err != nil { | ||
return diag.Errorf("error getting Federated settings (%s): %s %s", `federated_domains`, federationSettings.FederatedDomains, err) | ||
} | ||
|
||
if err := d.Set("identity_provider_status", federationSettings.IdentityProviderStatus); err != nil { | ||
return diag.Errorf("error getting Federated settings (%s): %s %s", `identityProviderStatus`, federationSettings.IdentityProviderStatus, err) | ||
} | ||
|
||
if err := d.Set("identity_provider_id", federationSettings.IdentityProviderID); err != nil { | ||
return diag.Errorf("error getting Federated settings (%s): %s %s", `IdentityProviderID`, federationSettings.IdentityProviderID, err) | ||
} | ||
|
||
if err := d.Set("has_role_mappings", federationSettings.HasRoleMappings); err != nil { | ||
return diag.Errorf("error getting Federated settings (%s): flag %s ", `HasRoleMappings`, err) | ||
} | ||
|
||
d.SetId(federationSettings.ID) | ||
|
||
return nil | ||
} |
Oops, something went wrong.