Skip to content

Commit e6ab655

Browse files
committed
added resources for saved filter handling
1 parent 4d3a072 commit e6ab655

File tree

15 files changed

+795
-0
lines changed

15 files changed

+795
-0
lines changed

docs/data-sources/saved_filter.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "spacelift_saved_filter Data Source - terraform-provider-spacelift"
4+
subcategory: ""
5+
description: |-
6+
spacelift_saved_filter represents a Spacelift saved filter.
7+
---
8+
9+
# spacelift_saved_filter (Data Source)
10+
11+
`spacelift_saved_filter` represents a Spacelift saved filter.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "spacelift_saved_filter" "filter" {
17+
filter_id = spacelift_saved_filter.filter.id
18+
}
19+
20+
output "filter_data" {
21+
value = data.spacelift_saved_filter.filter.data
22+
}
23+
```
24+
25+
<!-- schema generated by tfplugindocs -->
26+
## Schema
27+
28+
### Required
29+
30+
- `filter_id` (String) immutable ID (slug) of the filter
31+
32+
### Read-Only
33+
34+
- `created_by` (String) Login of the user who created the saved filter
35+
- `data` (String) Data is the JSON representation of the filter data
36+
- `id` (String) Globally unique ID of the saved filter
37+
- `is_public` (Boolean) Toggle whether the filter is public or not
38+
- `name` (String) Name of the filter
39+
- `type` (String) Type describes the type of the filter. It is used to determine which view the filter is for

docs/data-sources/saved_filters.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "spacelift_saved_filters Data Source - terraform-provider-spacelift"
4+
subcategory: ""
5+
description: |-
6+
spacelift_saved_filters can find all saved filters that have certain type or name
7+
---
8+
9+
# spacelift_saved_filters (Data Source)
10+
11+
`spacelift_saved_filters` can find all saved filters that have certain type or name
12+
13+
## Example Usage
14+
15+
```terraform
16+
# For all saved filter
17+
data "spacelift_saved_filters" "all" {}
18+
19+
# Filters with a matching type
20+
data "spacelift_saved_filters" "stack_filters" {
21+
type = "stacks"
22+
}
23+
24+
# Filters with a matching name
25+
data "spacelift_saved_filters" "my_filters" {
26+
name = "My best filter"
27+
}
28+
29+
output "filter_ids" {
30+
value = data.spacelift_saved_filters.stack_filters.filters[*].id
31+
}
32+
```
33+
34+
<!-- schema generated by tfplugindocs -->
35+
## Schema
36+
37+
### Optional
38+
39+
- `filter_name` (String) filter name to look for
40+
- `filter_type` (String) filter type to look for
41+
42+
### Read-Only
43+
44+
- `filters` (List of Object) (see [below for nested schema](#nestedatt--filters))
45+
- `id` (String) The ID of this resource.
46+
47+
<a id="nestedatt--filters"></a>
48+
### Nested Schema for `filters`
49+
50+
Read-Only:
51+
52+
- `created_by` (String)
53+
- `data` (String)
54+
- `id` (String)
55+
- `is_public` (Boolean)
56+
- `name` (String)
57+
- `type` (String)

docs/resources/saved_filter.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "spacelift_saved_filter Resource - terraform-provider-spacelift"
4+
subcategory: ""
5+
description: |-
6+
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.
7+
---
8+
9+
# spacelift_saved_filter (Resource)
10+
11+
`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.
12+
13+
## Example Usage
14+
15+
```terraform
16+
resource "spacelift_saved_filter" "my_filter" {
17+
type = "webhooks"
18+
name = "filter for all xyz teams"
19+
is_public = true
20+
data = jsonencode({
21+
"key" : "activeFilters",
22+
"value" : jsonencode({
23+
"filters" : [
24+
[
25+
"name",
26+
{
27+
"key" : "name",
28+
"filterName" : "name",
29+
"type" : "STRING",
30+
"values" : [
31+
"team_xyz_*"
32+
]
33+
}
34+
]
35+
],
36+
"sort" : {
37+
"direction" : "ASC",
38+
"option" : "space"
39+
},
40+
"text" : null,
41+
"order" : [
42+
{
43+
"name" : "enabled",
44+
"visible" : true
45+
},
46+
{
47+
"name" : "endpoint",
48+
"visible" : true
49+
},
50+
{
51+
"name" : "slug",
52+
"visible" : true
53+
},
54+
{
55+
"name" : "label",
56+
"visible" : true
57+
},
58+
{
59+
"name" : "name",
60+
"visible" : true
61+
},
62+
{
63+
"name" : "space",
64+
"visible" : true
65+
}
66+
]
67+
})
68+
})
69+
}
70+
```
71+
72+
<!-- schema generated by tfplugindocs -->
73+
## Schema
74+
75+
### Required
76+
77+
- `data` (String) Data is the JSON representation of the filter data
78+
- `is_public` (Boolean) Toggle whether the filter is public or not
79+
- `name` (String) Name of the saved filter
80+
- `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`.
81+
82+
### Read-Only
83+
84+
- `created_by` (String) Login of the user who created the saved filter
85+
- `id` (String) Globally unique ID of the saved filter
86+
87+
## Import
88+
89+
Import is supported using the following syntax:
90+
91+
```shell
92+
terraform import spacelift_saved_filter.my_filter $FILTER_ID
93+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
data "spacelift_saved_filter" "filter" {
2+
filter_id = spacelift_saved_filter.filter.id
3+
}
4+
5+
output "filter_data" {
6+
value = data.spacelift_saved_filter.filter.data
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# For all saved filter
2+
data "spacelift_saved_filters" "all" {}
3+
4+
# Filters with a matching type
5+
data "spacelift_saved_filters" "stack_filters" {
6+
type = "stacks"
7+
}
8+
9+
# Filters with a matching name
10+
data "spacelift_saved_filters" "my_filters" {
11+
name = "My best filter"
12+
}
13+
14+
output "filter_ids" {
15+
value = data.spacelift_saved_filters.stack_filters.filters[*].id
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform import spacelift_saved_filter.my_filter $FILTER_ID
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
resource "spacelift_saved_filter" "my_filter" {
2+
type = "webhooks"
3+
name = "filter for all xyz teams"
4+
is_public = true
5+
data = jsonencode({
6+
"key" : "activeFilters",
7+
"value" : jsonencode({
8+
"filters" : [
9+
[
10+
"name",
11+
{
12+
"key" : "name",
13+
"filterName" : "name",
14+
"type" : "STRING",
15+
"values" : [
16+
"team_xyz_*"
17+
]
18+
}
19+
]
20+
],
21+
"sort" : {
22+
"direction" : "ASC",
23+
"option" : "space"
24+
},
25+
"text" : null,
26+
"order" : [
27+
{
28+
"name" : "enabled",
29+
"visible" : true
30+
},
31+
{
32+
"name" : "endpoint",
33+
"visible" : true
34+
},
35+
{
36+
"name" : "slug",
37+
"visible" : true
38+
},
39+
{
40+
"name" : "label",
41+
"visible" : true
42+
},
43+
{
44+
"name" : "name",
45+
"visible" : true
46+
},
47+
{
48+
"name" : "space",
49+
"visible" : true
50+
}
51+
]
52+
})
53+
})
54+
}

spacelift/data_saved_filter.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package spacelift
2+
3+
import (
4+
"context"
5+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7+
8+
"github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal"
9+
)
10+
11+
func dataSavedFilter() *schema.Resource {
12+
return &schema.Resource{
13+
Description: "" +
14+
"`spacelift_saved_filter` represents a Spacelift saved filter.",
15+
16+
ReadContext: dataFilterRead,
17+
18+
Schema: map[string]*schema.Schema{
19+
"filter_id": {
20+
Type: schema.TypeString,
21+
Description: " immutable ID (slug) of the filter",
22+
Required: true,
23+
},
24+
"id": {
25+
Type: schema.TypeString,
26+
Description: "Globally unique ID of the saved filter",
27+
Computed: true,
28+
},
29+
"is_public": {
30+
Type: schema.TypeBool,
31+
Description: "Toggle whether the filter is public or not",
32+
Computed: true,
33+
},
34+
"created_by": {
35+
Type: schema.TypeString,
36+
Description: "Login of the user who created the saved filter",
37+
Computed: true,
38+
},
39+
"name": {
40+
Type: schema.TypeString,
41+
Description: "Name of the filter",
42+
Computed: true,
43+
},
44+
"type": {
45+
Type: schema.TypeString,
46+
Description: "Type describes the type of the filter. It is used to determine which view the filter is for",
47+
Computed: true,
48+
},
49+
"data": {
50+
Type: schema.TypeString,
51+
Description: "Data is the JSON representation of the filter data",
52+
Computed: true,
53+
},
54+
},
55+
}
56+
}
57+
58+
func dataFilterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
59+
var query struct {
60+
Filter struct {
61+
ID string `graphql:"id"`
62+
IsPublic bool `graphql:"isPublic"`
63+
CreatedBy string `graphql:"createdBy"`
64+
Name string `graphql:"name"`
65+
Type string `graphql:"type"`
66+
Data string `graphql:"data"`
67+
} `graphql:"savedFilter(id: $id)"`
68+
}
69+
70+
variables := map[string]interface{}{"id": d.Get("filter_id")}
71+
72+
if err := meta.(*internal.Client).Query(ctx, "savedFilter", &query, variables); err != nil {
73+
return diag.Errorf("could not query for filter: %v", err)
74+
}
75+
76+
d.SetId(query.Filter.ID)
77+
d.Set("is_public", query.Filter.IsPublic)
78+
d.Set("name", query.Filter.Name)
79+
d.Set("type", query.Filter.Type)
80+
d.Set("created_by", query.Filter.CreatedBy)
81+
d.Set("data", query.Filter.Data)
82+
83+
return nil
84+
}

0 commit comments

Comments
 (0)