Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/data-sources/configuration_profile_jira.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stacklet_configuration_profile_jira Data Source - terraform-provider-stacklet"
subcategory: ""
description: |-
Retrieve information about the Jira configuration profile.
---

# stacklet_configuration_profile_jira (Data Source)

Retrieve information about the Jira configuration profile.

## Example Usage

```terraform
data "stacklet_configuration_profile_jira" "example" {}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (String) The GraphQL Node ID of the configuration profile.
- `profile` (String) The profile name.
- `project` (Block List) Jira project configuration. (see [below for nested schema](#nestedblock--project))
- `url` (String) The Jira instance URL.
- `user` (String) The Jira instance authentication username.

<a id="nestedblock--project"></a>
### Nested Schema for `project`

Read-Only:

- `closed_status` (String) The state for closed tickets.
- `issue_type` (String) The type of issue to use for tickets.
- `name` (String) The name of the project.
- `project` (String) The ID of the project.
34 changes: 34 additions & 0 deletions docs/data-sources/configuration_profile_slack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stacklet_configuration_profile_slack Data Source - terraform-provider-stacklet"
subcategory: ""
description: |-
Retrieve information about the Slack configuration profile.
---

# stacklet_configuration_profile_slack (Data Source)

Retrieve information about the Slack configuration profile.

## Example Usage

```terraform
data "stacklet_configuration_profile_slack" "example" {}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (String) The GraphQL Node ID of the configuration profile.
- `profile` (String) The profile name.
- `user_fields` (List of String) Fields to use for identifying users for notification delivery.
- `webhook` (Block List) Webhook configuration. (see [below for nested schema](#nestedblock--webhook))

<a id="nestedblock--webhook"></a>
### Nested Schema for `webhook`

Read-Only:

- `name` (String) The webook name.
33 changes: 33 additions & 0 deletions docs/data-sources/configuration_profile_teams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stacklet_configuration_profile_teams Data Source - terraform-provider-stacklet"
subcategory: ""
description: |-
Retrieve information about the Microsoft Teams configuration profile.
---

# stacklet_configuration_profile_teams (Data Source)

Retrieve information about the Microsoft Teams configuration profile.

## Example Usage

```terraform
data "stacklet_configuration_profile_teams" "example" {}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (String) The GraphQL Node ID of the configuration profile.
- `profile` (String) The profile name.
- `webhook` (Block List) Webhook configuration. (see [below for nested schema](#nestedblock--webhook))

<a id="nestedblock--webhook"></a>
### Nested Schema for `webhook`

Read-Only:

- `name` (String) The webook name.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "stacklet_configuration_profile_jira" "example" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "stacklet_configuration_profile_slack" "example" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "stacklet_configuration_profile_teams" "example" {}
72 changes: 71 additions & 1 deletion internal/api/configuration_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ type ConfigurationProfile struct {
TypeName string `graphql:"__typename"`
EmailConfiguration EmailConfiguration `graphql:"... on EmailConfiguration"`
ServiceNowConfiguration ServiceNowConfiguration `graphql:"... on ServiceNowConfiguration"`
SlackConfiguration SlackConfiguration `graphql:"... on SlackConfiguration"`
SymphonyConfiguration SymphonyConfiguration `graphql:"... on SymphonyConfiguration"`
TeamsConfiguration TeamsConfiguration `graphql:"... on TeamsConfiguration"`
JiraConfiguration JiraConfiguration `graphql:"... on JiraConfiguration"`
}
}

Expand All @@ -39,7 +42,6 @@ type SMTPConfiguration struct {
type ServiceNowConfiguration struct {
Endpoint string
User string
Password string
IssueType string
ClosedState string
}
Expand All @@ -50,6 +52,44 @@ type SymphonyConfiguration struct {
ServiceAccount string
}

// SlackConfiguration is the configuration for Symphony profiles.
type SlackConfiguration struct {
UserFields []string
Webhooks []SlackWebhook
}

// SlackWebhook is a webhook configuration for Slack.
type SlackWebhook struct {
Name string
URL string `graphql:"url"`
}

// TeamsConfiguration is the configuration for Microsoft Teams profiles.
type TeamsConfiguration struct {
Webhooks []TeamsWebhook
}

// TeamsWebhook is a webhook configuration for Microsoft Teams.
type TeamsWebhook struct {
Name string
URL string `graphql:"url"`
}

// JiraConfiguation is the configuration for Jira profiles.
type JiraConfiguration struct {
URL *string `graphql:"url"`
Projects []JiraProject
User string
}

// JiraPorject is the configuration for a Jira project.
type JiraProject struct {
ClosedStatus string
IssueType string
Name string
Project string
}

type configurationProfileAPI struct {
c *graphql.Client
}
Expand All @@ -73,3 +113,33 @@ func (a configurationProfileAPI) Read(ctx context.Context, name ConfigurationPro

return &query.Configuration, nil
}

// ReadEmail returns data for the email configuration profile.
func (a configurationProfileAPI) ReadEmail(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileEmail)
}

// ReadSlack returns data for the Slack configuration profile.
func (a configurationProfileAPI) ReadSlack(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileSlack)
}

// ReadTeams returns data for the Microsoft Teams configuration profile.
func (a configurationProfileAPI) ReadTeams(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileTeams)
}

// ReadSymphony returns data for the Symphony configuration profile.
func (a configurationProfileAPI) ReadSymphony(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileSymphony)
}

// ReadSymphony returns data for the ServiceNow configuration profile.
func (a configurationProfileAPI) ReadServiceNow(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileServiceNow)
}

// ReadJira returns data for the Jira configuration profile.
func (a configurationProfileAPI) ReadJira(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileJira)
}
2 changes: 1 addition & 1 deletion internal/api/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var REPORT_SOURCES = []ReportSource{
//
// This is defined as a type since profiles are looked up by names matching
// type.
type ConfigurationProfileName string
type ConfigurationProfileName StringEnum

const (
ConfigurationProfileEmail = ConfigurationProfileName("email")
Expand Down
2 changes: 1 addition & 1 deletion internal/datasources/configuration_profile_email.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (d *configurationProfileEmailDataSource) Read(ctx context.Context, req data
return
}

config, err := d.api.ConfigurationProfile.Read(ctx, api.ConfigurationProfileEmail)
config, err := d.api.ConfigurationProfile.ReadEmail(ctx)
if err != nil {
errors.AddDiagError(&resp.Diagnostics, err)
return
Expand Down
119 changes: 119 additions & 0 deletions internal/datasources/configuration_profile_jira.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Copyright (c) 2025 - Stacklet, Inc.

package datasources

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/stacklet/terraform-provider-stacklet/internal/api"
"github.com/stacklet/terraform-provider-stacklet/internal/errors"
"github.com/stacklet/terraform-provider-stacklet/internal/models"
"github.com/stacklet/terraform-provider-stacklet/internal/modelupdate"
"github.com/stacklet/terraform-provider-stacklet/internal/providerdata"
)

var (
_ datasource.DataSource = &configurationProfileJiraDataSource{}
)

func NewConfigurationProfileJiraDataSource() datasource.DataSource {
return &configurationProfileJiraDataSource{}
}

type configurationProfileJiraDataSource struct {
api *api.API
}

func (d *configurationProfileJiraDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_configuration_profile_jira"
}

func (d *configurationProfileJiraDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieve information about the Jira configuration profile.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "The GraphQL Node ID of the configuration profile.",
Computed: true,
},
"profile": schema.StringAttribute{
Description: "The profile name.",
Computed: true,
},
"url": schema.StringAttribute{
Description: "The Jira instance URL.",
Computed: true,
},
"user": schema.StringAttribute{
Description: "The Jira instance authentication username.",
Computed: true,
},
},
Blocks: map[string]schema.Block{
"project": schema.ListNestedBlock{
Description: "Jira project configuration.",
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"closed_status": schema.StringAttribute{
Description: "The state for closed tickets.",
Computed: true,
},
"issue_type": schema.StringAttribute{
Description: "The type of issue to use for tickets.",
Computed: true,
},
"name": schema.StringAttribute{
Description: "The name of the project.",
Computed: true,
},
"project": schema.StringAttribute{
Description: "The ID of the project.",
Computed: true,
},
},
},
},
},
}
}

func (d *configurationProfileJiraDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
if pd, err := providerdata.GetDataSourceProviderData(req); err != nil {
errors.AddDiagError(&resp.Diagnostics, err)
} else if pd != nil {
d.api = pd.API
}
}

func (d *configurationProfileJiraDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data models.ConfigurationProfileJiraDataSource
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

config, err := d.api.ConfigurationProfile.ReadJira(ctx)
if err != nil {
errors.AddDiagError(&resp.Diagnostics, err)
return
}

data.ID = types.StringValue(config.ID)
data.Profile = types.StringValue(config.Profile)
data.URL = types.StringPointerValue(config.Record.JiraConfiguration.URL)
data.User = types.StringValue(config.Record.JiraConfiguration.User)

updater := modelupdate.NewConfigurationProfileUpdater(*config)
projects, diags := updater.JiraProjects()
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
data.Projects = projects

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
2 changes: 1 addition & 1 deletion internal/datasources/configuration_profile_servicenow.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (d *configurationProfileServiceNowDataSource) Read(ctx context.Context, req
return
}

config, err := d.api.ConfigurationProfile.Read(ctx, api.ConfigurationProfileServiceNow)
config, err := d.api.ConfigurationProfile.ReadServiceNow(ctx)
if err != nil {
errors.AddDiagError(&resp.Diagnostics, err)
return
Expand Down
Loading