-
Notifications
You must be signed in to change notification settings - Fork 31
added resources for saved filter handling #521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,39 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "spacelift_saved_filter Data Source - terraform-provider-spacelift" | ||
subcategory: "" | ||
description: |- | ||
spacelift_saved_filter represents a Spacelift saved filter. | ||
--- | ||
|
||
# spacelift_saved_filter (Data Source) | ||
|
||
`spacelift_saved_filter` represents a Spacelift saved filter. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "spacelift_saved_filter" "filter" { | ||
filter_id = spacelift_saved_filter.filter.id | ||
} | ||
|
||
output "filter_data" { | ||
value = data.spacelift_saved_filter.filter.data | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `filter_id` (String) immutable ID (slug) of the filter | ||
|
||
### Read-Only | ||
|
||
- `created_by` (String) Login of the user who created the saved filter | ||
- `data` (String) Data is the JSON representation of the filter data | ||
- `id` (String) Globally unique ID of the saved filter | ||
- `is_public` (Boolean) Toggle whether the filter is public or not | ||
- `name` (String) Name of the filter | ||
- `type` (String) Type describes the type of the filter. It is used to determine which view the filter is for |
This file contains hidden or 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,57 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "spacelift_saved_filters Data Source - terraform-provider-spacelift" | ||
subcategory: "" | ||
description: |- | ||
spacelift_saved_filters can find all saved filters that have certain type or name | ||
--- | ||
|
||
# spacelift_saved_filters (Data Source) | ||
|
||
`spacelift_saved_filters` can find all saved filters that have certain type or name | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# For all saved filter | ||
data "spacelift_saved_filters" "all" {} | ||
|
||
# Filters with a matching type | ||
data "spacelift_saved_filters" "stack_filters" { | ||
type = "stacks" | ||
} | ||
|
||
# Filters with a matching name | ||
data "spacelift_saved_filters" "my_filters" { | ||
name = "My best filter" | ||
} | ||
|
||
output "filter_ids" { | ||
value = data.spacelift_saved_filters.stack_filters.filters[*].id | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- `filter_name` (String) filter name to look for | ||
- `filter_type` (String) filter type to look for | ||
|
||
### Read-Only | ||
|
||
- `filters` (List of Object) (see [below for nested schema](#nestedatt--filters)) | ||
- `id` (String) The ID of this resource. | ||
|
||
<a id="nestedatt--filters"></a> | ||
### Nested Schema for `filters` | ||
|
||
Read-Only: | ||
|
||
- `created_by` (String) | ||
- `data` (String) | ||
- `id` (String) | ||
- `is_public` (Boolean) | ||
- `name` (String) | ||
- `type` (String) |
This file contains hidden or 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,93 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "spacelift_saved_filter Resource - terraform-provider-spacelift" | ||
subcategory: "" | ||
description: |- | ||
spacelift_saved_filter represents a Spacelift filter - a collection of customer-defined criteria that are applied by Spacelift at one of the decision points within the application. | ||
--- | ||
|
||
# spacelift_saved_filter (Resource) | ||
|
||
`spacelift_saved_filter` represents a Spacelift **filter** - a collection of customer-defined criteria that are applied by Spacelift at one of the decision points within the application. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "spacelift_saved_filter" "my_filter" { | ||
type = "webhooks" | ||
name = "filter for all xyz teams" | ||
is_public = true | ||
data = jsonencode({ | ||
"key" : "activeFilters", | ||
"value" : jsonencode({ | ||
"filters" : [ | ||
[ | ||
"name", | ||
{ | ||
"key" : "name", | ||
"filterName" : "name", | ||
"type" : "STRING", | ||
"values" : [ | ||
"team_xyz_*" | ||
] | ||
} | ||
] | ||
], | ||
"sort" : { | ||
"direction" : "ASC", | ||
"option" : "space" | ||
}, | ||
"text" : null, | ||
"order" : [ | ||
{ | ||
"name" : "enabled", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "endpoint", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "slug", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "label", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "name", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "space", | ||
"visible" : true | ||
} | ||
] | ||
}) | ||
}) | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `data` (String) Data is the JSON representation of the filter data | ||
- `is_public` (Boolean) Toggle whether the filter is public or not | ||
- `name` (String) Name of the saved filter | ||
- `type` (String) Type describes the type of the filter. It is used to determine which view the filter is for. Possible values are `stacks`, `blueprints`, `contexts`, `webhooks`. | ||
|
||
### Read-Only | ||
|
||
- `created_by` (String) Login of the user who created the saved filter | ||
- `id` (String) Globally unique ID of the saved filter | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
terraform import spacelift_saved_filter.my_filter $FILTER_ID | ||
``` |
This file contains hidden or 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,7 @@ | ||
data "spacelift_saved_filter" "filter" { | ||
filter_id = spacelift_saved_filter.filter.id | ||
} | ||
|
||
output "filter_data" { | ||
value = data.spacelift_saved_filter.filter.data | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/data-sources/spacelift_saved_filters/data-source.tf
This file contains hidden or 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,16 @@ | ||
# For all saved filter | ||
data "spacelift_saved_filters" "all" {} | ||
|
||
# Filters with a matching type | ||
data "spacelift_saved_filters" "stack_filters" { | ||
type = "stacks" | ||
} | ||
|
||
# Filters with a matching name | ||
data "spacelift_saved_filters" "my_filters" { | ||
name = "My best filter" | ||
} | ||
|
||
output "filter_ids" { | ||
value = data.spacelift_saved_filters.stack_filters.filters[*].id | ||
} |
This file contains hidden or 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 @@ | ||
terraform import spacelift_saved_filter.my_filter $FILTER_ID |
This file contains hidden or 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,54 @@ | ||
resource "spacelift_saved_filter" "my_filter" { | ||
type = "webhooks" | ||
name = "filter for all xyz teams" | ||
is_public = true | ||
data = jsonencode({ | ||
"key" : "activeFilters", | ||
"value" : jsonencode({ | ||
"filters" : [ | ||
[ | ||
"name", | ||
{ | ||
"key" : "name", | ||
"filterName" : "name", | ||
"type" : "STRING", | ||
"values" : [ | ||
"team_xyz_*" | ||
] | ||
} | ||
] | ||
], | ||
"sort" : { | ||
"direction" : "ASC", | ||
"option" : "space" | ||
}, | ||
"text" : null, | ||
"order" : [ | ||
{ | ||
"name" : "enabled", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "endpoint", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "slug", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "label", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "name", | ||
"visible" : true | ||
}, | ||
{ | ||
"name" : "space", | ||
"visible" : true | ||
} | ||
] | ||
}) | ||
}) | ||
} |
This file contains hidden or 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,85 @@ | ||
package spacelift | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal" | ||
) | ||
|
||
func dataSavedFilter() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "" + | ||
"`spacelift_saved_filter` represents a Spacelift saved filter.", | ||
|
||
ReadContext: dataFilterRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"filter_id": { | ||
Type: schema.TypeString, | ||
Description: " immutable ID (slug) of the filter", | ||
Required: true, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Description: "Globally unique ID of the saved filter", | ||
Computed: true, | ||
}, | ||
"is_public": { | ||
Type: schema.TypeBool, | ||
Description: "Toggle whether the filter is public or not", | ||
Computed: true, | ||
}, | ||
"created_by": { | ||
Type: schema.TypeString, | ||
Description: "Login of the user who created the saved filter", | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Description: "Name of the filter", | ||
Computed: true, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Description: "Type describes the type of the filter. It is used to determine which view the filter is for", | ||
Computed: true, | ||
}, | ||
"data": { | ||
Type: schema.TypeString, | ||
Description: "Data is the JSON representation of the filter data", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataFilterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var query struct { | ||
Filter struct { | ||
ID string `graphql:"id"` | ||
IsPublic bool `graphql:"isPublic"` | ||
CreatedBy string `graphql:"createdBy"` | ||
Name string `graphql:"name"` | ||
Type string `graphql:"type"` | ||
Data string `graphql:"data"` | ||
} `graphql:"savedFilter(id: $id)"` | ||
} | ||
|
||
variables := map[string]interface{}{"id": d.Get("filter_id")} | ||
|
||
if err := meta.(*internal.Client).Query(ctx, "savedFilter", &query, variables); err != nil { | ||
return diag.Errorf("could not query for filter: %v", err) | ||
} | ||
|
||
d.SetId(query.Filter.ID) | ||
truszkowski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
d.Set("is_public", query.Filter.IsPublic) | ||
d.Set("name", query.Filter.Name) | ||
d.Set("type", query.Filter.Type) | ||
d.Set("created_by", query.Filter.CreatedBy) | ||
d.Set("data", query.Filter.Data) | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.