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
37 changes: 37 additions & 0 deletions docs/data-sources/configuration_profile_account_owners.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stacklet_configuration_profile_account_owners Data Source - terraform-provider-stacklet"
subcategory: ""
description: |-
Retrieve information about the account owners configuration profile.
---

# stacklet_configuration_profile_account_owners (Data Source)

Retrieve information about the account owners configuration profile.

## Example Usage

```terraform
data "stacklet_configuration_profile_account_owners" "example" {}
```

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

### Read-Only

- `default` (Attributes List) List of default account owners. (see [below for nested schema](#nestedatt--default))
- `id` (String) The GraphQL Node ID of the configuration profile.
- `org_domain` (String) The organization domain to append to users for matching.
- `org_domain_tag` (String) The name of the tag to look up the organization domain.
- `profile` (String) The profile name.
- `tags` (List of String) List of tag names to look up the resource owner.

<a id="nestedatt--default"></a>
### Nested Schema for `default`

Read-Only:

- `account` (String) The account identifier.
- `owners` (List of String) List of owner addresses for this account.
29 changes: 29 additions & 0 deletions docs/data-sources/configuration_profile_resource_owner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "stacklet_configuration_profile_resource_owner Data Source - terraform-provider-stacklet"
subcategory: ""
description: |-
Retrieve information about the resource owner configuration profile.
---

# stacklet_configuration_profile_resource_owner (Data Source)

Retrieve information about the resource owner configuration profile.

## Example Usage

```terraform
data "stacklet_configuration_profile_resource_owner" "example" {}
```

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

### Read-Only

- `default` (List of String) List of fallback notification addresses.
- `id` (String) The GraphQL Node ID of the configuration profile.
- `org_domain` (String) The organization domain to append to users for matching.
- `org_domain_tag` (String) The name of the tag to look up the organization domain.
- `profile` (String) The profile name.
- `tags` (List of String) List of tag names to look up the resource owner.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "stacklet_configuration_profile_account_owners" "example" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "stacklet_configuration_profile_resource_owner" "example" {}
48 changes: 41 additions & 7 deletions internal/api/configuration_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ type ConfigurationProfile struct {
ID string
Profile string
Record 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"`
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"`
ResourceOwnerConfiguration ResourceOwnerConfiguration `graphql:"... on ResourceOwnerConfiguration"`
AccountOwnersConfiguration AccountOwnersConfiguration `graphql:"... on AccountOwnersConfiguration"`
}
}

Expand Down Expand Up @@ -90,6 +92,28 @@ type JiraProject struct {
Project string
}

// ResourceOwnerConfiguration is the configuation for resource owner.
type ResourceOwnerConfiguration struct {
Default []string `graphql:"resourceOwnerDefault: default"`
OrgDomain *string
OrgDomainTag *string
Tags []string
}

// AccountOwnersConfiguration is the configuration for account owners.
type AccountOwnersConfiguration struct {
Default []AccountOwners `graphql:"accountOwnersDefault: default"`
OrgDomain *string
OrgDomainTag *string
Tags []string
}

// AccountOwners tracks the owners for an account.
type AccountOwners struct {
Account string
Owners []string
}

type configurationProfileAPI struct {
c *graphql.Client
}
Expand Down Expand Up @@ -143,3 +167,13 @@ func (a configurationProfileAPI) ReadServiceNow(ctx context.Context) (*Configura
func (a configurationProfileAPI) ReadJira(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileJira)
}

// ReadAccountOwners returns data for the account owners configuration profile.
func (a configurationProfileAPI) ReadAccountOwners(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileAccountOwners)
}

// ReadResourceOwner returns data for the account owners configuration profile.
func (a configurationProfileAPI) ReadResourceOwner(ctx context.Context) (*ConfigurationProfile, error) {
return a.Read(ctx, ConfigurationProfileResourceOwner)
}
14 changes: 8 additions & 6 deletions internal/api/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ var REPORT_SOURCES = []ReportSource{
type ConfigurationProfileName StringEnum

const (
ConfigurationProfileEmail = ConfigurationProfileName("email")
ConfigurationProfileSlack = ConfigurationProfileName("slack")
ConfigurationProfileTeams = ConfigurationProfileName("teams")
ConfigurationProfileServiceNow = ConfigurationProfileName("servicenow")
ConfigurationProfileJira = ConfigurationProfileName("jira")
ConfigurationProfileSymphony = ConfigurationProfileName("symphony")
ConfigurationProfileEmail = ConfigurationProfileName("email")
ConfigurationProfileSlack = ConfigurationProfileName("slack")
ConfigurationProfileTeams = ConfigurationProfileName("teams")
ConfigurationProfileServiceNow = ConfigurationProfileName("servicenow")
ConfigurationProfileJira = ConfigurationProfileName("jira")
ConfigurationProfileSymphony = ConfigurationProfileName("symphony")
ConfigurationProfileAccountOwners = ConfigurationProfileName("account_owners")
ConfigurationProfileResourceOwner = ConfigurationProfileName("resource_owner")
)
118 changes: 118 additions & 0 deletions internal/datasources/configuration_profile_account_owners.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// 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"
tftypes "github.com/stacklet/terraform-provider-stacklet/internal/types"
)

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

