Skip to content

Commit 3cc16bb

Browse files
feat: add remaining datasources for notification profiles [ENG-5557] (#99)
[ENG-5557](https://stacklet.atlassian.net/browse/ENG-5557) ### what add support for fetching notification profiles for - jira - slack - teams ### why provide access to notifications profiles ### testing testing in sandbox, will add tests once resources are also available ### docs updated here [ENG-5557]: https://stacklet.atlassian.net/browse/ENG-5557?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 631c313 commit 3cc16bb

19 files changed

+655
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stacklet_configuration_profile_jira Data Source - terraform-provider-stacklet"
4+
subcategory: ""
5+
description: |-
6+
Retrieve information about the Jira configuration profile.
7+
---
8+
9+
# stacklet_configuration_profile_jira (Data Source)
10+
11+
Retrieve information about the Jira configuration profile.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stacklet_configuration_profile_jira" "example" {}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Read-Only
23+
24+
- `id` (String) The GraphQL Node ID of the configuration profile.
25+
- `profile` (String) The profile name.
26+
- `project` (Block List) Jira project configuration. (see [below for nested schema](#nestedblock--project))
27+
- `url` (String) The Jira instance URL.
28+
- `user` (String) The Jira instance authentication username.
29+
30+
<a id="nestedblock--project"></a>
31+
### Nested Schema for `project`
32+
33+
Read-Only:
34+
35+
- `closed_status` (String) The state for closed tickets.
36+
- `issue_type` (String) The type of issue to use for tickets.
37+
- `name` (String) The name of the project.
38+
- `project` (String) The ID of the project.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stacklet_configuration_profile_slack Data Source - terraform-provider-stacklet"
4+
subcategory: ""
5+
description: |-
6+
Retrieve information about the Slack configuration profile.
7+
---
8+
9+
# stacklet_configuration_profile_slack (Data Source)
10+
11+
Retrieve information about the Slack configuration profile.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stacklet_configuration_profile_slack" "example" {}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Read-Only
23+
24+
- `id` (String) The GraphQL Node ID of the configuration profile.
25+
- `profile` (String) The profile name.
26+
- `user_fields` (List of String) Fields to use for identifying users for notification delivery.
27+
- `webhook` (Block List) Webhook configuration. (see [below for nested schema](#nestedblock--webhook))
28+
29+
<a id="nestedblock--webhook"></a>
30+
### Nested Schema for `webhook`
31+
32+
Read-Only:
33+
34+
- `name` (String) The webook name.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stacklet_configuration_profile_teams Data Source - terraform-provider-stacklet"
4+
subcategory: ""
5+
description: |-
6+
Retrieve information about the Microsoft Teams configuration profile.
7+
---
8+
9+
# stacklet_configuration_profile_teams (Data Source)
10+
11+
Retrieve information about the Microsoft Teams configuration profile.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stacklet_configuration_profile_teams" "example" {}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Read-Only
23+
24+
- `id` (String) The GraphQL Node ID of the configuration profile.
25+
- `profile` (String) The profile name.
26+
- `webhook` (Block List) Webhook configuration. (see [below for nested schema](#nestedblock--webhook))
27+
28+
<a id="nestedblock--webhook"></a>
29+
### Nested Schema for `webhook`
30+
31+
Read-Only:
32+
33+
- `name` (String) The webook name.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "stacklet_configuration_profile_jira" "example" {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "stacklet_configuration_profile_slack" "example" {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "stacklet_configuration_profile_teams" "example" {}

internal/api/configuration_profile.go

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ type ConfigurationProfile struct {
1616
TypeName string `graphql:"__typename"`
1717
EmailConfiguration EmailConfiguration `graphql:"... on EmailConfiguration"`
1818
ServiceNowConfiguration ServiceNowConfiguration `graphql:"... on ServiceNowConfiguration"`
19+
SlackConfiguration SlackConfiguration `graphql:"... on SlackConfiguration"`
1920
SymphonyConfiguration SymphonyConfiguration `graphql:"... on SymphonyConfiguration"`
21+
TeamsConfiguration TeamsConfiguration `graphql:"... on TeamsConfiguration"`
22+
JiraConfiguration JiraConfiguration `graphql:"... on JiraConfiguration"`
2023
}
2124
}
2225

@@ -39,7 +42,6 @@ type SMTPConfiguration struct {
3942
type ServiceNowConfiguration struct {
4043
Endpoint string
4144
User string
42-
Password string
4345
IssueType string
4446
ClosedState string
4547
}
@@ -50,6 +52,44 @@ type SymphonyConfiguration struct {
5052
ServiceAccount string
5153
}
5254

55+
// SlackConfiguration is the configuration for Symphony profiles.
56+
type SlackConfiguration struct {
57+
UserFields []string
58+
Webhooks []SlackWebhook
59+
}
60+
61+
// SlackWebhook is a webhook configuration for Slack.
62+
type SlackWebhook struct {
63+
Name string
64+
URL string `graphql:"url"`
65+
}
66+
67+
// TeamsConfiguration is the configuration for Microsoft Teams profiles.
68+
type TeamsConfiguration struct {
69+
Webhooks []TeamsWebhook
70+
}
71+
72+
// TeamsWebhook is a webhook configuration for Microsoft Teams.
73+
type TeamsWebhook struct {
74+
Name string
75+
URL string `graphql:"url"`
76+
}
77+
78+
// JiraConfiguation is the configuration for Jira profiles.
79+
type JiraConfiguration struct {
80+
URL *string `graphql:"url"`
81+
Projects []JiraProject
82+
User string
83+
}
84+
85+
// JiraPorject is the configuration for a Jira project.
86+
type JiraProject struct {
87+
ClosedStatus string
88+
IssueType string
89+
Name string
90+
Project string
91+
}
92+
5393
type configurationProfileAPI struct {
5494
c *graphql.Client
5595
}
@@ -73,3 +113,33 @@ func (a configurationProfileAPI) Read(ctx context.Context, name ConfigurationPro
73113

74114
return &query.Configuration, nil
75115
}
116+
117+
// ReadEmail returns data for the email configuration profile.
118+
func (a configurationProfileAPI) ReadEmail(ctx context.Context) (*ConfigurationProfile, error) {
119+
return a.Read(ctx, ConfigurationProfileEmail)
120+
}
121+
122+
// ReadSlack returns data for the Slack configuration profile.
123+
func (a configurationProfileAPI) ReadSlack(ctx context.Context) (*ConfigurationProfile, error) {
124+
return a.Read(ctx, ConfigurationProfileSlack)
125+
}
126+
127+
// ReadTeams returns data for the Microsoft Teams configuration profile.
128+
func (a configurationProfileAPI) ReadTeams(ctx context.Context) (*ConfigurationProfile, error) {
129+
return a.Read(ctx, ConfigurationProfileTeams)
130+
}
131+
132+
// ReadSymphony returns data for the Symphony configuration profile.
133+
func (a configurationProfileAPI) ReadSymphony(ctx context.Context) (*ConfigurationProfile, error) {
134+
return a.Read(ctx, ConfigurationProfileSymphony)
135+
}
136+
137+
// ReadSymphony returns data for the ServiceNow configuration profile.
138+
func (a configurationProfileAPI) ReadServiceNow(ctx context.Context) (*ConfigurationProfile, error) {
139+
return a.Read(ctx, ConfigurationProfileServiceNow)
140+
}
141+
142+
// ReadJira returns data for the Jira configuration profile.
143+
func (a configurationProfileAPI) ReadJira(ctx context.Context) (*ConfigurationProfile, error) {
144+
return a.Read(ctx, ConfigurationProfileJira)
145+
}

internal/api/enums.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var REPORT_SOURCES = []ReportSource{
4242
//
4343
// This is defined as a type since profiles are looked up by names matching
4444
// type.
45-
type ConfigurationProfileName string
45+
type ConfigurationProfileName StringEnum
4646

4747
const (
4848
ConfigurationProfileEmail = ConfigurationProfileName("email")

internal/datasources/configuration_profile_email.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (d *configurationProfileEmailDataSource) Read(ctx context.Context, req data
8989
return
9090
}
9191

92-
config, err := d.api.ConfigurationProfile.Read(ctx, api.ConfigurationProfileEmail)
92+
config, err := d.api.ConfigurationProfile.ReadEmail(ctx)
9393
if err != nil {
9494
errors.AddDiagError(&resp.Diagnostics, err)
9595
return
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright (c) 2025 - Stacklet, Inc.
2+
3+
package datasources
4+
5+
import (
6+
"context"
7+
8+
"github.com/hashicorp/terraform-plugin-framework/datasource"
9+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
10+
"github.com/hashicorp/terraform-plugin-framework/types"
11+
12+
"github.com/stacklet/terraform-provider-stacklet/internal/api"
13+
"github.com/stacklet/terraform-provider-stacklet/internal/errors"
14+
"github.com/stacklet/terraform-provider-stacklet/internal/models"
15+
"github.com/stacklet/terraform-provider-stacklet/internal/modelupdate"
16+
"github.com/stacklet/terraform-provider-stacklet/internal/providerdata"
17+
)
18+
19+
var (
20+
_ datasource.DataSource = &configurationProfileJiraDataSource{}
21+
)
22+
23+
func NewConfigurationProfileJiraDataSource() datasource.DataSource {
24+
return &configurationProfileJiraDataSource{}
25+
}
26+
27+
type configurationProfileJiraDataSource struct {
28+
api *api.API
29+
}
30+
31+
func (d *configurationProfileJiraDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
32+
resp.TypeName = req.ProviderTypeName + "_configuration_profile_jira"
33+
}
34+
35+
func (d *configurationProfileJiraDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
36+
resp.Schema = schema.Schema{
37+
Description: "Retrieve information about the Jira configuration profile.",
38+
Attributes: map[string]schema.Attribute{
39+
"id": schema.StringAttribute{
40+
Description: "The GraphQL Node ID of the configuration profile.",
41+
Computed: true,
42+
},
43+
"profile": schema.StringAttribute{
44+
Description: "The profile name.",
45+
Computed: true,
46+
},
47+
"url": schema.StringAttribute{
48+
Description: "The Jira instance URL.",
49+
Computed: true,
50+
},
51+
"user": schema.StringAttribute{
52+
Description: "The Jira instance authentication username.",
53+
Computed: true,
54+
},
55+
},
56+
Blocks: map[string]schema.Block{
57+
"project": schema.ListNestedBlock{
58+
Description: "Jira project configuration.",
59+
NestedObject: schema.NestedBlockObject{
60+
Attributes: map[string]schema.Attribute{
61+
"closed_status": schema.StringAttribute{
62+
Description: "The state for closed tickets.",
63+
Computed: true,
64+
},
65+
"issue_type": schema.StringAttribute{
66+
Description: "The type of issue to use for tickets.",
67+
Computed: true,
68+
},
69+
"name": schema.StringAttribute{
70+
Description: "The name of the project.",
71+
Computed: true,
72+
},
73+
"project": schema.StringAttribute{
74+
Description: "The ID of the project.",
75+
Computed: true,
76+
},
77+
},
78+
},
79+
},
80+
},
81+
}
82+
}
83+
84+
func (d *configurationProfileJiraDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
85+
if pd, err := providerdata.GetDataSourceProviderData(req); err != nil {
86+
errors.AddDiagError(&resp.Diagnostics, err)
87+
} else if pd != nil {
88+
d.api = pd.API
89+
}
90+
}
91+
92+
func (d *configurationProfileJiraDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
93+
var data models.ConfigurationProfileJiraDataSource
94+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
95+
if resp.Diagnostics.HasError() {
96+
return
97+
}
98+
99+
config, err := d.api.ConfigurationProfile.ReadJira(ctx)
100+
if err != nil {
101+
errors.AddDiagError(&resp.Diagnostics, err)
102+
return
103+
}
104+
105+
data.ID = types.StringValue(config.ID)
106+
data.Profile = types.StringValue(config.Profile)
107+
data.URL = types.StringPointerValue(config.Record.JiraConfiguration.URL)
108+
data.User = types.StringValue(config.Record.JiraConfiguration.User)
109+
110+
updater := modelupdate.NewConfigurationProfileUpdater(*config)
111+
projects, diags := updater.JiraProjects()
112+
resp.Diagnostics.Append(diags...)
113+
if resp.Diagnostics.HasError() {
114+
return
115+
}
116+
data.Projects = projects
117+
118+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
119+
}

0 commit comments

Comments
 (0)