Skip to content

INTMDB-543: LDAP Config and LDAP Verify Resources Fix #1004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/mwielbut/pointy v1.1.0
github.com/spf13/cast v1.5.0
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20210625132053-af2d5c0ad54f
go.mongodb.org/atlas v0.19.0
go.mongodb.org/atlas v0.21.0
go.mongodb.org/realm v0.1.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9 h1:9m35o4kyRYjwbsIb/l
go.mongodb.org/atlas v0.18.1-0.20221109142841-f9f8ebe7b9b9/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.19.0 h1:gvezG9d0KsSDaExEdTtcGqZHRvvVazzuEcBUpBXxmlg=
go.mongodb.org/atlas v0.19.0/go.mod h1:PFk1IGhiGjFXHGVspOK7i1U2nnPjK8wAjYwQf6FoVf4=
go.mongodb.org/atlas v0.21.0 h1:7Wi8Yy3hJGAyMvb8vZZjoYaQ89l58GCmIx5ppxtrrqc=
go.mongodb.org/atlas v0.21.0/go.mod h1:XTjsxWgoOSwaZrQUvhTEuwjymxnF0r12RPibZuW1Uts=
go.mongodb.org/realm v0.1.0 h1:zJiXyLaZrznQ+Pz947ziSrDKUep39DO4SfA0Fzx8M4M=
go.mongodb.org/realm v0.1.0/go.mod h1:4Vj6iy+Puo1TDERcoh4XZ+pjtwbOzPpzqy3Cwe8ZmDM=
go.mozilla.org/mozlog v0.0.0-20170222151521-4bb13139d403/go.mod h1:jHoPAGnDrCy6kaI2tAze5Prf0Nr0w/oNkROt2lw3n3o=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func dataSourceMongoDBAtlasCloudProviderSnapshot() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "This data source is deprecated. Please transition to mongodbatlas_cloud_backup_snapshot as soon as possible",
DeprecationMessage: "This data source is deprecated, and will be removed in v1.9 release. Please transition to mongodbatlas_cloud_backup_snapshot as soon as possible",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func dataSourceMongoDBAtlasCloudProviderSnapshotBackupPolicy() *schema.Resource
},
},
},
DeprecationMessage: "This data source is deprecated. Please transition to mongodbatlas_cloud_backup_schedule as soon as possible",
DeprecationMessage: "This data source is deprecated, and will be removed in v1.9 release. Please transition to mongodbatlas_cloud_backup_schedule as soon as possible",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJob() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "This data source is deprecated. Please transition to mongodbatlas_cloud_backup_snapshot_restore_job as soon as possible",
DeprecationMessage: "This data source is deprecated, and will be removed in v1.9 release. Please transition to mongodbatlas_cloud_backup_snapshot_restore_job as soon as possible",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func dataSourceMongoDBAtlasCloudProviderSnapshotRestoreJobs() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "This data source is deprecated. Please transition to mongodbatlas_cloud_backup_snapshot_restore_jobs as soon as possible",
DeprecationMessage: "This data source is deprecated, and will be removed in v1.9 release. Please transition to mongodbatlas_cloud_backup_snapshot_restore_jobs as soon as possible",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func dataSourceMongoDBAtlasCloudProviderSnapshots() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "This data source is deprecated. Please transition to mongodbatlas_cloud_backup_snapshots as soon as possible",
DeprecationMessage: "This data source is deprecated, and will be removed in v1.9 release. Please transition to mongodbatlas_cloud_backup_snapshots as soon as possible",
}
}

