Skip to content
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

refactor: adjust project_api_key to new file structure #1676

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit-non-blocking] given the decision on one package per resource and to follow the "don't stutter" general recommendation of go

Suggested change
"mongodbatlas_project_api_key": projectapikey.DataSourceProjectAPIKey(),
"mongodbatlas_project_api_key": projectapikey.DataSource(),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense, will do a followup PR to adjust all of the resources that have already been adjusted to new structure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, thx

"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
3 changes: 2 additions & 1 deletion mongodbatlas/data_source_org_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"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/config"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/service/projectapikey"

matlas "go.mongodb.org/atlas/mongodbatlas"
)
Expand Down Expand Up @@ -42,7 +43,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(projectapikey.ErrorProjectSetting, `org_id`, root.APIKey.ID, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error seems to be defined in the wrong package

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this message was not accurate, adjusted and left a new constant to help with consistency in error messages

}
d.SetId(apiKeyOrgList.APIKey.Roles[idx].OrgID)
return nil
Expand Down
Loading