From c9a43ff5581890deb222cbfec47e452fae40adae Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Thu, 6 Feb 2025 13:52:00 +0000 Subject: [PATCH 1/2] add status check methods --- internal/config/http_status_checks.go | 15 +++++++++++++++ .../resource_access_list_api_key.go | 9 +++++---- .../data_source_advanced_cluster.go | 3 +-- .../data_source_advanced_clusters.go | 3 +-- .../advancedcluster/model_advanced_cluster.go | 9 +++++---- .../advancedcluster/resource_advanced_cluster.go | 6 +++--- .../advancedclustertpf/common_await_changes.go | 4 ++-- .../resource_alert_configuration.go | 3 +-- internal/service/apikey/resource_api_key.go | 9 +++++---- internal/service/auditing/resource_auditing.go | 3 +-- .../data_source_backup_compliance_policy.go | 3 +-- .../resource_backup_compliance_policy.go | 3 +-- .../resource_cloud_backup_schedule.go | 4 ++-- .../resource_cloud_backup_snapshot.go | 5 ++--- ...esource_cloud_backup_snapshot_export_bucket.go | 5 ++--- .../resource_cloud_backup_snapshot_restore_job.go | 3 +-- .../resource_cloud_provider_access_setup.go | 3 +-- .../resource_cluster_outage_simulation.go | 5 ++--- .../customdbrole/resource_custom_db_role.go | 3 +-- ...source_custom_dns_configuration_cluster_aws.go | 3 +-- .../data_source_data_lake_pipeline_run.go | 3 +-- .../resource_data_lake_pipeline.go | 3 +-- internal/service/encryptionatrest/resource.go | 3 +-- .../encryptionatrestprivateendpoint/resource.go | 3 +-- .../state_transition.go | 4 ++-- .../resource_federated_database_instance.go | 3 +-- .../resource_federated_query_limit.go | 3 +-- ...source_federated_settings_identity_provider.go | 5 ++--- .../resource_federated_settings_connected_org.go | 3 +-- ...esource_federated_settings_org_role_mapping.go | 5 ++--- internal/service/flexcluster/resource.go | 6 +++--- internal/service/flexcluster/state_transition.go | 3 ++- .../data_source_global_cluster_config.go | 6 +++--- .../resource_global_cluster_config.go | 9 +++++---- .../resource_ldap_configuration.go | 7 ++++--- .../service/ldapverify/resource_ldap_verify.go | 5 ++--- .../resource_maintenance_window.go | 3 +-- .../mongodbemployeeaccessgrant/resource.go | 3 ++- .../data_source_network_container.go | 3 +-- .../resource_network_container.go | 11 ++++++----- .../networkpeering/data_source_network_peering.go | 3 +-- .../networkpeering/resource_network_peering.go | 7 +++---- .../onlinearchive/resource_online_archive.go | 7 +++---- .../service/organization/resource_organization.go | 5 ++--- .../resource_private_endpoint_regional_mode.go | 5 ++--- .../resource_privatelink_endpoint.go | 7 +++---- .../resource_privatelink_endpoint_serverless.go | 2 +- .../resource_privatelink_endpoint_service.go | 5 ++--- ...oint_service_data_federation_online_archive.go | 5 ++--- ...rce_privatelink_endpoint_service_serverless.go | 6 +++--- internal/service/project/resource_project.go | 3 +-- .../resource_project_invitation.go | 3 +-- internal/service/pushbasedlogexport/resource.go | 3 +-- .../pushbasedlogexport/state_transition.go | 3 ++- internal/service/resourcepolicy/resource.go | 7 ++++--- .../resource_search_deployment.go | 4 ++-- .../state_transition_search_deployment.go | 5 +++-- .../service/searchindex/resource_search_index.go | 2 +- .../resource_serverless_instance.go | 4 ++-- .../resource_stream_connection.go | 7 +++---- .../service/streamconnection/state_transition.go | 3 ++- .../streaminstance/resource_stream_instance.go | 4 ++-- .../service/streamprivatelinkendpoint/resource.go | 5 ++--- .../streamprivatelinkendpoint/state_transition.go | 4 ++-- internal/service/streamprocessor/resource.go | 7 ++++--- .../service/streamprocessor/state_transition.go | 4 ++-- internal/service/team/resource_team.go | 2 +- .../resource_third_party_integration.go | 3 +-- tools/scaffold/template/resource.tmpl | 2 +- 69 files changed, 154 insertions(+), 165 deletions(-) create mode 100644 internal/config/http_status_checks.go diff --git a/internal/config/http_status_checks.go b/internal/config/http_status_checks.go new file mode 100644 index 0000000000..e738656177 --- /dev/null +++ b/internal/config/http_status_checks.go @@ -0,0 +1,15 @@ +package config + +import "net/http" + +func StatusNotFound(resp *http.Response) bool { + return resp != nil && resp.StatusCode == http.StatusNotFound +} + +func StatusServiceUnavailable(resp *http.Response) bool { + return resp != nil && resp.StatusCode == http.StatusServiceUnavailable +} + +func StatusBadRequest(resp *http.Response) bool { + return resp != nil && resp.StatusCode == http.StatusBadRequest +} diff --git a/internal/service/accesslistapikey/resource_access_list_api_key.go b/internal/service/accesslistapikey/resource_access_list_api_key.go index 9b13349ee0..9780a65eb0 100644 --- a/internal/service/accesslistapikey/resource_access_list_api_key.go +++ b/internal/service/accesslistapikey/resource_access_list_api_key.go @@ -5,15 +5,16 @@ import ( "errors" "fmt" "net" - "net/http" "strings" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) func Resource() *schema.Resource { @@ -104,7 +105,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. _, resp, err := connV2.ProgrammaticAPIKeysApi.CreateApiKeyAccessList(ctx, orgID, apiKeyID, accessList).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -129,7 +130,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di apiKey, resp, err := connV2.ProgrammaticAPIKeysApi.GetApiKeyAccessList(ctx, orgID, ipAddress, apiKeyID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusBadRequest { + if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { d.SetId("") return nil } diff --git a/internal/service/advancedcluster/data_source_advanced_cluster.go b/internal/service/advancedcluster/data_source_advanced_cluster.go index ece283b448..eab11a3165 100644 --- a/internal/service/advancedcluster/data_source_advanced_cluster.go +++ b/internal/service/advancedcluster/data_source_advanced_cluster.go @@ -3,7 +3,6 @@ package advancedcluster import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -294,7 +293,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. clusterDesc, resp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return nil } return diag.FromErr(fmt.Errorf(errorRead, clusterName, err)) diff --git a/internal/service/advancedcluster/data_source_advanced_clusters.go b/internal/service/advancedcluster/data_source_advanced_clusters.go index e1974d6fce..02541754fb 100644 --- a/internal/service/advancedcluster/data_source_advanced_clusters.go +++ b/internal/service/advancedcluster/data_source_advanced_clusters.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -310,7 +309,7 @@ func dataSourcePluralRead(ctx context.Context, d *schema.ResourceData, meta any) list, resp, err := connV2.ClustersApi.ListClusters(ctx, projectID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return nil } return diag.FromErr(fmt.Errorf(errorListRead, projectID, err)) diff --git a/internal/service/advancedcluster/model_advanced_cluster.go b/internal/service/advancedcluster/model_advanced_cluster.go index 0057090a38..5ea4a78f6b 100644 --- a/internal/service/advancedcluster/model_advanced_cluster.go +++ b/internal/service/advancedcluster/model_advanced_cluster.go @@ -21,6 +21,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedclustertpf" ) @@ -358,10 +359,10 @@ func UpgradeRefreshFunc(ctx context.Context, name, projectID string, client admi if err != nil && cluster == nil && resp == nil { return nil, "", err } else if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err @@ -385,10 +386,10 @@ func ResourceClusterListAdvancedRefreshFunc(ctx context.Context, projectID strin } if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/advancedcluster/resource_advanced_cluster.go b/internal/service/advancedcluster/resource_advanced_cluster.go index 180b8bbad1..071c908ea0 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster.go +++ b/internal/service/advancedcluster/resource_advanced_cluster.go @@ -608,7 +608,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di cluster, resp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -1343,10 +1343,10 @@ func resourceRefreshFunc(ctx context.Context, name, projectID string, connV2 *ad } if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/advancedclustertpf/common_await_changes.go b/internal/service/advancedclustertpf/common_await_changes.go index 336c2695ac..8febc036a9 100644 --- a/internal/service/advancedclustertpf/common_await_changes.go +++ b/internal/service/advancedclustertpf/common_await_changes.go @@ -88,10 +88,10 @@ func resourceRefreshFunc(ctx context.Context, name, projectID string, api admin. } if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", retrystrategy.RetryStrategyDeletedState, nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", retrystrategy.RetryStrategyPendingState, nil } return nil, "", err diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index 1d1f9c9ecc..70cb01ba62 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -2,7 +2,6 @@ package alertconfiguration import ( "context" - "net/http" "reflect" "strings" @@ -432,7 +431,7 @@ func (r *alertConfigurationRS) Read(ctx context.Context, req resource.ReadReques alert, getResp, err := connV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), ids[EncodedIDKeyProjectID], ids[EncodedIDKeyAlertID]).Execute() if err != nil { // deleted in the backend case - if getResp != nil && getResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/apikey/resource_api_key.go b/internal/service/apikey/resource_api_key.go index 5c698db146..180396f559 100644 --- a/internal/service/apikey/resource_api_key.go +++ b/internal/service/apikey/resource_api_key.go @@ -5,14 +5,15 @@ import ( "errors" "fmt" "log" - "net/http" "strings" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) func Resource() *schema.Resource { @@ -67,7 +68,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. apiKey, resp, err := connV2.ProgrammaticAPIKeysApi.CreateApiKey(ctx, orgID, createRequest).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -95,7 +96,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di apiKey, resp, err := connV2.ProgrammaticAPIKeysApi.GetApiKey(ctx, orgID, apiKeyID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusBadRequest { + if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { log.Printf("warning API key deleted will recreate: %s \n", err.Error()) d.SetId("") return nil diff --git a/internal/service/auditing/resource_auditing.go b/internal/service/auditing/resource_auditing.go index 0afa146db3..7fd59e5f4e 100644 --- a/internal/service/auditing/resource_auditing.go +++ b/internal/service/auditing/resource_auditing.go @@ -3,7 +3,6 @@ package auditing import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -87,7 +86,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di connV2 := meta.(*config.MongoDBClient).AtlasV2 auditing, resp, err := connV2.AuditingApi.GetAuditingConfiguration(ctx, d.Id()).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go b/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go index 27dd6e8761..7bdbb76ab7 100644 --- a/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go +++ b/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go @@ -3,7 +3,6 @@ package backupcompliancepolicy import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -238,7 +237,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. projectID := d.Get("project_id").(string) policy, resp, err := connV2.CloudBackupsApi.GetDataProtectionSettings(ctx, projectID).Execute() - if resp != nil && resp.StatusCode == http.StatusNotFound || policy.GetProjectId() == "" { + if config.StatusNotFound(resp) || policy.GetProjectId() == "" { return nil } if err != nil { diff --git a/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go b/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go index 5c0603bc41..a1d18f8a6e 100644 --- a/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go +++ b/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -283,7 +282,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di policy, resp, err := connV2.CloudBackupsApi.GetDataProtectionSettings(ctx, projectID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go b/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go index 314c1ce9a1..6f601c5630 100644 --- a/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go +++ b/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go @@ -376,7 +376,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di return diag.Errorf("%s : %s : %s", errorSnapshotBackupScheduleRead, ErrorOperationNotPermitted, AsymmetricShardsUnsupportedAction) } if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -388,7 +388,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di } else { backupSchedule, resp, err = connV2.CloudBackupsApi.GetBackupSchedule(context.Background(), projectID, clusterName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go b/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go index 4564cebdfe..385c8a4857 100644 --- a/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go +++ b/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -178,7 +177,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di snapshot, resp, err := connV2.CloudBackupsApi.GetReplicaSetBackup(ctx, groupID, clusterName, snapshotID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -295,7 +294,7 @@ func resourceRefreshFunc(ctx context.Context, requestParams *admin.GetReplicaSet if err != nil { return nil, "failed", err } - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return "", "DELETED", nil } status := snapshot.GetStatus() diff --git a/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go b/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go index 9bd51f6b51..fe39928450 100644 --- a/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go +++ b/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "regexp" "strings" "time" @@ -229,7 +228,7 @@ func resourceRefresh(ctx context.Context, client *admin.APIClient, projectID, ex clustersPaginated, resp, err := client.ClustersApi.ListClusters(ctx, projectID).Execute() if err != nil { // For our purposes, no clusters is equivalent to all changes having been APPLIED - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return "", "APPLIED", nil } return nil, "REPEATING", err @@ -258,7 +257,7 @@ func resourceRefresh(ctx context.Context, client *admin.APIClient, projectID, ex } if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go index e95a9a21da..3a934463a6 100644 --- a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go +++ b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -163,7 +162,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di restoreID := ids["snapshot_restore_job_id"] snapshotReq, resp, err := conn.CloudBackupsApi.GetBackupRestoreJob(ctx, projectID, clusterName, restoreID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go index 49c90165e8..f30d530d0e 100644 --- a/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go @@ -3,7 +3,6 @@ package cloudprovideraccess import ( "context" "fmt" - "net/http" "regexp" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -111,7 +110,7 @@ func resourceCloudProviderAccessSetupRead(ctx context.Context, d *schema.Resourc role, resp, err := conn.CloudProviderAccessApi.GetCloudProviderAccessRole(context.Background(), projectID, roleID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go b/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go index f30e36c0b0..fdbbcd344b 100644 --- a/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go +++ b/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -140,7 +139,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di outageSimulation, resp, err := connV2.ClusterOutageSimulationApi.GetOutageSimulation(ctx, projectID, clusterName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -199,7 +198,7 @@ func resourceRefreshFunc(ctx context.Context, clusterName, projectID string, cli outageSimulation, resp, err := client.ClusterOutageSimulationApi.GetOutageSimulation(ctx, projectID, clusterName).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } return nil, "", err diff --git a/internal/service/customdbrole/resource_custom_db_role.go b/internal/service/customdbrole/resource_custom_db_role.go index b435ce3e30..6a2b1c9890 100644 --- a/internal/service/customdbrole/resource_custom_db_role.go +++ b/internal/service/customdbrole/resource_custom_db_role.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "regexp" "strings" "time" @@ -157,7 +156,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di customDBRole, resp, err := connV2.CustomDatabaseRolesApi.GetCustomDatabaseRole(ctx, projectID, roleName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go b/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go index 4eaee15ab9..c414f465d0 100644 --- a/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go +++ b/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go @@ -3,7 +3,6 @@ package customdnsconfigurationclusteraws import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -62,7 +61,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di projectID := d.Id() dnsResp, resp, err := connV2.AWSClustersDNSApi.GetAwsCustomDns(context.Background(), projectID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go b/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go index 425dd5e812..116bba9f7e 100644 --- a/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go +++ b/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go @@ -3,7 +3,6 @@ package datalakepipeline import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -96,7 +95,7 @@ func dataSourceRunRead(ctx context.Context, d *schema.ResourceData, meta any) di run, resp, err := connV2.DataLakePipelinesApi.GetPipelineRun(ctx, projectID, name, pipelineRunID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/datalakepipeline/resource_data_lake_pipeline.go b/internal/service/datalakepipeline/resource_data_lake_pipeline.go index 03eb973098..b5d618f3ee 100644 --- a/internal/service/datalakepipeline/resource_data_lake_pipeline.go +++ b/internal/service/datalakepipeline/resource_data_lake_pipeline.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -289,7 +288,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di name := ids["name"] pipeline, resp, err := connV2.DataLakePipelinesApi.GetPipeline(ctx, projectID, name).Execute() - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/encryptionatrest/resource.go b/internal/service/encryptionatrest/resource.go index acd44ba53a..66e6d0d12d 100644 --- a/internal/service/encryptionatrest/resource.go +++ b/internal/service/encryptionatrest/resource.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "reflect" "time" @@ -340,7 +339,7 @@ func (r *encryptionAtRestRS) Read(ctx context.Context, req resource.ReadRequest, encryptionResp, getResp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), projectID).Execute() if err != nil { - if getResp != nil && getResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/encryptionatrestprivateendpoint/resource.go b/internal/service/encryptionatrestprivateendpoint/resource.go index c829c46b8a..f7d6bb10aa 100644 --- a/internal/service/encryptionatrestprivateendpoint/resource.go +++ b/internal/service/encryptionatrestprivateendpoint/resource.go @@ -3,7 +3,6 @@ package encryptionatrestprivateendpoint import ( "context" "errors" - "net/http" "regexp" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -90,7 +89,7 @@ func (r *encryptionAtRestPrivateEndpointRS) Read(ctx context.Context, req resour endpointModel, apiResp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRestPrivateEndpoint(ctx, projectID, cloudProvider, endpointID).Execute() if err != nil { - if apiResp != nil && apiResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/encryptionatrestprivateendpoint/state_transition.go b/internal/service/encryptionatrestprivateendpoint/state_transition.go index a2644a8033..a5b6bc7013 100644 --- a/internal/service/encryptionatrestprivateendpoint/state_transition.go +++ b/internal/service/encryptionatrestprivateendpoint/state_transition.go @@ -3,11 +3,11 @@ package encryptionatrestprivateendpoint import ( "context" "errors" - "net/http" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -67,7 +67,7 @@ func refreshFunc(ctx context.Context, projectID, cloudProvider, endpointID strin return nil, "", err } if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return &admin.EARPrivateEndpoint{}, retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index 7c28bfcb9f..2bb26b27f1 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -402,7 +401,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di dataFederationInstance, resp, err := connV2.DataFederationApi.GetFederatedDatabase(ctx, projectID, name).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedquerylimit/resource_federated_query_limit.go b/internal/service/federatedquerylimit/resource_federated_query_limit.go index 37e22c295c..5a66c92007 100644 --- a/internal/service/federatedquerylimit/resource_federated_query_limit.go +++ b/internal/service/federatedquerylimit/resource_federated_query_limit.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -109,7 +108,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di queryLimit, resp, err := conn.DataFederationApi.ReturnFederatedDatabaseQueryLimit(ctx, projectID, tenantName, limitName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index da30875487..9a459a97bf 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -152,7 +151,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di if err != nil { // case 404 // deleted in the backend case - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -359,7 +358,7 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag. federationSettingsID, idpID := DecodeIDs(d.Id()) resp, err := connV2.FederatedAuthenticationApi.DeleteIdentityProvider(ctx, federationSettingsID, idpID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go index 6f49cb8f74..930e4835dd 100644 --- a/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go +++ b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -82,7 +81,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di federatedSettingsConnectedOrganization, resp, err := conn.FederatedAuthenticationApi.GetConnectedOrgConfig(context.Background(), federationSettingsID, orgID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go index dc5b70aae6..22f4c93c13 100644 --- a/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go +++ b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -82,7 +81,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di federatedSettingsOrganizationRoleMapping, resp, err := conn.FederatedAuthenticationApi.GetRoleMapping(context.Background(), federationSettingsID, roleMappingID, orgID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -133,7 +132,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. } federatedSettingsOrganizationRoleMapping, resp, err := conn.FederatedAuthenticationApi.CreateRoleMapping(ctx, federationSettingsID.(string), orgID.(string), &roleMapping).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/flexcluster/resource.go b/internal/service/flexcluster/resource.go index fc3e4ae252..a43d69b815 100644 --- a/internal/service/flexcluster/resource.go +++ b/internal/service/flexcluster/resource.go @@ -3,13 +3,13 @@ package flexcluster import ( "context" "errors" - "net/http" "regexp" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" - "go.mongodb.org/atlas-sdk/v20241113004/admin" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" @@ -96,7 +96,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. connV2 := r.Client.AtlasV2 flexCluster, apiResp, err := connV2.FlexClustersApi.GetFlexCluster(ctx, flexClusterState.ProjectId.ValueString(), flexClusterState.Name.ValueString()).Execute() if err != nil { - if apiResp != nil && apiResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/flexcluster/state_transition.go b/internal/service/flexcluster/state_transition.go index 466e7dc78d..c3fe2fc66a 100644 --- a/internal/service/flexcluster/state_transition.go +++ b/internal/service/flexcluster/state_transition.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -49,7 +50,7 @@ func refreshFunc(ctx context.Context, requestParams *admin.GetFlexClusterApiPara return func() (any, string, error) { flexCluster, resp, err := client.GetFlexClusterWithParams(ctx, requestParams).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/globalclusterconfig/data_source_global_cluster_config.go b/internal/service/globalclusterconfig/data_source_global_cluster_config.go index 4ea696dcb7..7791b5bf42 100644 --- a/internal/service/globalclusterconfig/data_source_global_cluster_config.go +++ b/internal/service/globalclusterconfig/data_source_global_cluster_config.go @@ -3,10 +3,10 @@ package globalclusterconfig import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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" ) @@ -75,7 +75,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. resp, httpResp, err := connV2.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if httpResp != nil && httpResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(httpResp) { d.SetId("") return nil } @@ -83,7 +83,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. } oldResp, httpResp, err := connV220240530.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if httpResp != nil && httpResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(httpResp) { d.SetId("") return nil } diff --git a/internal/service/globalclusterconfig/resource_global_cluster_config.go b/internal/service/globalclusterconfig/resource_global_cluster_config.go index 57b997e891..d3e2661085 100644 --- a/internal/service/globalclusterconfig/resource_global_cluster_config.go +++ b/internal/service/globalclusterconfig/resource_global_cluster_config.go @@ -4,17 +4,18 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "time" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "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/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) const ( @@ -180,7 +181,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di resp, httpResp, err := connV2.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if httpResp != nil && httpResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(httpResp) { d.SetId("") return nil } @@ -188,7 +189,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di } oldResp, httpResp, err := connV220240530.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if httpResp != nil && httpResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(httpResp) { d.SetId("") return nil } diff --git a/internal/service/ldapconfiguration/resource_ldap_configuration.go b/internal/service/ldapconfiguration/resource_ldap_configuration.go index 82c1eed106..b7aecb7562 100644 --- a/internal/service/ldapconfiguration/resource_ldap_configuration.go +++ b/internal/service/ldapconfiguration/resource_ldap_configuration.go @@ -3,13 +3,14 @@ package ldapconfiguration import ( "context" "fmt" - "net/http" + + "go.mongodb.org/atlas-sdk/v20241113004/admin" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) const ( @@ -156,7 +157,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di connV2 := meta.(*config.MongoDBClient).AtlasV2 resp, httpResp, err := connV2.LDAPConfigurationApi.GetLdapConfiguration(context.Background(), d.Id()).Execute() if err != nil { - if httpResp != nil && httpResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(httpResp) { d.SetId("") return nil } diff --git a/internal/service/ldapverify/resource_ldap_verify.go b/internal/service/ldapverify/resource_ldap_verify.go index 45a4c56269..396083b805 100644 --- a/internal/service/ldapverify/resource_ldap_verify.go +++ b/internal/service/ldapverify/resource_ldap_verify.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "time" @@ -170,7 +169,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di requestID := ids["request_id"] ldapResp, resp, err := connV2.LDAPConfigurationApi.GetLdapConfigurationStatus(context.Background(), projectID, requestID).Execute() if err != nil || ldapResp == nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -252,7 +251,7 @@ func resourceRefreshFunc(ctx context.Context, projectID, requestID string, connV return func() (any, string, error) { ldap, resp, err := connV2.LDAPConfigurationApi.GetLdapConfigurationStatus(ctx, projectID, requestID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } return nil, "", err diff --git a/internal/service/maintenancewindow/resource_maintenance_window.go b/internal/service/maintenancewindow/resource_maintenance_window.go index 8700b1856d..c3aeef7eaa 100644 --- a/internal/service/maintenancewindow/resource_maintenance_window.go +++ b/internal/service/maintenancewindow/resource_maintenance_window.go @@ -3,7 +3,6 @@ package maintenancewindow import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -136,7 +135,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di maintenanceWindow, resp, err := connV2.MaintenanceWindowsApi.GetMaintenanceWindow(context.Background(), projectID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/mongodbemployeeaccessgrant/resource.go b/internal/service/mongodbemployeeaccessgrant/resource.go index 034bec4211..87037c0cb9 100644 --- a/internal/service/mongodbemployeeaccessgrant/resource.go +++ b/internal/service/mongodbemployeeaccessgrant/resource.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -54,7 +55,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. projectID := tfModel.ProjectID.ValueString() clusterName := tfModel.ClusterName.ValueString() cluster, httpResp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute() - if httpResp != nil && httpResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(httpResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/networkcontainer/data_source_network_container.go b/internal/service/networkcontainer/data_source_network_container.go index e4b0392e8d..a08183458a 100644 --- a/internal/service/networkcontainer/data_source_network_container.go +++ b/internal/service/networkcontainer/data_source_network_container.go @@ -3,7 +3,6 @@ package networkcontainer import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -81,7 +80,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. container, resp, err := connV2.NetworkPeeringApi.GetPeeringContainer(ctx, projectID, containerID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return nil } return diag.FromErr(fmt.Errorf(ErrorContainerRead, containerID, err)) diff --git a/internal/service/networkcontainer/resource_network_container.go b/internal/service/networkcontainer/resource_network_container.go index 9e8741cc2d..fec5f57bea 100644 --- a/internal/service/networkcontainer/resource_network_container.go +++ b/internal/service/networkcontainer/resource_network_container.go @@ -5,19 +5,20 @@ import ( "errors" "fmt" "log" - "net/http" "strings" "time" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" + "github.com/spf13/cast" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "github.com/spf13/cast" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) const ( @@ -158,7 +159,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di container, resp, err := connV2.NetworkPeeringApi.GetPeeringContainer(ctx, projectID, containerID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -323,7 +324,7 @@ func resourceRefreshFunc(ctx context.Context, d *schema.ResourceData, client *ad var err error container, res, err := client.NetworkPeeringApi.GetPeeringContainer(ctx, projectID, containerID).Execute() if err != nil { - if res.StatusCode == 404 { + if config.StatusNotFound(res) { return "", "deleted", nil } diff --git a/internal/service/networkpeering/data_source_network_peering.go b/internal/service/networkpeering/data_source_network_peering.go index 36e0dc877b..6679a443f4 100644 --- a/internal/service/networkpeering/data_source_network_peering.go +++ b/internal/service/networkpeering/data_source_network_peering.go @@ -3,7 +3,6 @@ package networkpeering import ( "context" "fmt" - "net/http" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -117,7 +116,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. peer, resp, err := conn.NetworkPeeringApi.GetPeeringConnection(ctx, projectID, peerID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return nil } diff --git a/internal/service/networkpeering/resource_network_peering.go b/internal/service/networkpeering/resource_network_peering.go index 73b41bf617..5db72710e3 100644 --- a/internal/service/networkpeering/resource_network_peering.go +++ b/internal/service/networkpeering/resource_network_peering.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "strings" "time" @@ -277,7 +276,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di peer, resp, err := conn.NetworkPeeringApi.GetPeeringConnection(ctx, projectID, peerID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -444,7 +443,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. } peerConn, resp, getErr := conn.NetworkPeeringApi.GetPeeringConnection(ctx, projectID, peerID).Execute() if getErr != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return nil } } @@ -544,7 +543,7 @@ func resourceRefreshFunc(ctx context.Context, peerID, projectID, containerID str return func() (any, string, error) { c, resp, err := api.GetPeeringConnection(ctx, projectID, peerID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index f80b1cdfad..7e4f337d6d 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "strings" "time" @@ -266,10 +265,10 @@ func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, arch if err != nil && c == nil && resp == nil { return nil, "", err } else if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err @@ -293,7 +292,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di onlineArchive, resp, err := connV2.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index e364588092..db64d9d31f 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "strings" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -94,7 +93,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. conn := meta.(*config.MongoDBClient).AtlasV2 organization, resp, err := conn.OrganizationsApi.CreateOrganization(ctx, newCreateOrganizationRequest(d)).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound && !strings.Contains(err.Error(), "USER_NOT_FOUND") { + if config.StatusNotFound(resp) && !strings.Contains(err.Error(), "USER_NOT_FOUND") { d.SetId("") return nil } @@ -162,7 +161,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di organization, resp, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { log.Printf("warning Organization deleted will recreate: %s \n", err.Error()) d.SetId("") return nil diff --git a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go index 4b84b88b4a..013a0c4917 100644 --- a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go +++ b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "net/http" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -72,7 +71,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di setting, resp, err := conn.PrivateEndpointServicesApi.GetRegionalizedPrivateEndpointSetting(ctx, projectID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -102,7 +101,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. } _, resp, err := conn.PrivateEndpointServicesApi.ToggleRegionalizedPrivateEndpointSetting(ctx, projectID, &settingParam).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return nil } diff --git a/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go b/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go index eb3bb8e964..61c506c349 100644 --- a/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go +++ b/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "strings" "time" @@ -166,7 +165,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di privateEndpoint, resp, err := connV2.PrivateEndpointServicesApi.GetPrivateEndpointService(context.Background(), projectID, providerName, privateLinkID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -241,7 +240,7 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag. _, resp, err := connV2.PrivateEndpointServicesApi.DeletePrivateEndpointService(ctx, projectID, providerName, privateLinkID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return nil } @@ -310,7 +309,7 @@ func refreshFunc(ctx context.Context, client *admin.APIClient, projectID, provid return func() (any, string, error) { p, resp, err := client.PrivateEndpointServicesApi.GetPrivateEndpointService(ctx, projectID, providerName, privateLinkID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go b/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go index c7209ff762..22a3170db6 100644 --- a/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go +++ b/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go @@ -246,7 +246,7 @@ func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID return func() (any, string, error) { p, resp, err := client.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, privateLinkID).Execute() if err != nil { - if resp != nil && (resp.StatusCode == 404 || resp.StatusCode == 400) { + if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { return "", "DELETED", nil } return nil, "REJECTED", err diff --git a/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go b/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go index 7bedd882c3..07b2bfd57b 100644 --- a/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go +++ b/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "log" - "net/http" "strings" "time" @@ -218,7 +217,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di privateEndpoint, resp, err := connV2.PrivateEndpointServicesApi.GetPrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, privateLinkID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -375,7 +374,7 @@ func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID return func() (any, string, error) { i, resp, err := client.PrivateEndpointServicesApi.GetPrivateEndpoint(ctx, projectID, providerName, endpointServiceID, privateLinkID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go b/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go index 231cf22941..4121756627 100644 --- a/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go +++ b/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "net/http" "strings" "time" @@ -104,7 +103,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di privateEndpoint, resp, err := connV2.DataFederationApi.GetDataFederationPrivateEndpoint(ctx, projectID, endpointID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } @@ -125,7 +124,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. endpointID := ids["endpoint_id"] privateEndpoint, resp, err := connV2.DataFederationApi.GetDataFederationPrivateEndpoint(ctx, projectID, endpointID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go index 1885fa72c6..5a3de6f1ea 100644 --- a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go +++ b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go @@ -308,7 +308,7 @@ func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID return func() (any, string, error) { serverlessTenantEndpoint, resp, err := client.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointServiceID).Execute() if err != nil { - if resp != nil && resp.StatusCode == 404 || resp.StatusCode == 400 { + if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { return "", "DELETED", nil } @@ -335,10 +335,10 @@ func resourceListRefreshFunc(ctx context.Context, projectID string, client *admi if err != nil && serverlessInstances == nil && resp == nil { return nil, "", err } else if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 35b6b8d09a..00ea563dd1 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "log" - "net/http" "reflect" "sort" "time" @@ -209,7 +208,7 @@ func (r *projectRS) Read(ctx context.Context, req resource.ReadRequest, resp *re // get project projectRes, atlasResp, err := connV2.ProjectsApi.GetProject(ctx, projectID).Execute() if err != nil { - if atlasResp != nil && atlasResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(atlasResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/projectinvitation/resource_project_invitation.go b/internal/service/projectinvitation/resource_project_invitation.go index e49f4b06ba..5f90769c23 100644 --- a/internal/service/projectinvitation/resource_project_invitation.go +++ b/internal/service/projectinvitation/resource_project_invitation.go @@ -3,7 +3,6 @@ package projectinvitation import ( "context" "fmt" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -94,7 +93,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di projectInvitation, resp, err := connV2.ProjectsApi.GetProjectInvitation(ctx, projectID, invitationID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { // case 404: deleted in the backend case + if config.StatusNotFound(resp) { // case 404: deleted in the backend case d.SetId("") return nil } diff --git a/internal/service/pushbasedlogexport/resource.go b/internal/service/pushbasedlogexport/resource.go index b3c1e23646..7a5e032729 100644 --- a/internal/service/pushbasedlogexport/resource.go +++ b/internal/service/pushbasedlogexport/resource.go @@ -3,7 +3,6 @@ package pushbasedlogexport import ( "context" "log" - "net/http" "slices" "time" @@ -103,7 +102,7 @@ func (r *pushBasedLogExportRS) Read(ctx context.Context, req resource.ReadReques projectID := tfState.ProjectID.ValueString() logConfig, getResp, err := connV2.PushBasedLogExportApi.GetPushBasedLogConfiguration(ctx, projectID).Execute() if err != nil { - if getResp != nil && getResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/pushbasedlogexport/state_transition.go b/internal/service/pushbasedlogexport/state_transition.go index 623b4e887b..c07f718938 100644 --- a/internal/service/pushbasedlogexport/state_transition.go +++ b/internal/service/pushbasedlogexport/state_transition.go @@ -12,6 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) const ( @@ -66,7 +67,7 @@ func refreshFunc(ctx context.Context, projectID string, client admin.PushBasedLo return nil, "", err } if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/resourcepolicy/resource.go b/internal/service/resourcepolicy/resource.go index b181de673e..5a77fa4bed 100644 --- a/internal/service/resourcepolicy/resource.go +++ b/internal/service/resourcepolicy/resource.go @@ -4,14 +4,15 @@ import ( "context" "errors" "fmt" - "net/http" "regexp" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) var _ resource.ResourceWithConfigure = &resourcePolicyRS{} @@ -105,7 +106,7 @@ func (r *resourcePolicyRS) Read(ctx context.Context, req resource.ReadRequest, r policySDK, apiResp, err := connV2.ResourcePoliciesApi.GetAtlasResourcePolicy(ctx, orgID, resourcePolicyID).Execute() if err != nil { - if apiResp != nil && apiResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/searchdeployment/resource_search_deployment.go b/internal/service/searchdeployment/resource_search_deployment.go index 1695650233..f2feba5855 100644 --- a/internal/service/searchdeployment/resource_search_deployment.go +++ b/internal/service/searchdeployment/resource_search_deployment.go @@ -3,12 +3,12 @@ package searchdeployment import ( "context" "errors" - "net/http" "regexp" "time" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" @@ -95,7 +95,7 @@ func (r *searchDeploymentRS) Read(ctx context.Context, req resource.ReadRequest, clusterName := searchDeploymentPlan.ClusterName.ValueString() deploymentResp, getResp, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute() if err != nil { - if getResp != nil && getResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/searchdeployment/state_transition_search_deployment.go b/internal/service/searchdeployment/state_transition_search_deployment.go index 576fa8387f..9a77662b38 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment.go +++ b/internal/service/searchdeployment/state_transition_search_deployment.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -56,10 +57,10 @@ func searchDeploymentRefreshFunc(ctx context.Context, projectID, clusterName str return nil, "", err } if err != nil { - if resp != nil && resp.StatusCode == 404 && strings.Contains(err.Error(), SearchDeploymentDoesNotExistsError) { + if config.StatusNotFound(resp) && strings.Contains(err.Error(), SearchDeploymentDoesNotExistsError) { return "", retrystrategy.RetryStrategyDeletedState, nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", retrystrategy.RetryStrategyUpdatingState, nil } return nil, "", err diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index 39f6492d85..e7369e203b 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -307,7 +307,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di searchIndex, resp, err := connV2.AtlasSearchApi.GetAtlasSearchIndex(ctx, projectID, clusterName, indexID).Execute() if err != nil { // deleted in the backend case - if resp != nil && resp.StatusCode == 404 && !d.IsNewResource() { + if config.StatusNotFound(resp) && !d.IsNewResource() { d.SetId("") return nil } diff --git a/internal/service/serverlessinstance/resource_serverless_instance.go b/internal/service/serverlessinstance/resource_serverless_instance.go index ce737bb780..618a57ea9c 100644 --- a/internal/service/serverlessinstance/resource_serverless_instance.go +++ b/internal/service/serverlessinstance/resource_serverless_instance.go @@ -394,10 +394,10 @@ func resourceRefreshFunc(ctx context.Context, name, projectID string, connV2 *ad if err != nil && instance == nil && resp == nil { return nil, "", err } else if err != nil { - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return "", "DELETED", nil } - if resp != nil && resp.StatusCode == 503 { + if config.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/streamconnection/resource_stream_connection.go b/internal/service/streamconnection/resource_stream_connection.go index 3b9a96ee20..84ba677eea 100644 --- a/internal/service/streamconnection/resource_stream_connection.go +++ b/internal/service/streamconnection/resource_stream_connection.go @@ -3,16 +3,15 @@ package streamconnection import ( "context" "errors" - "net/http" "regexp" "time" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -145,7 +144,7 @@ func (r *streamConnectionRS) Read(ctx context.Context, req resource.ReadRequest, connectionName := streamConnectionState.ConnectionName.ValueString() apiResp, getResp, err := connV2.StreamsApi.GetStreamConnection(ctx, projectID, instanceName, connectionName).Execute() if err != nil { - if getResp != nil && getResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamconnection/state_transition.go b/internal/service/streamconnection/state_transition.go index c751bb484b..ea6ce84a86 100644 --- a/internal/service/streamconnection/state_transition.go +++ b/internal/service/streamconnection/state_transition.go @@ -5,6 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -17,7 +18,7 @@ func DeleteStreamConnection(ctx context.Context, api admin.StreamsApi, projectID if admin.IsErrorCode(err, "STREAM_KAFKA_CONNECTION_IS_DEPLOYING") { return retry.RetryableError(err) } - if resp != nil && resp.StatusCode == 404 { + if config.StatusNotFound(resp) { return nil } return retry.NonRetryableError(err) diff --git a/internal/service/streaminstance/resource_stream_instance.go b/internal/service/streaminstance/resource_stream_instance.go index d9f35ff7b2..f360bf54cd 100644 --- a/internal/service/streaminstance/resource_stream_instance.go +++ b/internal/service/streaminstance/resource_stream_instance.go @@ -3,11 +3,11 @@ package streaminstance import ( "context" "errors" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -74,7 +74,7 @@ func (r *streamInstanceRS) Read(ctx context.Context, req resource.ReadRequest, r instanceName := streamInstanceState.InstanceName.ValueString() apiResp, getResp, err := connV2.StreamsApi.GetStreamInstance(ctx, projectID, instanceName).Execute() if err != nil { - if getResp != nil && getResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamprivatelinkendpoint/resource.go b/internal/service/streamprivatelinkendpoint/resource.go index 88b0b20529..283b3194d6 100644 --- a/internal/service/streamprivatelinkendpoint/resource.go +++ b/internal/service/streamprivatelinkendpoint/resource.go @@ -3,14 +3,13 @@ package streamprivatelinkendpoint import ( "context" "errors" - "net/http" "regexp" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" @@ -108,7 +107,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. connV2 := r.Client.AtlasV2 streamsPrivateLinkConnection, apiResp, err := connV2.StreamsApi.GetPrivateLinkConnection(ctx, projectID, connectionID).Execute() if err != nil { - if apiResp != nil && apiResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamprivatelinkendpoint/state_transition.go b/internal/service/streamprivatelinkendpoint/state_transition.go index 92a27776d7..543565777e 100644 --- a/internal/service/streamprivatelinkendpoint/state_transition.go +++ b/internal/service/streamprivatelinkendpoint/state_transition.go @@ -3,11 +3,11 @@ package streamprivatelinkendpoint import ( "context" "errors" - "net/http" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -67,7 +67,7 @@ func refreshFunc(ctx context.Context, projectID, connectionID string, client adm return nil, "", err } if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return &admin.StreamsPrivateLinkConnection{}, retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/streamprocessor/resource.go b/internal/service/streamprocessor/resource.go index a9e35cfa45..9134f6a30e 100644 --- a/internal/service/streamprocessor/resource.go +++ b/internal/service/streamprocessor/resource.go @@ -4,14 +4,15 @@ import ( "context" "errors" "fmt" - "net/http" "regexp" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) const StreamProcessorName = "stream_processor" @@ -131,7 +132,7 @@ func (r *streamProcessorRS) Read(ctx context.Context, req resource.ReadRequest, instanceName := state.InstanceName.ValueString() streamProcessor, apiResp, err := connV2.StreamsApi.GetStreamProcessor(ctx, projectID, instanceName, state.ProcessorName.ValueString()).Execute() if err != nil { - if apiResp != nil && apiResp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamprocessor/state_transition.go b/internal/service/streamprocessor/state_transition.go index 00e11ee78c..c69aaef8ce 100644 --- a/internal/service/streamprocessor/state_transition.go +++ b/internal/service/streamprocessor/state_transition.go @@ -4,10 +4,10 @@ import ( "context" "errors" "fmt" - "net/http" "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -47,7 +47,7 @@ func refreshFunc(ctx context.Context, requestParams *admin.GetStreamProcessorApi return func() (any, string, error) { streamProcessor, resp, err := client.GetStreamProcessorWithParams(ctx, requestParams).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { return "", DroppedState, err } return nil, FailedState, err diff --git a/internal/service/team/resource_team.go b/internal/service/team/resource_team.go index ec94c47d00..94d0df6748 100644 --- a/internal/service/team/resource_team.go +++ b/internal/service/team/resource_team.go @@ -102,7 +102,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di team, resp, err := connV2.TeamsApi.GetTeamById(context.Background(), orgID, teamID).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/thirdpartyintegration/resource_third_party_integration.go b/internal/service/thirdpartyintegration/resource_third_party_integration.go index 13f2a3071d..066d884d19 100644 --- a/internal/service/thirdpartyintegration/resource_third_party_integration.go +++ b/internal/service/thirdpartyintegration/resource_third_party_integration.go @@ -3,7 +3,6 @@ package thirdpartyintegration import ( "context" "fmt" - "net/http" "regexp" "github.com/hashicorp/go-cty/cty" @@ -168,7 +167,7 @@ func resourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schem integration, resp, err := connV2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(ctx, projectID, integrationType).Execute() if err != nil { - if resp != nil && resp.StatusCode == http.StatusNotFound { + if config.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/tools/scaffold/template/resource.tmpl b/tools/scaffold/template/resource.tmpl index 2a73237ffa..5374f0a0d2 100644 --- a/tools/scaffold/template/resource.tmpl +++ b/tools/scaffold/template/resource.tmpl @@ -73,7 +73,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. // connV2 := r.Client.AtlasV2 //if err != nil { - // if apiResp != nil && apiResp.StatusCode == http.StatusNotFound { + // if config.StatusNotFound(apiResp) { // resp.State.RemoveResource(ctx) // return // } From 2d85b5ea55bdc693c6e4c765f7bceb8ee6aaae9c Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 7 Feb 2025 11:07:30 +0000 Subject: [PATCH 2/2] address PR comments --- .../{config => common/validate}/http_status_checks.go | 2 +- .../accesslistapikey/resource_access_list_api_key.go | 5 +++-- .../advancedcluster/data_source_advanced_cluster.go | 3 ++- .../advancedcluster/data_source_advanced_clusters.go | 3 ++- .../service/advancedcluster/model_advanced_cluster.go | 10 +++++----- .../advancedcluster/resource_advanced_cluster.go | 6 +++--- .../service/advancedclustertpf/common_await_changes.go | 9 ++++++--- .../alertconfiguration/resource_alert_configuration.go | 3 ++- internal/service/apikey/resource_api_key.go | 5 +++-- internal/service/auditing/resource_auditing.go | 3 ++- .../data_source_backup_compliance_policy.go | 3 ++- .../resource_backup_compliance_policy.go | 3 ++- .../resource_cloud_backup_schedule.go | 5 +++-- .../resource_cloud_backup_snapshot.go | 5 +++-- .../resource_cloud_backup_snapshot_export_bucket.go | 5 +++-- .../resource_cloud_backup_snapshot_restore_job.go | 3 ++- .../resource_cloud_provider_access_setup.go | 3 ++- .../resource_cluster_outage_simulation.go | 5 +++-- .../service/customdbrole/resource_custom_db_role.go | 3 ++- .../resource_custom_dns_configuration_cluster_aws.go | 3 ++- .../data_source_data_lake_pipeline_run.go | 3 ++- .../datalakepipeline/resource_data_lake_pipeline.go | 3 ++- internal/service/encryptionatrest/resource.go | 2 +- .../encryptionatrestprivateendpoint/resource.go | 3 ++- .../state_transition.go | 4 ++-- .../resource_federated_database_instance.go | 3 ++- .../resource_federated_query_limit.go | 3 ++- .../resource_federated_settings_identity_provider.go | 5 +++-- .../resource_federated_settings_connected_org.go | 3 ++- .../resource_federated_settings_org_role_mapping.go | 5 +++-- internal/service/flexcluster/resource.go | 3 ++- internal/service/flexcluster/state_transition.go | 4 ++-- .../data_source_global_cluster_config.go | 5 +++-- .../resource_global_cluster_config.go | 5 +++-- .../ldapconfiguration/resource_ldap_configuration.go | 3 ++- internal/service/ldapverify/resource_ldap_verify.go | 5 +++-- .../maintenancewindow/resource_maintenance_window.go | 3 ++- .../service/mongodbemployeeaccessgrant/resource.go | 3 ++- .../networkcontainer/data_source_network_container.go | 3 ++- .../networkcontainer/resource_network_container.go | 5 +++-- .../networkpeering/data_source_network_peering.go | 3 ++- .../service/networkpeering/resource_network_peering.go | 7 ++++--- .../service/onlinearchive/resource_online_archive.go | 7 ++++--- internal/service/organization/resource_organization.go | 5 +++-- .../resource_private_endpoint_regional_mode.go | 5 +++-- .../resource_privatelink_endpoint.go | 7 ++++--- .../resource_privatelink_endpoint_serverless.go | 3 ++- .../resource_privatelink_endpoint_service.go | 5 +++-- ..._endpoint_service_data_federation_online_archive.go | 4 ++-- ...resource_privatelink_endpoint_service_serverless.go | 7 ++++--- internal/service/project/resource_project.go | 3 ++- .../projectinvitation/resource_project_invitation.go | 3 ++- internal/service/pushbasedlogexport/resource.go | 3 ++- .../service/pushbasedlogexport/state_transition.go | 4 ++-- internal/service/resourcepolicy/resource.go | 3 ++- .../searchdeployment/resource_search_deployment.go | 3 ++- .../state_transition_search_deployment.go | 6 +++--- internal/service/searchindex/resource_search_index.go | 3 ++- .../serverlessinstance/resource_serverless_instance.go | 5 +++-- .../streamconnection/resource_stream_connection.go | 3 ++- internal/service/streamconnection/state_transition.go | 4 ++-- .../service/streaminstance/resource_stream_instance.go | 3 ++- internal/service/streamprivatelinkendpoint/resource.go | 3 ++- .../streamprivatelinkendpoint/state_transition.go | 4 ++-- internal/service/streamprocessor/resource.go | 3 ++- internal/service/streamprocessor/state_transition.go | 4 ++-- internal/service/team/resource_team.go | 3 ++- .../resource_third_party_integration.go | 3 ++- tools/scaffold/template/resource.tmpl | 4 +++- 69 files changed, 170 insertions(+), 110 deletions(-) rename internal/{config => common/validate}/http_status_checks.go (95%) diff --git a/internal/config/http_status_checks.go b/internal/common/validate/http_status_checks.go similarity index 95% rename from internal/config/http_status_checks.go rename to internal/common/validate/http_status_checks.go index e738656177..0c52d0d626 100644 --- a/internal/config/http_status_checks.go +++ b/internal/common/validate/http_status_checks.go @@ -1,4 +1,4 @@ -package config +package validate import "net/http" diff --git a/internal/service/accesslistapikey/resource_access_list_api_key.go b/internal/service/accesslistapikey/resource_access_list_api_key.go index 9780a65eb0..f01f1c10e0 100644 --- a/internal/service/accesslistapikey/resource_access_list_api_key.go +++ b/internal/service/accesslistapikey/resource_access_list_api_key.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -105,7 +106,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. _, resp, err := connV2.ProgrammaticAPIKeysApi.CreateApiKeyAccessList(ctx, orgID, apiKeyID, accessList).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -130,7 +131,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di apiKey, resp, err := connV2.ProgrammaticAPIKeysApi.GetApiKeyAccessList(ctx, orgID, ipAddress, apiKeyID).Execute() if err != nil { - if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { + if validate.StatusNotFound(resp) || validate.StatusBadRequest(resp) { d.SetId("") return nil } diff --git a/internal/service/advancedcluster/data_source_advanced_cluster.go b/internal/service/advancedcluster/data_source_advanced_cluster.go index eab11a3165..cdcff14563 100644 --- a/internal/service/advancedcluster/data_source_advanced_cluster.go +++ b/internal/service/advancedcluster/data_source_advanced_cluster.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -293,7 +294,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. clusterDesc, resp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } return diag.FromErr(fmt.Errorf(errorRead, clusterName, err)) diff --git a/internal/service/advancedcluster/data_source_advanced_clusters.go b/internal/service/advancedcluster/data_source_advanced_clusters.go index 02541754fb..1ed2693c12 100644 --- a/internal/service/advancedcluster/data_source_advanced_clusters.go +++ b/internal/service/advancedcluster/data_source_advanced_clusters.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -309,7 +310,7 @@ func dataSourcePluralRead(ctx context.Context, d *schema.ResourceData, meta any) list, resp, err := connV2.ClustersApi.ListClusters(ctx, projectID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } return diag.FromErr(fmt.Errorf(errorListRead, projectID, err)) diff --git a/internal/service/advancedcluster/model_advanced_cluster.go b/internal/service/advancedcluster/model_advanced_cluster.go index 5ea4a78f6b..dc9f92fead 100644 --- a/internal/service/advancedcluster/model_advanced_cluster.go +++ b/internal/service/advancedcluster/model_advanced_cluster.go @@ -21,7 +21,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedclustertpf" ) @@ -359,10 +359,10 @@ func UpgradeRefreshFunc(ctx context.Context, name, projectID string, client admi if err != nil && cluster == nil && resp == nil { return nil, "", err } else if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err @@ -386,10 +386,10 @@ func ResourceClusterListAdvancedRefreshFunc(ctx context.Context, projectID strin } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/advancedcluster/resource_advanced_cluster.go b/internal/service/advancedcluster/resource_advanced_cluster.go index 071c908ea0..a035d87470 100644 --- a/internal/service/advancedcluster/resource_advanced_cluster.go +++ b/internal/service/advancedcluster/resource_advanced_cluster.go @@ -608,7 +608,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di cluster, resp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -1343,10 +1343,10 @@ func resourceRefreshFunc(ctx context.Context, name, projectID string, connV2 *ad } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/advancedclustertpf/common_await_changes.go b/internal/service/advancedclustertpf/common_await_changes.go index 8febc036a9..2a6aee8541 100644 --- a/internal/service/advancedclustertpf/common_await_changes.go +++ b/internal/service/advancedclustertpf/common_await_changes.go @@ -7,11 +7,14 @@ import ( "strings" "time" + "go.mongodb.org/atlas-sdk/v20241113004/admin" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" - "go.mongodb.org/atlas-sdk/v20241113004/admin" ) var ( @@ -88,10 +91,10 @@ func resourceRefreshFunc(ctx context.Context, name, projectID string, api admin. } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", retrystrategy.RetryStrategyDeletedState, nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", retrystrategy.RetryStrategyPendingState, nil } return nil, "", err diff --git a/internal/service/alertconfiguration/resource_alert_configuration.go b/internal/service/alertconfiguration/resource_alert_configuration.go index 70cb01ba62..2675607ed3 100644 --- a/internal/service/alertconfiguration/resource_alert_configuration.go +++ b/internal/service/alertconfiguration/resource_alert_configuration.go @@ -21,6 +21,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -431,7 +432,7 @@ func (r *alertConfigurationRS) Read(ctx context.Context, req resource.ReadReques alert, getResp, err := connV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), ids[EncodedIDKeyProjectID], ids[EncodedIDKeyAlertID]).Execute() if err != nil { // deleted in the backend case - if config.StatusNotFound(getResp) { + if validate.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/apikey/resource_api_key.go b/internal/service/apikey/resource_api_key.go index 180396f559..b255862531 100644 --- a/internal/service/apikey/resource_api_key.go +++ b/internal/service/apikey/resource_api_key.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -68,7 +69,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. apiKey, resp, err := connV2.ProgrammaticAPIKeysApi.CreateApiKey(ctx, orgID, createRequest).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -96,7 +97,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di apiKey, resp, err := connV2.ProgrammaticAPIKeysApi.GetApiKey(ctx, orgID, apiKeyID).Execute() if err != nil { - if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { + if validate.StatusNotFound(resp) || validate.StatusBadRequest(resp) { log.Printf("warning API key deleted will recreate: %s \n", err.Error()) d.SetId("") return nil diff --git a/internal/service/auditing/resource_auditing.go b/internal/service/auditing/resource_auditing.go index 7fd59e5f4e..4e3a9ee4bf 100644 --- a/internal/service/auditing/resource_auditing.go +++ b/internal/service/auditing/resource_auditing.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -86,7 +87,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di connV2 := meta.(*config.MongoDBClient).AtlasV2 auditing, resp, err := connV2.AuditingApi.GetAuditingConfiguration(ctx, d.Id()).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go b/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go index 7bdbb76ab7..3844149541 100644 --- a/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go +++ b/internal/service/backupcompliancepolicy/data_source_backup_compliance_policy.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupschedule" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cluster" @@ -237,7 +238,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. projectID := d.Get("project_id").(string) policy, resp, err := connV2.CloudBackupsApi.GetDataProtectionSettings(ctx, projectID).Execute() - if config.StatusNotFound(resp) || policy.GetProjectId() == "" { + if validate.StatusNotFound(resp) || policy.GetProjectId() == "" { return nil } if err != nil { diff --git a/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go b/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go index a1d18f8a6e..f83d16447c 100644 --- a/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go +++ b/internal/service/backupcompliancepolicy/resource_backup_compliance_policy.go @@ -13,6 +13,7 @@ import ( "github.com/spf13/cast" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/cloudbackupschedule" ) @@ -282,7 +283,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di policy, resp, err := connV2.CloudBackupsApi.GetDataProtectionSettings(ctx, projectID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go b/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go index 6f601c5630..4ccc7c9418 100644 --- a/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go +++ b/internal/service/cloudbackupschedule/resource_cloud_backup_schedule.go @@ -11,6 +11,7 @@ import ( "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/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/spf13/cast" admin20240530 "go.mongodb.org/atlas-sdk/v20240530005/admin" @@ -376,7 +377,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di return diag.Errorf("%s : %s : %s", errorSnapshotBackupScheduleRead, ErrorOperationNotPermitted, AsymmetricShardsUnsupportedAction) } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -388,7 +389,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di } else { backupSchedule, resp, err = connV2.CloudBackupsApi.GetBackupSchedule(context.Background(), projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go b/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go index 385c8a4857..2f86cac294 100644 --- a/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go +++ b/internal/service/cloudbackupsnapshot/resource_cloud_backup_snapshot.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -177,7 +178,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di snapshot, resp, err := connV2.CloudBackupsApi.GetReplicaSetBackup(ctx, groupID, clusterName, snapshotID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -294,7 +295,7 @@ func resourceRefreshFunc(ctx context.Context, requestParams *admin.GetReplicaSet if err != nil { return nil, "failed", err } - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } status := snapshot.GetStatus() diff --git a/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go b/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go index fe39928450..031c2ed995 100644 --- a/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go +++ b/internal/service/cloudbackupsnapshotexportbucket/resource_cloud_backup_snapshot_export_bucket.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -228,7 +229,7 @@ func resourceRefresh(ctx context.Context, client *admin.APIClient, projectID, ex clustersPaginated, resp, err := client.ClustersApi.ListClusters(ctx, projectID).Execute() if err != nil { // For our purposes, no clusters is equivalent to all changes having been APPLIED - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "APPLIED", nil } return nil, "REPEATING", err @@ -257,7 +258,7 @@ func resourceRefresh(ctx context.Context, client *admin.APIClient, projectID, ex } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go index 3a934463a6..4106f5cbb6 100644 --- a/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go +++ b/internal/service/cloudbackupsnapshotrestorejob/resource_cloud_backup_snapshot_restore_job.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -162,7 +163,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di restoreID := ids["snapshot_restore_job_id"] snapshotReq, resp, err := conn.CloudBackupsApi.GetBackupRestoreJob(ctx, projectID, clusterName, restoreID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go index f30d530d0e..d471fd054e 100644 --- a/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go +++ b/internal/service/cloudprovideraccess/resource_cloud_provider_access_setup.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -110,7 +111,7 @@ func resourceCloudProviderAccessSetupRead(ctx context.Context, d *schema.Resourc role, resp, err := conn.CloudProviderAccessApi.GetCloudProviderAccessRole(context.Background(), projectID, roleID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go b/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go index fdbbcd344b..38de0fc3f7 100644 --- a/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go +++ b/internal/service/clusteroutagesimulation/resource_cluster_outage_simulation.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -139,7 +140,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di outageSimulation, resp, err := connV2.ClusterOutageSimulationApi.GetOutageSimulation(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -198,7 +199,7 @@ func resourceRefreshFunc(ctx context.Context, clusterName, projectID string, cli outageSimulation, resp, err := client.ClusterOutageSimulationApi.GetOutageSimulation(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } return nil, "", err diff --git a/internal/service/customdbrole/resource_custom_db_role.go b/internal/service/customdbrole/resource_custom_db_role.go index 6a2b1c9890..c854c408d5 100644 --- a/internal/service/customdbrole/resource_custom_db_role.go +++ b/internal/service/customdbrole/resource_custom_db_role.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/spf13/cast" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -156,7 +157,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di customDBRole, resp, err := connV2.CustomDatabaseRolesApi.GetCustomDatabaseRole(ctx, projectID, roleName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go b/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go index c414f465d0..8d0379185b 100644 --- a/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go +++ b/internal/service/customdnsconfigurationclusteraws/resource_custom_dns_configuration_cluster_aws.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -61,7 +62,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di projectID := d.Id() dnsResp, resp, err := connV2.AWSClustersDNSApi.GetAwsCustomDns(context.Background(), projectID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go b/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go index 116bba9f7e..d5b3a9da96 100644 --- a/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go +++ b/internal/service/datalakepipeline/data_source_data_lake_pipeline_run.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -95,7 +96,7 @@ func dataSourceRunRead(ctx context.Context, d *schema.ResourceData, meta any) di run, resp, err := connV2.DataLakePipelinesApi.GetPipelineRun(ctx, projectID, name, pipelineRunID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/datalakepipeline/resource_data_lake_pipeline.go b/internal/service/datalakepipeline/resource_data_lake_pipeline.go index b5d618f3ee..557a155d3b 100644 --- a/internal/service/datalakepipeline/resource_data_lake_pipeline.go +++ b/internal/service/datalakepipeline/resource_data_lake_pipeline.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -288,7 +289,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di name := ids["name"] pipeline, resp, err := connV2.DataLakePipelinesApi.GetPipeline(ctx, projectID, name).Execute() - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/encryptionatrest/resource.go b/internal/service/encryptionatrest/resource.go index 66e6d0d12d..a5ee02b5af 100644 --- a/internal/service/encryptionatrest/resource.go +++ b/internal/service/encryptionatrest/resource.go @@ -339,7 +339,7 @@ func (r *encryptionAtRestRS) Read(ctx context.Context, req resource.ReadRequest, encryptionResp, getResp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRest(context.Background(), projectID).Execute() if err != nil { - if config.StatusNotFound(getResp) { + if validate.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/encryptionatrestprivateendpoint/resource.go b/internal/service/encryptionatrestprivateendpoint/resource.go index f7d6bb10aa..3d09e59bf5 100644 --- a/internal/service/encryptionatrestprivateendpoint/resource.go +++ b/internal/service/encryptionatrestprivateendpoint/resource.go @@ -13,6 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -89,7 +90,7 @@ func (r *encryptionAtRestPrivateEndpointRS) Read(ctx context.Context, req resour endpointModel, apiResp, err := connV2.EncryptionAtRestUsingCustomerKeyManagementApi.GetEncryptionAtRestPrivateEndpoint(ctx, projectID, cloudProvider, endpointID).Execute() if err != nil { - if config.StatusNotFound(apiResp) { + if validate.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/encryptionatrestprivateendpoint/state_transition.go b/internal/service/encryptionatrestprivateendpoint/state_transition.go index a5b6bc7013..2f289a5ed7 100644 --- a/internal/service/encryptionatrestprivateendpoint/state_transition.go +++ b/internal/service/encryptionatrestprivateendpoint/state_transition.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -67,7 +67,7 @@ func refreshFunc(ctx context.Context, projectID, cloudProvider, endpointID strin return nil, "", err } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return &admin.EARPrivateEndpoint{}, retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go index 2bb26b27f1..e38168defb 100644 --- a/internal/service/federateddatabaseinstance/resource_federated_database_instance.go +++ b/internal/service/federateddatabaseinstance/resource_federated_database_instance.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -401,7 +402,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di dataFederationInstance, resp, err := connV2.DataFederationApi.GetFederatedDatabase(ctx, projectID, name).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedquerylimit/resource_federated_query_limit.go b/internal/service/federatedquerylimit/resource_federated_query_limit.go index 5a66c92007..25f6fa719e 100644 --- a/internal/service/federatedquerylimit/resource_federated_query_limit.go +++ b/internal/service/federatedquerylimit/resource_federated_query_limit.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -108,7 +109,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di queryLimit, resp, err := conn.DataFederationApi.ReturnFederatedDatabaseQueryLimit(ctx, projectID, tenantName, limitName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go index 9a459a97bf..53f3a187d1 100644 --- a/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go +++ b/internal/service/federatedsettingsidentityprovider/resource_federated_settings_identity_provider.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/cast" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -151,7 +152,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di if err != nil { // case 404 // deleted in the backend case - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -358,7 +359,7 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag. federationSettingsID, idpID := DecodeIDs(d.Id()) resp, err := connV2.FederatedAuthenticationApi.DeleteIdentityProvider(ctx, federationSettingsID, idpID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go index 930e4835dd..6c006afaca 100644 --- a/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go +++ b/internal/service/federatedsettingsorgconfig/resource_federated_settings_connected_org.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/spf13/cast" ) @@ -81,7 +82,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di federatedSettingsConnectedOrganization, resp, err := conn.FederatedAuthenticationApi.GetConnectedOrgConfig(context.Background(), federationSettingsID, orgID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go index 22f4c93c13..7b2de74235 100644 --- a/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go +++ b/internal/service/federatedsettingsorgrolemapping/resource_federated_settings_org_role_mapping.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -81,7 +82,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di federatedSettingsOrganizationRoleMapping, resp, err := conn.FederatedAuthenticationApi.GetRoleMapping(context.Background(), federationSettingsID, roleMappingID, orgID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -132,7 +133,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. } federatedSettingsOrganizationRoleMapping, resp, err := conn.FederatedAuthenticationApi.CreateRoleMapping(ctx, federationSettingsID.(string), orgID.(string), &roleMapping).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/flexcluster/resource.go b/internal/service/flexcluster/resource.go index a43d69b815..9c4d30b089 100644 --- a/internal/service/flexcluster/resource.go +++ b/internal/service/flexcluster/resource.go @@ -13,6 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -96,7 +97,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. connV2 := r.Client.AtlasV2 flexCluster, apiResp, err := connV2.FlexClustersApi.GetFlexCluster(ctx, flexClusterState.ProjectId.ValueString(), flexClusterState.Name.ValueString()).Execute() if err != nil { - if config.StatusNotFound(apiResp) { + if validate.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/flexcluster/state_transition.go b/internal/service/flexcluster/state_transition.go index c3fe2fc66a..14131265df 100644 --- a/internal/service/flexcluster/state_transition.go +++ b/internal/service/flexcluster/state_transition.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -50,7 +50,7 @@ func refreshFunc(ctx context.Context, requestParams *admin.GetFlexClusterApiPara return func() (any, string, error) { flexCluster, resp, err := client.GetFlexClusterWithParams(ctx, requestParams).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/globalclusterconfig/data_source_global_cluster_config.go b/internal/service/globalclusterconfig/data_source_global_cluster_config.go index 7791b5bf42..a226854fc9 100644 --- a/internal/service/globalclusterconfig/data_source_global_cluster_config.go +++ b/internal/service/globalclusterconfig/data_source_global_cluster_config.go @@ -8,6 +8,7 @@ import ( "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/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -75,7 +76,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. resp, httpResp, err := connV2.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(httpResp) { + if validate.StatusNotFound(httpResp) { d.SetId("") return nil } @@ -83,7 +84,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. } oldResp, httpResp, err := connV220240530.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(httpResp) { + if validate.StatusNotFound(httpResp) { d.SetId("") return nil } diff --git a/internal/service/globalclusterconfig/resource_global_cluster_config.go b/internal/service/globalclusterconfig/resource_global_cluster_config.go index d3e2661085..d7d756bbfc 100644 --- a/internal/service/globalclusterconfig/resource_global_cluster_config.go +++ b/internal/service/globalclusterconfig/resource_global_cluster_config.go @@ -15,6 +15,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -181,7 +182,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di resp, httpResp, err := connV2.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(httpResp) { + if validate.StatusNotFound(httpResp) { d.SetId("") return nil } @@ -189,7 +190,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di } oldResp, httpResp, err := connV220240530.GlobalClustersApi.GetManagedNamespace(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(httpResp) { + if validate.StatusNotFound(httpResp) { d.SetId("") return nil } diff --git a/internal/service/ldapconfiguration/resource_ldap_configuration.go b/internal/service/ldapconfiguration/resource_ldap_configuration.go index b7aecb7562..d9cf180a56 100644 --- a/internal/service/ldapconfiguration/resource_ldap_configuration.go +++ b/internal/service/ldapconfiguration/resource_ldap_configuration.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -157,7 +158,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di connV2 := meta.(*config.MongoDBClient).AtlasV2 resp, httpResp, err := connV2.LDAPConfigurationApi.GetLdapConfiguration(context.Background(), d.Id()).Execute() if err != nil { - if config.StatusNotFound(httpResp) { + if validate.StatusNotFound(httpResp) { d.SetId("") return nil } diff --git a/internal/service/ldapverify/resource_ldap_verify.go b/internal/service/ldapverify/resource_ldap_verify.go index 396083b805..20904b07bc 100644 --- a/internal/service/ldapverify/resource_ldap_verify.go +++ b/internal/service/ldapverify/resource_ldap_verify.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -169,7 +170,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di requestID := ids["request_id"] ldapResp, resp, err := connV2.LDAPConfigurationApi.GetLdapConfigurationStatus(context.Background(), projectID, requestID).Execute() if err != nil || ldapResp == nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -251,7 +252,7 @@ func resourceRefreshFunc(ctx context.Context, projectID, requestID string, connV return func() (any, string, error) { ldap, resp, err := connV2.LDAPConfigurationApi.GetLdapConfigurationStatus(ctx, projectID, requestID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } return nil, "", err diff --git a/internal/service/maintenancewindow/resource_maintenance_window.go b/internal/service/maintenancewindow/resource_maintenance_window.go index c3aeef7eaa..11ced3b2e9 100644 --- a/internal/service/maintenancewindow/resource_maintenance_window.go +++ b/internal/service/maintenancewindow/resource_maintenance_window.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/spf13/cast" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -135,7 +136,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di maintenanceWindow, resp, err := connV2.MaintenanceWindowsApi.GetMaintenanceWindow(context.Background(), projectID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/mongodbemployeeaccessgrant/resource.go b/internal/service/mongodbemployeeaccessgrant/resource.go index 87037c0cb9..f29994214e 100644 --- a/internal/service/mongodbemployeeaccessgrant/resource.go +++ b/internal/service/mongodbemployeeaccessgrant/resource.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -55,7 +56,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. projectID := tfModel.ProjectID.ValueString() clusterName := tfModel.ClusterName.ValueString() cluster, httpResp, err := connV2.ClustersApi.GetCluster(ctx, projectID, clusterName).Execute() - if config.StatusNotFound(httpResp) { + if validate.StatusNotFound(httpResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/networkcontainer/data_source_network_container.go b/internal/service/networkcontainer/data_source_network_container.go index a08183458a..22b5023d94 100644 --- a/internal/service/networkcontainer/data_source_network_container.go +++ b/internal/service/networkcontainer/data_source_network_container.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -80,7 +81,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. container, resp, err := connV2.NetworkPeeringApi.GetPeeringContainer(ctx, projectID, containerID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } return diag.FromErr(fmt.Errorf(ErrorContainerRead, containerID, err)) diff --git a/internal/service/networkcontainer/resource_network_container.go b/internal/service/networkcontainer/resource_network_container.go index fec5f57bea..fc73824ee9 100644 --- a/internal/service/networkcontainer/resource_network_container.go +++ b/internal/service/networkcontainer/resource_network_container.go @@ -18,6 +18,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -159,7 +160,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di container, resp, err := connV2.NetworkPeeringApi.GetPeeringContainer(ctx, projectID, containerID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -324,7 +325,7 @@ func resourceRefreshFunc(ctx context.Context, d *schema.ResourceData, client *ad var err error container, res, err := client.NetworkPeeringApi.GetPeeringContainer(ctx, projectID, containerID).Execute() if err != nil { - if config.StatusNotFound(res) { + if validate.StatusNotFound(res) { return "", "deleted", nil } diff --git a/internal/service/networkpeering/data_source_network_peering.go b/internal/service/networkpeering/data_source_network_peering.go index 6679a443f4..dad4eedb4b 100644 --- a/internal/service/networkpeering/data_source_network_peering.go +++ b/internal/service/networkpeering/data_source_network_peering.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -116,7 +117,7 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag. peer, resp, err := conn.NetworkPeeringApi.GetPeeringConnection(ctx, projectID, peerID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } diff --git a/internal/service/networkpeering/resource_network_peering.go b/internal/service/networkpeering/resource_network_peering.go index 5db72710e3..845d41db6f 100644 --- a/internal/service/networkpeering/resource_network_peering.go +++ b/internal/service/networkpeering/resource_network_peering.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/networkcontainer" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -276,7 +277,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di peer, resp, err := conn.NetworkPeeringApi.GetPeeringConnection(ctx, projectID, peerID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -443,7 +444,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. } peerConn, resp, getErr := conn.NetworkPeeringApi.GetPeeringConnection(ctx, projectID, peerID).Execute() if getErr != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } } @@ -543,7 +544,7 @@ func resourceRefreshFunc(ctx context.Context, peerID, projectID, containerID str return func() (any, string, error) { c, resp, err := api.GetPeeringConnection(ctx, projectID, peerID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/onlinearchive/resource_online_archive.go b/internal/service/onlinearchive/resource_online_archive.go index 7e4f337d6d..05c0b7cb61 100644 --- a/internal/service/onlinearchive/resource_online_archive.go +++ b/internal/service/onlinearchive/resource_online_archive.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -265,10 +266,10 @@ func resourceOnlineRefreshFunc(ctx context.Context, projectID, clusterName, arch if err != nil && c == nil && resp == nil { return nil, "", err } else if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err @@ -292,7 +293,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di onlineArchive, resp, err := connV2.OnlineArchiveApi.GetOnlineArchive(context.Background(), projectID, archiveID, clusterName).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/organization/resource_organization.go b/internal/service/organization/resource_organization.go index db64d9d31f..286e8338f8 100644 --- a/internal/service/organization/resource_organization.go +++ b/internal/service/organization/resource_organization.go @@ -13,6 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -93,7 +94,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag. conn := meta.(*config.MongoDBClient).AtlasV2 organization, resp, err := conn.OrganizationsApi.CreateOrganization(ctx, newCreateOrganizationRequest(d)).Execute() if err != nil { - if config.StatusNotFound(resp) && !strings.Contains(err.Error(), "USER_NOT_FOUND") { + if validate.StatusNotFound(resp) && !strings.Contains(err.Error(), "USER_NOT_FOUND") { d.SetId("") return nil } @@ -161,7 +162,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di organization, resp, err := conn.OrganizationsApi.GetOrganization(ctx, orgID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { log.Printf("warning Organization deleted will recreate: %s \n", err.Error()) d.SetId("") return nil diff --git a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go index 013a0c4917..103ae01277 100644 --- a/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go +++ b/internal/service/privateendpointregionalmode/resource_private_endpoint_regional_mode.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -71,7 +72,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di setting, resp, err := conn.PrivateEndpointServicesApi.GetRegionalizedPrivateEndpointSetting(ctx, projectID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -101,7 +102,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. } _, resp, err := conn.PrivateEndpointServicesApi.ToggleRegionalizedPrivateEndpointSetting(ctx, projectID, &settingParam).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } diff --git a/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go b/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go index 61c506c349..f93266e626 100644 --- a/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go +++ b/internal/service/privatelinkendpoint/resource_privatelink_endpoint.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -165,7 +166,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di privateEndpoint, resp, err := connV2.PrivateEndpointServicesApi.GetPrivateEndpointService(context.Background(), projectID, providerName, privateLinkID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -240,7 +241,7 @@ func resourceDelete(ctx context.Context, d *schema.ResourceData, meta any) diag. _, resp, err := connV2.PrivateEndpointServicesApi.DeletePrivateEndpointService(ctx, projectID, providerName, privateLinkID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } @@ -309,7 +310,7 @@ func refreshFunc(ctx context.Context, client *admin.APIClient, projectID, provid return func() (any, string, error) { p, resp, err := client.PrivateEndpointServicesApi.GetPrivateEndpointService(ctx, projectID, providerName, privateLinkID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go b/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go index 22a3170db6..5dbd68b8a6 100644 --- a/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go +++ b/internal/service/privatelinkendpointserverless/resource_privatelink_endpoint_serverless.go @@ -17,6 +17,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpoint" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/privatelinkendpointserviceserverless" @@ -246,7 +247,7 @@ func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID return func() (any, string, error) { p, resp, err := client.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, privateLinkID).Execute() if err != nil { - if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { + if validate.StatusNotFound(resp) || validate.StatusBadRequest(resp) { return "", "DELETED", nil } return nil, "REJECTED", err diff --git a/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go b/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go index 07b2bfd57b..6965eff939 100644 --- a/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go +++ b/internal/service/privatelinkendpointservice/resource_privatelink_endpoint_service.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -217,7 +218,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di privateEndpoint, resp, err := connV2.PrivateEndpointServicesApi.GetPrivateEndpoint(context.Background(), projectID, providerName, endpointServiceID, privateLinkID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -374,7 +375,7 @@ func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID return func() (any, string, error) { i, resp, err := client.PrivateEndpointServicesApi.GetPrivateEndpoint(ctx, projectID, providerName, endpointServiceID, privateLinkID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } diff --git a/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go b/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go index 4121756627..273e4ee6f2 100644 --- a/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go +++ b/internal/service/privatelinkendpointservicedatafederationonlinearchive/resource_privatelink_endpoint_service_data_federation_online_archive.go @@ -103,7 +103,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di privateEndpoint, resp, err := connV2.DataFederationApi.GetDataFederationPrivateEndpoint(ctx, projectID, endpointID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } @@ -124,7 +124,7 @@ func resourceUpdate(ctx context.Context, d *schema.ResourceData, meta any) diag. endpointID := ids["endpoint_id"] privateEndpoint, resp, err := connV2.DataFederationApi.GetDataFederationPrivateEndpoint(ctx, projectID, endpointID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go index 5a3de6f1ea..bda0c5b2f3 100644 --- a/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go +++ b/internal/service/privatelinkendpointserviceserverless/resource_privatelink_endpoint_service_serverless.go @@ -17,6 +17,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -308,7 +309,7 @@ func resourceRefreshFunc(ctx context.Context, client *admin.APIClient, projectID return func() (any, string, error) { serverlessTenantEndpoint, resp, err := client.ServerlessPrivateEndpointsApi.GetServerlessPrivateEndpoint(ctx, projectID, instanceName, endpointServiceID).Execute() if err != nil { - if config.StatusNotFound(resp) || config.StatusBadRequest(resp) { + if validate.StatusNotFound(resp) || validate.StatusBadRequest(resp) { return "", "DELETED", nil } @@ -335,10 +336,10 @@ func resourceListRefreshFunc(ctx context.Context, projectID string, client *admi if err != nil && serverlessInstances == nil && resp == nil { return nil, "", err } else if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/project/resource_project.go b/internal/service/project/resource_project.go index 00ea563dd1..9053c01e38 100644 --- a/internal/service/project/resource_project.go +++ b/internal/service/project/resource_project.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -208,7 +209,7 @@ func (r *projectRS) Read(ctx context.Context, req resource.ReadRequest, resp *re // get project projectRes, atlasResp, err := connV2.ProjectsApi.GetProject(ctx, projectID).Execute() if err != nil { - if config.StatusNotFound(atlasResp) { + if validate.StatusNotFound(atlasResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/projectinvitation/resource_project_invitation.go b/internal/service/projectinvitation/resource_project_invitation.go index 5f90769c23..30cd66c906 100644 --- a/internal/service/projectinvitation/resource_project_invitation.go +++ b/internal/service/projectinvitation/resource_project_invitation.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -93,7 +94,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di projectInvitation, resp, err := connV2.ProjectsApi.GetProjectInvitation(ctx, projectID, invitationID).Execute() if err != nil { - if config.StatusNotFound(resp) { // case 404: deleted in the backend case + if validate.StatusNotFound(resp) { // case 404: deleted in the backend case d.SetId("") return nil } diff --git a/internal/service/pushbasedlogexport/resource.go b/internal/service/pushbasedlogexport/resource.go index 7a5e032729..23895be88c 100644 --- a/internal/service/pushbasedlogexport/resource.go +++ b/internal/service/pushbasedlogexport/resource.go @@ -13,6 +13,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -102,7 +103,7 @@ func (r *pushBasedLogExportRS) Read(ctx context.Context, req resource.ReadReques projectID := tfState.ProjectID.ValueString() logConfig, getResp, err := connV2.PushBasedLogExportApi.GetPushBasedLogConfiguration(ctx, projectID).Execute() if err != nil { - if config.StatusNotFound(getResp) { + if validate.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/pushbasedlogexport/state_transition.go b/internal/service/pushbasedlogexport/state_transition.go index c07f718938..2184ddc846 100644 --- a/internal/service/pushbasedlogexport/state_transition.go +++ b/internal/service/pushbasedlogexport/state_transition.go @@ -12,7 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" ) const ( @@ -67,7 +67,7 @@ func refreshFunc(ctx context.Context, projectID string, client admin.PushBasedLo return nil, "", err } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/resourcepolicy/resource.go b/internal/service/resourcepolicy/resource.go index 5a77fa4bed..d5f7350709 100644 --- a/internal/service/resourcepolicy/resource.go +++ b/internal/service/resourcepolicy/resource.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -106,7 +107,7 @@ func (r *resourcePolicyRS) Read(ctx context.Context, req resource.ReadRequest, r policySDK, apiResp, err := connV2.ResourcePoliciesApi.GetAtlasResourcePolicy(ctx, orgID, resourcePolicyID).Execute() if err != nil { - if config.StatusNotFound(apiResp) { + if validate.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/searchdeployment/resource_search_deployment.go b/internal/service/searchdeployment/resource_search_deployment.go index f2feba5855..ec9c58bc4f 100644 --- a/internal/service/searchdeployment/resource_search_deployment.go +++ b/internal/service/searchdeployment/resource_search_deployment.go @@ -11,6 +11,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -95,7 +96,7 @@ func (r *searchDeploymentRS) Read(ctx context.Context, req resource.ReadRequest, clusterName := searchDeploymentPlan.ClusterName.ValueString() deploymentResp, getResp, err := connV2.AtlasSearchApi.GetAtlasSearchDeployment(ctx, projectID, clusterName).Execute() if err != nil { - if config.StatusNotFound(getResp) { + if validate.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/searchdeployment/state_transition_search_deployment.go b/internal/service/searchdeployment/state_transition_search_deployment.go index 9a77662b38..4b4c1b4cf5 100644 --- a/internal/service/searchdeployment/state_transition_search_deployment.go +++ b/internal/service/searchdeployment/state_transition_search_deployment.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -57,10 +57,10 @@ func searchDeploymentRefreshFunc(ctx context.Context, projectID, clusterName str return nil, "", err } if err != nil { - if config.StatusNotFound(resp) && strings.Contains(err.Error(), SearchDeploymentDoesNotExistsError) { + if validate.StatusNotFound(resp) && strings.Contains(err.Error(), SearchDeploymentDoesNotExistsError) { return "", retrystrategy.RetryStrategyDeletedState, nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", retrystrategy.RetryStrategyUpdatingState, nil } return nil, "", err diff --git a/internal/service/searchindex/resource_search_index.go b/internal/service/searchindex/resource_search_index.go index e7369e203b..af7cfc7c1b 100644 --- a/internal/service/searchindex/resource_search_index.go +++ b/internal/service/searchindex/resource_search_index.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -307,7 +308,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di searchIndex, resp, err := connV2.AtlasSearchApi.GetAtlasSearchIndex(ctx, projectID, clusterName, indexID).Execute() if err != nil { // deleted in the backend case - if config.StatusNotFound(resp) && !d.IsNewResource() { + if validate.StatusNotFound(resp) && !d.IsNewResource() { d.SetId("") return nil } diff --git a/internal/service/serverlessinstance/resource_serverless_instance.go b/internal/service/serverlessinstance/resource_serverless_instance.go index 618a57ea9c..854b426fc9 100644 --- a/internal/service/serverlessinstance/resource_serverless_instance.go +++ b/internal/service/serverlessinstance/resource_serverless_instance.go @@ -14,6 +14,7 @@ import ( "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/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/advancedcluster" "go.mongodb.org/atlas-sdk/v20241113004/admin" @@ -394,10 +395,10 @@ func resourceRefreshFunc(ctx context.Context, name, projectID string, connV2 *ad if err != nil && instance == nil && resp == nil { return nil, "", err } else if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", "DELETED", nil } - if config.StatusServiceUnavailable(resp) { + if validate.StatusServiceUnavailable(resp) { return "", "PENDING", nil } return nil, "", err diff --git a/internal/service/streamconnection/resource_stream_connection.go b/internal/service/streamconnection/resource_stream_connection.go index 84ba677eea..f631ccd871 100644 --- a/internal/service/streamconnection/resource_stream_connection.go +++ b/internal/service/streamconnection/resource_stream_connection.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -144,7 +145,7 @@ func (r *streamConnectionRS) Read(ctx context.Context, req resource.ReadRequest, connectionName := streamConnectionState.ConnectionName.ValueString() apiResp, getResp, err := connV2.StreamsApi.GetStreamConnection(ctx, projectID, instanceName, connectionName).Execute() if err != nil { - if config.StatusNotFound(getResp) { + if validate.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamconnection/state_transition.go b/internal/service/streamconnection/state_transition.go index ea6ce84a86..325cf2f16d 100644 --- a/internal/service/streamconnection/state_transition.go +++ b/internal/service/streamconnection/state_transition.go @@ -5,7 +5,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -18,7 +18,7 @@ func DeleteStreamConnection(ctx context.Context, api admin.StreamsApi, projectID if admin.IsErrorCode(err, "STREAM_KAFKA_CONNECTION_IS_DEPLOYING") { return retry.RetryableError(err) } - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return nil } return retry.NonRetryableError(err) diff --git a/internal/service/streaminstance/resource_stream_instance.go b/internal/service/streaminstance/resource_stream_instance.go index f360bf54cd..424e0532d0 100644 --- a/internal/service/streaminstance/resource_stream_instance.go +++ b/internal/service/streaminstance/resource_stream_instance.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -74,7 +75,7 @@ func (r *streamInstanceRS) Read(ctx context.Context, req resource.ReadRequest, r instanceName := streamInstanceState.InstanceName.ValueString() apiResp, getResp, err := connV2.StreamsApi.GetStreamInstance(ctx, projectID, instanceName).Execute() if err != nil { - if config.StatusNotFound(getResp) { + if validate.StatusNotFound(getResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamprivatelinkendpoint/resource.go b/internal/service/streamprivatelinkendpoint/resource.go index 283b3194d6..ff9f4f3ed0 100644 --- a/internal/service/streamprivatelinkendpoint/resource.go +++ b/internal/service/streamprivatelinkendpoint/resource.go @@ -12,6 +12,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -107,7 +108,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. connV2 := r.Client.AtlasV2 streamsPrivateLinkConnection, apiResp, err := connV2.StreamsApi.GetPrivateLinkConnection(ctx, projectID, connectionID).Execute() if err != nil { - if config.StatusNotFound(apiResp) { + if validate.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamprivatelinkendpoint/state_transition.go b/internal/service/streamprivatelinkendpoint/state_transition.go index 543565777e..70a6799e52 100644 --- a/internal/service/streamprivatelinkendpoint/state_transition.go +++ b/internal/service/streamprivatelinkendpoint/state_transition.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/retrystrategy" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -67,7 +67,7 @@ func refreshFunc(ctx context.Context, projectID, connectionID string, client adm return nil, "", err } if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return &admin.StreamsPrivateLinkConnection{}, retrystrategy.RetryStrategyDeletedState, nil } return nil, "", err diff --git a/internal/service/streamprocessor/resource.go b/internal/service/streamprocessor/resource.go index 9134f6a30e..6ac78dc46e 100644 --- a/internal/service/streamprocessor/resource.go +++ b/internal/service/streamprocessor/resource.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -132,7 +133,7 @@ func (r *streamProcessorRS) Read(ctx context.Context, req resource.ReadRequest, instanceName := state.InstanceName.ValueString() streamProcessor, apiResp, err := connV2.StreamsApi.GetStreamProcessor(ctx, projectID, instanceName, state.ProcessorName.ValueString()).Execute() if err != nil { - if config.StatusNotFound(apiResp) { + if validate.StatusNotFound(apiResp) { resp.State.RemoveResource(ctx) return } diff --git a/internal/service/streamprocessor/state_transition.go b/internal/service/streamprocessor/state_transition.go index c69aaef8ce..72756cd963 100644 --- a/internal/service/streamprocessor/state_transition.go +++ b/internal/service/streamprocessor/state_transition.go @@ -7,7 +7,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" - "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "go.mongodb.org/atlas-sdk/v20241113004/admin" ) @@ -47,7 +47,7 @@ func refreshFunc(ctx context.Context, requestParams *admin.GetStreamProcessorApi return func() (any, string, error) { streamProcessor, resp, err := client.GetStreamProcessorWithParams(ctx, requestParams).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { return "", DroppedState, err } return nil, FailedState, err diff --git a/internal/service/team/resource_team.go b/internal/service/team/resource_team.go index 94d0df6748..30b14f8bf2 100644 --- a/internal/service/team/resource_team.go +++ b/internal/service/team/resource_team.go @@ -18,6 +18,7 @@ import ( "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/dsschema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -102,7 +103,7 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di team, resp, err := connV2.TeamsApi.GetTeamById(context.Background(), orgID, teamID).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/internal/service/thirdpartyintegration/resource_third_party_integration.go b/internal/service/thirdpartyintegration/resource_third_party_integration.go index 066d884d19..10270f7faf 100644 --- a/internal/service/thirdpartyintegration/resource_third_party_integration.go +++ b/internal/service/thirdpartyintegration/resource_third_party_integration.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/go-cty/cty" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" ) @@ -167,7 +168,7 @@ func resourceMongoDBAtlasThirdPartyIntegrationRead(ctx context.Context, d *schem integration, resp, err := connV2.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(ctx, projectID, integrationType).Execute() if err != nil { - if config.StatusNotFound(resp) { + if validate.StatusNotFound(resp) { d.SetId("") return nil } diff --git a/tools/scaffold/template/resource.tmpl b/tools/scaffold/template/resource.tmpl index 5374f0a0d2..c2c0d2a342 100644 --- a/tools/scaffold/template/resource.tmpl +++ b/tools/scaffold/template/resource.tmpl @@ -7,6 +7,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/mongodb/terraform-provider-mongodbatlas/internal/config" + "github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate" + ) const resourceName = "{{.NameSnakeCase}}" @@ -73,7 +75,7 @@ func (r *rs) Read(ctx context.Context, req resource.ReadRequest, resp *resource. // connV2 := r.Client.AtlasV2 //if err != nil { - // if config.StatusNotFound(apiResp) { + // if validate.StatusNotFound(apiResp) { // resp.State.RemoveResource(ctx) // return // }