func NewConfigurationProfileAccountOwnersDataSource() datasource.DataSource {
return &configurationProfileAccountOwnersDataSource{}
}

type configurationProfileAccountOwnersDataSource struct {
api *api.API
}

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

func (d *configurationProfileAccountOwnersDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieve information about the account owners 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,
},
"default": schema.ListNestedAttribute{
Description: "List of default account owners.",
Computed: true,
NestedObject: schema.NestedAttributeObject{
Attributes: map[string]schema.Attribute{
"account": schema.StringAttribute{
Description: "The account identifier.",
Computed: true,
},
"owners": schema.ListAttribute{
Description: "List of owner addresses for this account.",
ElementType: types.StringType,
Computed: true,
},
},
},
},
"org_domain": schema.StringAttribute{
Description: "The organization domain to append to users for matching.",
Computed: true,
},
"org_domain_tag": schema.StringAttribute{
Description: "The name of the tag to look up the organization domain.",
Computed: true,
},
"tags": schema.ListAttribute{
Description: "List of tag names to look up the resource owner.",
ElementType: types.StringType,
Computed: true,
},
},
}
}

func (d *configurationProfileAccountOwnersDataSource) 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 *configurationProfileAccountOwnersDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data models.ConfigurationProfileAccountOwnersDataSource
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

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

data.ID = types.StringValue(config.ID)
data.Profile = types.StringValue(config.Profile)

updater := modelupdate.NewConfigurationProfileUpdater(*config)
defaultOwners, diags := updater.AccountOwnersDefault()
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
data.Default = defaultOwners

data.OrgDomain = types.StringPointerValue(config.Record.AccountOwnersConfiguration.OrgDomain)
data.OrgDomainTag = types.StringPointerValue(config.Record.AccountOwnersConfiguration.OrgDomainTag)
data.Tags = tftypes.StringsList(config.Record.AccountOwnersConfiguration.Tags)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
97 changes: 97 additions & 0 deletions internal/datasources/configuration_profile_resource_owner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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/providerdata"
tftypes "github.com/stacklet/terraform-provider-stacklet/internal/types"
)

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

func NewConfigurationProfileResourceOwnerDataSource() datasource.DataSource {
return &configurationProfileResourceOwnerDataSource{}
}

type configurationProfileResourceOwnerDataSource struct {
api *api.API
}

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

func (d *configurationProfileResourceOwnerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Retrieve information about the resource owner 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,
},
"default": schema.ListAttribute{
Description: "List of fallback notification addresses.",
ElementType: types.StringType,
Computed: true,
},
"org_domain": schema.StringAttribute{
Description: "The organization domain to append to users for matching.",
Computed: true,
},
"org_domain_tag": schema.StringAttribute{
Description: "The name of the tag to look up the organization domain.",
Computed: true,
},
"tags": schema.ListAttribute{
Description: "List of tag names to look up the resource owner.",
ElementType: types.StringType,
Computed: true,
},
},
}
}

func (d *configurationProfileResourceOwnerDataSource) 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 *configurationProfileResourceOwnerDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var data models.ConfigurationProfileResourceOwnerDataSource
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

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

data.ID = types.StringValue(config.ID)
data.Profile = types.StringValue(config.Profile)
data.Default = tftypes.StringsList(config.Record.ResourceOwnerConfiguration.Default)
data.OrgDomain = types.StringPointerValue(config.Record.ResourceOwnerConfiguration.OrgDomain)
data.OrgDomainTag = types.StringPointerValue(config.Record.ResourceOwnerConfiguration.OrgDomainTag)
data.Tags = tftypes.StringsList(config.Record.ResourceOwnerConfiguration.Tags)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
2 changes: 2 additions & 0 deletions internal/datasources/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ var DATASOURCES = []func() datasource.DataSource{
NewAccountDataSource,
NewAccountGroupDataSource,
NewBindingDataSource,
NewConfigurationProfileAccountOwnersDataSource,
NewConfigurationProfileEmailDataSource,
NewConfigurationProfileJiraDataSource,
NewConfigurationProfileResourceOwnerDataSource,
NewConfigurationProfileServiceNowDataSource,
NewConfigurationProfileSlackDataSource,
NewConfigurationProfileSymphonyDataSource,
Expand Down
Loading