Expand Down
51 changes: 51 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_org_id.go
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
}
43 changes: 43 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_org_id_test.go
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
}`)
}
1 change: 1 addition & 0 deletions mongodbatlas/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func getDataSourcesMap() map[string]*schema.Resource {
"mongodbatlas_custom_db_roles": dataSourceMongoDBAtlasCustomDBRoles(),
"mongodbatlas_database_user": dataSourceMongoDBAtlasDatabaseUser(),
"mongodbatlas_database_users": dataSourceMongoDBAtlasDatabaseUsers(),
"mongodbatlas_roles_org_id": dataSourceMongoDBAtlasOrgID(),
"mongodbatlas_project": dataSourceMongoDBAtlasProject(),
"mongodbatlas_projects": dataSourceMongoDBAtlasProjects(),
"mongodbatlas_cluster": dataSourceMongoDBAtlasCluster(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func resourceMongoDBAtlasCloudProviderSnapshot() *schema.Resource {
Default: "10m",
},
},
DeprecationMessage: "this resource is deprecated, please transition as soon as possible to mongodbatlas_cloud_backup_snapshot",
DeprecationMessage: "this resource is deprecated, and will be removed in v1.9 release, please transition as soon as possible to mongodbatlas_cloud_backup_snapshot",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func resourceMongoDBAtlasCloudProviderSnapshotBackupPolicy() *schema.Resource {
},
},
},
DeprecationMessage: "this resource is deprecated, please transition as soon as possible to mongodbatlas_cloud_backup_schedule",
DeprecationMessage: "this resource is deprecated, and will be removed in v1.9 release, please transition as soon as possible to mongodbatlas_cloud_backup_schedule",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func resourceMongoDBAtlasCloudProviderSnapshotRestoreJob() *schema.Resource {
Computed: true,
},
},
DeprecationMessage: "this resource is deprecated, please transition as soon as possible to mongodbatlas_cloud_backup_snapshot_restore_job",
DeprecationMessage: "this resource is deprecated, and will be removed in v1.9 release, please transition as soon as possible to mongodbatlas_cloud_backup_snapshot_restore_job",
}
}

Expand Down
33 changes: 17 additions & 16 deletions mongodbatlas/resource_mongodbatlas_ldap_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mwielbut/pointy"
matlas "go.mongodb.org/atlas/mongodbatlas"
)

Expand Down Expand Up @@ -104,35 +105,35 @@ func resourceMongoDBAtlasLDAPConfigurationCreate(ctx context.Context, d *schema.
ldap := &matlas.LDAP{}

if v, ok := d.GetOk("authentication_enabled"); ok {
ldap.AuthenticationEnabled = v.(bool)
ldap.AuthenticationEnabled = pointy.Bool(v.(bool))
}

if v, ok := d.GetOk("authorization_enabled"); ok {
ldap.AuthorizationEnabled = v.(bool)
ldap.AuthorizationEnabled = pointy.Bool(v.(bool))
}

if v, ok := d.GetOk("hostname"); ok {
ldap.Hostname = v.(string)
ldap.Hostname = pointy.String(v.(string))
}

if v, ok := d.GetOk("port"); ok {
ldap.Port = v.(int)
ldap.Port = pointy.Int(v.(int))
}

if v, ok := d.GetOk("bind_username"); ok {
ldap.BindUsername = v.(string)
ldap.BindUsername = pointy.String(v.(string))
}

if v, ok := d.GetOk("bind_password"); ok {
ldap.BindPassword = v.(string)
ldap.BindPassword = pointy.String(v.(string))
}

if v, ok := d.GetOk("ca_certificate"); ok {
ldap.CaCertificate = v.(string)
ldap.CaCertificate = pointy.String(v.(string))
}

if v, ok := d.GetOk("authz_query_template"); ok {
ldap.AuthzQueryTemplate = v.(string)
ldap.AuthzQueryTemplate = pointy.String(v.(string))
}

if v, ok := d.GetOk("user_to_dn_mapping"); ok {
Expand Down Expand Up @@ -201,35 +202,35 @@ func resourceMongoDBAtlasLDAPConfigurationUpdate(ctx context.Context, d *schema.
ldap := &matlas.LDAP{}

if d.HasChange("authentication_enabled") {
ldap.AuthenticationEnabled = d.Get("").(bool)
ldap.AuthenticationEnabled = pointy.Bool(d.Get("").(bool))
}

if d.HasChange("authorization_enabled") {
ldap.AuthorizationEnabled = d.Get("authorization_enabled").(bool)
ldap.AuthorizationEnabled = pointy.Bool(d.Get("authorization_enabled").(bool))
}

if d.HasChange("hostname") {
ldap.Hostname = d.Get("hostname").(string)
ldap.Hostname = pointy.String(d.Get("hostname").(string))
}

if d.HasChange("port") {
ldap.Port = d.Get("port").(int)
ldap.Port = pointy.Int(d.Get("port").(int))
}

if d.HasChange("bind_username") {
ldap.BindUsername = d.Get("bind_username").(string)
ldap.BindUsername = pointy.String(d.Get("bind_username").(string))
}

if d.HasChange("bind_password") {
ldap.BindPassword = d.Get("bind_password").(string)
ldap.BindPassword = pointy.String(d.Get("bind_password").(string))
}

if d.HasChange("ca_certificate") {
ldap.CaCertificate = d.Get("ca_certificate").(string)
ldap.CaCertificate = pointy.String(d.Get("ca_certificate").(string))
}

if d.HasChange("authz_query_template") {
ldap.AuthzQueryTemplate = d.Get("authz_query_template").(string)
ldap.AuthzQueryTemplate = pointy.String(d.Get("authz_query_template").(string))
}

if d.HasChange("user_to_dn_mapping") {
Expand Down
13 changes: 7 additions & 6 deletions mongodbatlas/resource_mongodbatlas_ldap_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/mwielbut/pointy"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
matlas "go.mongodb.org/atlas/mongodbatlas"
Expand Down Expand Up @@ -118,22 +119,22 @@ func resourceMongoDBAtlasLDAPVerifyCreate(ctx context.Context, d *schema.Resourc
ldapReq := &matlas.LDAP{}

if v, ok := d.GetOk("hostname"); ok {
ldapReq.Hostname = v.(string)
ldapReq.Hostname = pointy.String(v.(string))
}
if v, ok := d.GetOk("port"); ok {
ldapReq.Port = v.(int)
ldapReq.Port = pointy.Int(v.(int))
}
if v, ok := d.GetOk("bind_username"); ok {
ldapReq.BindUsername = v.(string)
ldapReq.BindUsername = pointy.String(v.(string))
}
if v, ok := d.GetOk("bind_password"); ok {
ldapReq.BindPassword = v.(string)
ldapReq.BindPassword = pointy.String(v.(string))
}
if v, ok := d.GetOk("ca_certificate"); ok {
ldapReq.CaCertificate = v.(string)
ldapReq.CaCertificate = pointy.String(v.(string))
}
if v, ok := d.GetOk("authz_query_template"); ok {
ldapReq.AuthzQueryTemplate = v.(string)
ldapReq.AuthzQueryTemplate = pointy.String(v.(string))
}

ldap, _, err := conn.LDAPConfigurations.Verify(ctx, projectID, ldapReq)
Expand Down
1 change: 1 addition & 0 deletions mongodbatlas/resource_mongodbatlas_private_ip_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func resourceMongoDBAtlasPrivateIPMode() *schema.Resource {
Required: true,
},
},
DeprecationMessage: "This resource is deprecated, and will be removed in v1.9 release. Please transition to Multiple Horizons connection strings as soon as possible",
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func resourceMongoDBAtlasThirdPartyIntegration() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(integrationTypes, false),
Deprecated: "This field type has values (NEW_RELIC, FLOWDOCK) that are deprecated and will be removed in 1.9.0 release ",
},
"license_key": {
Type: schema.TypeString,
Expand Down
Loading