Skip to content

Commit

Permalink
refactor: adjust project_api_key to new file structure (#1676)
Browse files Browse the repository at this point in the history
* refactor: adjust project_api_key to new file structure

* adjust error message for org_id data source leaving new constant for setting attribute errors
  • Loading branch information
AgustinBettati authored Nov 29, 2023
1 parent ddb43b2 commit d71180f
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jobs:
- 'internal/service/alertconfiguration/*.go'
- 'internal/service/atlasuser/*.go'
- 'internal/service/databaseuser/*.go'
- 'internal/service/projectapikey/*.go'
- 'mongodbatlas/data_source_accesslist_api_key*.go'
- 'mongodbatlas/data_source_api_key*.go'
- 'mongodbatlas/data_source_cloud_provider_access_setup*.go'
Expand All @@ -91,7 +92,6 @@ jobs:
- 'mongodbatlas/data_source_org_id*.go'
- 'mongodbatlas/data_source_org_invitation*.go'
- 'mongodbatlas/data_source_organization*.go'
- 'mongodbatlas/data_source_project_api_key*.go'
- 'mongodbatlas/data_source_team*.go'
- 'mongodbatlas/data_source_third_party_integration*.go'
- 'mongodbatlas/resource_api_key*.go'
Expand All @@ -102,7 +102,6 @@ jobs:
- 'mongodbatlas/resource_maintenance_window*.go'
- 'mongodbatlas/resource_org_invitation*.go'
- 'mongodbatlas/resource_organization*.go'
- 'mongodbatlas/resource_project_api_key*.go'
- 'mongodbatlas/resource_team*.go'
- 'mongodbatlas/resource_third_party_integration*.go'
event_trigger:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/migration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ jobs:
- 'internal/service/alertconfiguration/*.go'
- 'internal/service/atlasuser/*.go'
- 'internal/service/databaseuser/*.go'
- 'mongodbatlas/data_source_project_api_key*.go'
- 'mongodbatlas/resource_project_api_key*.go'
- 'internal/service/projectapikey/*.go'
backup_online_archive:
- 'mongodbatlas/**online_archive**.go'
advanced_cluster:
Expand Down
5 changes: 5 additions & 0 deletions internal/common/constant/error_message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constant

const (
ErrorSettingAttribute = "error setting `%s`: %s"
)
7 changes: 4 additions & 3 deletions internal/provider/provider_sdk2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cluster"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectapikey"
"github.com/mongodb/terraform-provider-mongodbatlas/mongodbatlas"
"github.com/mwielbut/pointy"
)
Expand Down Expand Up @@ -108,8 +109,8 @@ func getDataSourcesMap() map[string]*schema.Resource {
"mongodbatlas_api_keys": mongodbatlas.DataSourceAPIKeys(),
"mongodbatlas_access_list_api_key": mongodbatlas.DataSourceAccessListAPIKey(),
"mongodbatlas_access_list_api_keys": mongodbatlas.DataSourceAccessListAPIKeys(),
"mongodbatlas_project_api_key": mongodbatlas.DataSourceProjectAPIKey(),
"mongodbatlas_project_api_keys": mongodbatlas.DataSourceProjectAPIKeys(),
"mongodbatlas_project_api_key": projectapikey.DataSourceProjectAPIKey(),
"mongodbatlas_project_api_keys": projectapikey.DataSourceProjectAPIKeys(),
"mongodbatlas_roles_org_id": mongodbatlas.DataSourceOrgID(),
"mongodbatlas_cluster": cluster.DataSourceCluster(),
"mongodbatlas_clusters": cluster.DataSourceClusters(),
Expand Down Expand Up @@ -188,7 +189,7 @@ func getResourcesMap() map[string]*schema.Resource {
"mongodbatlas_advanced_cluster": advancedcluster.ResourceAdvancedCluster(),
"mongodbatlas_api_key": mongodbatlas.ResourceAPIKey(),
"mongodbatlas_access_list_api_key": mongodbatlas.ResourceAccessListAPIKey(),
"mongodbatlas_project_api_key": mongodbatlas.ResourceProjectAPIKey(),
"mongodbatlas_project_api_key": projectapikey.ResourceProjectAPIKey(),
"mongodbatlas_custom_db_role": mongodbatlas.ResourceCustomDBRole(),
"mongodbatlas_cluster": cluster.ResourceCluster(),
"mongodbatlas_network_container": mongodbatlas.ResourceNetworkContainer(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mongodbatlas
package projectapikey

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mongodbatlas
package projectapikey

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mongodbatlas
package projectapikey

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mongodbatlas_test
package projectapikey_test

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mongodbatlas_test
package projectapikey_test

import (
"context"
Expand Down
8 changes: 3 additions & 5 deletions mongodbatlas/data_source_org_id.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/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"

matlas "go.mongodb.org/atlas/mongodbatlas"
Expand All @@ -28,10 +29,7 @@ func dataSourceMongoDBAtlasOrgIDRead(ctx context.Context, d *schema.ResourceData
// Get client connection.
conn := meta.(*config.MongoDBClient).Atlas

var (
err error
root *matlas.Root
)
var err error

options := &matlas.ListOptions{}
apiKeyOrgList, _, err := conn.Root.List(ctx, options)
Expand All @@ -42,7 +40,7 @@ func dataSourceMongoDBAtlasOrgIDRead(ctx context.Context, d *schema.ResourceData
for idx, role := range apiKeyOrgList.APIKey.Roles {
if strings.HasPrefix(role.RoleName, "ORG_") {
if err := d.Set("org_id", apiKeyOrgList.APIKey.Roles[idx].OrgID); err != nil {
return diag.Errorf(ErrorProjectSetting, `org_id`, root.APIKey.ID, err)
return diag.Errorf(constant.ErrorSettingAttribute, "org_id", err)
}
d.SetId(apiKeyOrgList.APIKey.Roles[idx].OrgID)
return nil
Expand Down

0 comments on commit d71180f

Please sign in to comment.