Skip to content

Commit

Permalink
fix: null pointer error project data source (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaangiolillo authored Aug 9, 2023
1 parent 6312735 commit 639014c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
37 changes: 21 additions & 16 deletions mongodbatlas/data_source_mongodbatlas_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,23 +242,28 @@ func flattenProjects(ctx context.Context, client *MongoDBClient, projects []*mat
diags = append(diags, diagWarning)
}

results[k] = map[string]interface{}{
"id": project.ID,
"org_id": project.OrgID,
"name": project.Name,
"cluster_count": project.ClusterCount,
"created": project.Created,
"teams": flattenTeams(teams),
"api_keys": flattenAPIKeys(apiKeys),
"is_collect_database_specifics_statistics_enabled": projectSettings.IsCollectDatabaseSpecificsStatisticsEnabled,
"is_data_explorer_enabled": projectSettings.IsDataExplorerEnabled,
"is_extended_storage_sizes_enabled": projectSettings.IsExtendedStorageSizesEnabled,
"is_performance_advisor_enabled": projectSettings.IsPerformanceAdvisorEnabled,
"is_realtime_performance_panel_enabled": projectSettings.IsRealtimePerformancePanelEnabled,
"is_schema_advisor_enabled": projectSettings.IsSchemaAdvisorEnabled,
"region_usage_restrictions": project.RegionUsageRestrictions,
"limits": flattenLimits(limits),
resultEntry := map[string]interface{}{
"id": project.ID,
"org_id": project.OrgID,
"name": project.Name,
"cluster_count": project.ClusterCount,
"created": project.Created,
"region_usage_restrictions": project.RegionUsageRestrictions,
"teams": flattenTeams(teams),
"api_keys": flattenAPIKeys(apiKeys),
"limits": flattenLimits(limits),
}

if projectSettings != nil {
resultEntry["is_collect_database_specifics_statistics_enabled"] = projectSettings.IsCollectDatabaseSpecificsStatisticsEnabled
resultEntry["is_data_explorer_enabled"] = projectSettings.IsDataExplorerEnabled
resultEntry["is_extended_storage_sizes_enabled"] = projectSettings.IsExtendedStorageSizesEnabled
resultEntry["is_performance_advisor_enabled"] = projectSettings.IsPerformanceAdvisorEnabled
resultEntry["is_realtime_performance_panel_enabled"] = projectSettings.IsRealtimePerformancePanelEnabled
resultEntry["is_schema_advisor_enabled"] = projectSettings.IsSchemaAdvisorEnabled
}

results[k] = resultEntry
}
}

Expand Down
4 changes: 4 additions & 0 deletions mongodbatlas/resource_mongodbatlas_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ func expandLimitsList(limits []interface{}) []*projectLimit {
}

func flattenTeams(ta *matlas.TeamsAssigned) []map[string]interface{} {
if ta == nil || ta.Results == nil || ta.TotalCount == 0 {
return nil
}

teams := ta.Results
res := make([]map[string]interface{}, len(teams))

Expand Down

0 comments on commit 639014c

Please sign in to comment.