-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added resources for saved filter handling
- Loading branch information
1 parent
4d3a072
commit e6ab655
Showing
15 changed files
with
795 additions
and
0 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,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 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 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 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 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 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 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 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,84 @@ | ||
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) | ||
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.