-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Edouard de BRYE <[email protected]> Co-authored-by: ParthaI <[email protected]>
- Loading branch information
1 parent
10f9ce7
commit 231e873
Showing
14 changed files
with
204 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: "Steampipe Table: tfe_project - Query Terraform Enterprise Projects using SQL" | ||
description: "Allows users to query Projects in Terraform Enterprise, specifically the ID and name association." | ||
--- | ||
|
||
# Table: tfe_project - Query Terraform Enterprise Projects using SQL | ||
|
||
Terraform Cloud projects let you organize your workspaces into groups. You can structure your projects based on your | ||
organization's resource usage and ownership patterns, such as teams, business units, or services. With Terraform Cloud | ||
Standard Edition, you can give teams access to groups of workspaces using projects. | ||
|
||
## Table Usage Guide | ||
The `tfe_project` table provides information about Projects within Terraform Enterprise organization. As a DevOps | ||
engineer or a system administrator, explore project's details through this table, including its ID, name and organization. | ||
Utilize it in conjunction with `tfe_workspace` table to improve grouping and filtering on workspaces insights. | ||
|
||
**Important Notes** | ||
- You must specify the `organization` in the `tfe.spc` file to query this table. | ||
|
||
## Examples | ||
|
||
### List projects | ||
Explore which projects are in the Terraform Enterprise organization. | ||
|
||
```sql+postgres | ||
select | ||
id, | ||
name, | ||
organization, | ||
organization_name | ||
from | ||
tfe_project; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
id, | ||
name, | ||
organization, | ||
organization_name | ||
from | ||
tfe_project; | ||
``` | ||
|
||
### List workspace in a specific project | ||
Explore which workspaces belong to a specific project. This can provide an additional filtering layer to analyse | ||
relative workspaces. | ||
|
||
```sql+postgres | ||
select | ||
w.name | ||
from | ||
tfe_workspace as w | ||
join | ||
tfe_project as p | ||
on p.id = w.project_id | ||
where | ||
p.name = 'my-project'; | ||
``` | ||
|
||
```sql+sqlite | ||
select | ||
w.name | ||
from | ||
tfe_workspace as w | ||
join | ||
tfe_project as p | ||
on p.id = w.project_id | ||
where | ||
p.name = 'my-project'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package tfe | ||
|
||
import ( | ||
"context" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" | ||
|
||
"github.com/hashicorp/go-tfe" | ||
|
||
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin" | ||
) | ||
|
||
func tableTfeProject(ctx context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "tfe_project", | ||
Description: "Projects for the workspaces.", | ||
List: &plugin.ListConfig{ | ||
Hydrate: listProject, | ||
}, | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.SingleColumn("id"), | ||
Hydrate: getProject, | ||
}, | ||
Columns: []*plugin.Column{ | ||
// Top columns | ||
{Name: "id", Type: proto.ColumnType_STRING, Description: "ID of the project."}, | ||
{Name: "name", Type: proto.ColumnType_STRING, Description: "Name of the project."}, | ||
{Name: "organization", Type: proto.ColumnType_JSON, Description: "Organization details that the project belongs to."}, | ||
{Name: "organization_name", Type: proto.ColumnType_STRING, Hydrate: GetOrganizationName, Transform: transform.FromValue(), Description: "Name of the organization containing the project."}, | ||
}, | ||
} | ||
} | ||
|
||
func listProject(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
conn, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("tfe_project.listProject", "connection_error", err) | ||
return nil, err | ||
} | ||
data, err := GetOrganizationName(ctx, d, h) | ||
if err != nil { | ||
return nil, err | ||
} | ||
organizationName := data.(string) | ||
limit := d.QueryContext.Limit | ||
options := tfe.ProjectListOptions{ | ||
ListOptions: tfe.ListOptions{ | ||
// https://www.terraform.io/docs/cloud/api/index.html#pagination | ||
PageSize: 100, | ||
}, | ||
} | ||
if limit != nil { | ||
if *limit < int64(100) { | ||
options.PageSize = int(*limit) | ||
} | ||
} | ||
|
||
pagesLeft := true | ||
for pagesLeft { | ||
result, err := conn.Projects.List(ctx, organizationName, &options) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("tfe_project.listProject", "query_error", err) | ||
return nil, err | ||
} | ||
for _, i := range result.Items { | ||
d.StreamListItem(ctx, i) | ||
// Context can be cancelled due to manual cancellation or the limit has been hit | ||
if d.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
// Pagination | ||
if result.Pagination.CurrentPage < result.Pagination.TotalPages { | ||
options.PageNumber = result.Pagination.NextPage | ||
} else { | ||
pagesLeft = false | ||
} | ||
} | ||
return nil, nil | ||
} | ||
|
||
func getProject(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { | ||
conn, err := connect(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("tfe_project.getProject", "connection_error", err) | ||
return nil, err | ||
} | ||
result, err := conn.Projects.Read(ctx, d.EqualsQuals["id"].GetStringValue()) | ||
|
||
if err != nil { | ||
plugin.Logger(ctx).Error("tfe_project.getProject", "query_error", err) | ||
return nil, err | ||
} | ||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.