diff --git a/client/project.go b/client/project.go index 043e3e6f..2de1cd01 100644 --- a/client/project.go +++ b/client/project.go @@ -48,6 +48,18 @@ type Project struct { } `json:"settings_data" mapstructure:"settings_data"` } +// FlattenedProject is needed for data source +type FlattenedProject struct { + ID int `model:"id" mapstructure:"id"` + Name string `model:"name" mapstructure:"name"` + AccountID int `json:"account_id" model:"account_id" mapstructure:"account_id"` + DateCreated int `json:"date_created" model:"date_created" mapstructure:"date_created"` + DateModified int `json:"date_modified" model:"date_modified" mapstructure:"date_modified"` + Status string `model:"status" mapstructure:"status"` + TimeFormat string `json:"time_format" mapstructure:"time_format"` + Timezone string `json:"timezone" mapstructure:"timezone"` +} + // FIXME: finish implementing the entire set of Project fields /* SettingsData struct { diff --git a/rollbar/data_source_projects.go b/rollbar/data_source_projects.go index 7a34296b..e09f9a45 100644 --- a/rollbar/data_source_projects.go +++ b/rollbar/data_source_projects.go @@ -103,7 +103,7 @@ func dataSourceProjectsRead(ctx context.Context, d *schema.ResourceData, m inter if err != nil { return diag.FromErr(err) } - mustSet(d, "projects", projects) + mustSet(d, "projects", flattenProjects(projects)) // Set resource ID to current timestamp (every resource must have an ID or // it will be destroyed). @@ -112,3 +112,21 @@ func dataSourceProjectsRead(ctx context.Context, d *schema.ResourceData, m inter log.Debug().Msg("Successfully read project list from API.") return diags } + +func flattenProjects(projects []client.Project) []client.FlattenedProject { + var fps []client.FlattenedProject + for _, p := range projects { + fp := client.FlattenedProject{ + ID: p.ID, + Name: p.Name, + AccountID: p.AccountID, + DateCreated: p.DateCreated, + DateModified: p.DateModified, + Status: p.Status, + TimeFormat: p.SettingsData.TimeFormat, + Timezone: p.SettingsData.Timezone, + } + fps = append(fps, fp) + } + return fps +}