Skip to content

Commit ff6d3cf

Browse files
feat: add datasource for resource and account owners configuration [ENG-5558] (#100)
[ENG-5558](https://stacklet.atlassian.net/browse/ENG-5558) ### what add datasources for account owners and resource owner configuration profiles ### why access the current configuration ### testing tested in sandbox ### docs updated here [ENG-5558]: https://stacklet.atlassian.net/browse/ENG-5558?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 3cc16bb commit ff6d3cf

File tree

12 files changed

+395
-13
lines changed

12 files changed

+395
-13
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stacklet_configuration_profile_account_owners Data Source - terraform-provider-stacklet"
4+
subcategory: ""
5+
description: |-
6+
Retrieve information about the account owners configuration profile.
7+
---
8+
9+
# stacklet_configuration_profile_account_owners (Data Source)
10+
11+
Retrieve information about the account owners configuration profile.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stacklet_configuration_profile_account_owners" "example" {}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Read-Only
23+
24+
- `default` (Attributes List) List of default account owners. (see [below for nested schema](#nestedatt--default))
25+
- `id` (String) The GraphQL Node ID of the configuration profile.
26+
- `org_domain` (String) The organization domain to append to users for matching.
27+
- `org_domain_tag` (String) The name of the tag to look up the organization domain.
28+
- `profile` (String) The profile name.
29+
- `tags` (List of String) List of tag names to look up the resource owner.
30+
31+
<a id="nestedatt--default"></a>
32+
### Nested Schema for `default`
33+
34+
Read-Only:
35+
36+
- `account` (String) The account identifier.
37+
- `owners` (List of String) List of owner addresses for this account.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stacklet_configuration_profile_resource_owner Data Source - terraform-provider-stacklet"
4+
subcategory: ""
5+
description: |-
6+
Retrieve information about the resource owner configuration profile.
7+
---
8+
9+
# stacklet_configuration_profile_resource_owner (Data Source)
10+
11+
Retrieve information about the resource owner configuration profile.
12+
13+
## Example Usage
14+
15+
```terraform
16+
data "stacklet_configuration_profile_resource_owner" "example" {}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Read-Only
23+
24+
- `default` (List of String) List of fallback notification addresses.
25+
- `id` (String) The GraphQL Node ID of the configuration profile.
26+
- `org_domain` (String) The organization domain to append to users for matching.
27+
- `org_domain_tag` (String) The name of the tag to look up the organization domain.
28+
- `profile` (String) The profile name.
29+
- `tags` (List of String) List of tag names to look up the resource owner.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "stacklet_configuration_profile_account_owners" "example" {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data "stacklet_configuration_profile_resource_owner" "example" {}

internal/api/configuration_profile.go

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ type ConfigurationProfile struct {
1313
ID string
1414
Profile string
1515
Record struct {
16-
TypeName string `graphql:"__typename"`
17-
EmailConfiguration EmailConfiguration `graphql:"... on EmailConfiguration"`
18-
ServiceNowConfiguration ServiceNowConfiguration `graphql:"... on ServiceNowConfiguration"`
19-
SlackConfiguration SlackConfiguration `graphql:"... on SlackConfiguration"`
20-
SymphonyConfiguration SymphonyConfiguration `graphql:"... on SymphonyConfiguration"`
21-
TeamsConfiguration TeamsConfiguration `graphql:"... on TeamsConfiguration"`
22-
JiraConfiguration JiraConfiguration `graphql:"... on JiraConfiguration"`
16+
TypeName string `graphql:"__typename"`
17+
EmailConfiguration EmailConfiguration `graphql:"... on EmailConfiguration"`
18+
ServiceNowConfiguration ServiceNowConfiguration `graphql:"... on ServiceNowConfiguration"`
19+
SlackConfiguration SlackConfiguration `graphql:"... on SlackConfiguration"`
20+
SymphonyConfiguration SymphonyConfiguration `graphql:"... on SymphonyConfiguration"`
21+
TeamsConfiguration TeamsConfiguration `graphql:"... on TeamsConfiguration"`
22+
JiraConfiguration JiraConfiguration `graphql:"... on JiraConfiguration"`
23+
ResourceOwnerConfiguration ResourceOwnerConfiguration `graphql:"... on ResourceOwnerConfiguration"`
24+
AccountOwnersConfiguration AccountOwnersConfiguration `graphql:"... on AccountOwnersConfiguration"`
2325
}
2426
}
2527

@@ -90,6 +92,28 @@ type JiraProject struct {
9092
Project string
9193
}
9294

95+
// ResourceOwnerConfiguration is the configuation for resource owner.
96+
type ResourceOwnerConfiguration struct {
97+
Default []string `graphql:"resourceOwnerDefault: default"`
98+
OrgDomain *string
99+
OrgDomainTag *string
100+
Tags []string
101+
}
102+
103+
// AccountOwnersConfiguration is the configuration for account owners.
104+
type AccountOwnersConfiguration struct {
105+
Default []AccountOwners `graphql:"accountOwnersDefault: default"`
106+
OrgDomain *string
107+
OrgDomainTag *string
108+
Tags []string
109+
}
110+
111+
// AccountOwners tracks the owners for an account.
112+
type AccountOwners struct {
113+
Account string
114+
Owners []string
115+
}
116+
93117
type configurationProfileAPI struct {
94118
c *graphql.Client
95119
}
@@ -143,3 +167,13 @@ func (a configurationProfileAPI) ReadServiceNow(ctx context.Context) (*Configura
143167
func (a configurationProfileAPI) ReadJira(ctx context.Context) (*ConfigurationProfile, error) {
144168
return a.Read(ctx, ConfigurationProfileJira)
145169
}
170+
171+
// ReadAccountOwners returns data for the account owners configuration profile.
172+
func (a configurationProfileAPI) ReadAccountOwners(ctx context.Context) (*ConfigurationProfile, error) {
173+
return a.Read(ctx, ConfigurationProfileAccountOwners)
174+
}
175+
176+
// ReadResourceOwner returns data for the account owners configuration profile.
177+
func (a configurationProfileAPI) ReadResourceOwner(ctx context.Context) (*ConfigurationProfile, error) {
178+
return a.Read(ctx, ConfigurationProfileResourceOwner)
179+
}

internal/api/enums.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ var REPORT_SOURCES = []ReportSource{
4545
type ConfigurationProfileName StringEnum
4646

4747
const (
48-
ConfigurationProfileEmail = ConfigurationProfileName("email")
49-
ConfigurationProfileSlack = ConfigurationProfileName("slack")
50-
ConfigurationProfileTeams = ConfigurationProfileName("teams")
51-
ConfigurationProfileServiceNow = ConfigurationProfileName("servicenow")
52-
ConfigurationProfileJira = ConfigurationProfileName("jira")
53-
ConfigurationProfileSymphony = ConfigurationProfileName("symphony")
48+
ConfigurationProfileEmail = ConfigurationProfileName("email")
49+
ConfigurationProfileSlack = ConfigurationProfileName("slack")
50+
ConfigurationProfileTeams = ConfigurationProfileName("teams")
51+
ConfigurationProfileServiceNow = ConfigurationProfileName("servicenow")
52+
ConfigurationProfileJira = ConfigurationProfileName("jira")
53+
ConfigurationProfileSymphony = ConfigurationProfileName("symphony")
54+
ConfigurationProfileAccountOwners = ConfigurationProfileName("account_owners")
55+
ConfigurationProfileResourceOwner = ConfigurationProfileName("resource_owner")
5456
)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
tftypes "github.com/stacklet/terraform-provider-stacklet/internal/types"
18+
)
19+
20+
var (
21+
_ datasource.DataSource = &configurationProfileAccountOwnersDataSource{}
22+
)
23+
24+
func NewConfigurationProfileAccountOwnersDataSource() datasource.DataSource {
25+
return &configurationProfileAccountOwnersDataSource{}
26+
}
27+
28+
type configurationProfileAccountOwnersDataSource struct {
29+
api *api.API
30+
}
31+
32+
func (d *configurationProfileAccountOwnersDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
33+
resp.TypeName = req.ProviderTypeName + "_configuration_profile_account_owners"
34+
}
35+
36+
func (d *configurationProfileAccountOwnersDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
37+
resp.Schema = schema.Schema{
38+
Description: "Retrieve information about the account owners configuration profile.",
39+
Attributes: map[string]schema.Attribute{
40+
"id": schema.StringAttribute{
41+
Description: "The GraphQL Node ID of the configuration profile.",
42+
Computed: true,
43+
},
44+
"profile": schema.StringAttribute{
45+
Description: "The profile name.",
46+
Computed: true,
47+
},
48+
"default": schema.ListNestedAttribute{
49+
Description: "List of default account owners.",
50+
Computed: true,
51+
NestedObject: schema.NestedAttributeObject{
52+
Attributes: map[string]schema.Attribute{
53+
"account": schema.StringAttribute{
54+
Description: "The account identifier.",
55+
Computed: true,
56+
},
57+
"owners": schema.ListAttribute{
58+
Description: "List of owner addresses for this account.",
59+
ElementType: types.StringType,
60+
Computed: true,
61+
},
62+
},
63+
},
64+
},
65+
"org_domain": schema.StringAttribute{
66+
Description: "The organization domain to append to users for matching.",
67+
Computed: true,
68+
},
69+
"org_domain_tag": schema.StringAttribute{
70+
Description: "The name of the tag to look up the organization domain.",
71+
Computed: true,
72+
},
73+
"tags": schema.ListAttribute{
74+
Description: "List of tag names to look up the resource owner.",
75+
ElementType: types.StringType,
76+
Computed: true,
77+
},
78+
},
79+
}
80+
}
81+
82+
func (d *configurationProfileAccountOwnersDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
83+
if pd, err := providerdata.GetDataSourceProviderData(req); err != nil {
84+
errors.AddDiagError(&resp.Diagnostics, err)
85+
} else if pd != nil {
86+
d.api = pd.API
87+
}
88+
}
89+
90+
func (d *configurationProfileAccountOwnersDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
91+
var data models.ConfigurationProfileAccountOwnersDataSource
92+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
93+
if resp.Diagnostics.HasError() {
94+
return
95+
}
96+
97+
config, err := d.api.ConfigurationProfile.ReadAccountOwners(ctx)
98+
if err != nil {
99+
errors.AddDiagError(&resp.Diagnostics, err)
100+
return
101+
}
102+
103+
data.ID = types.StringValue(config.ID)
104+
data.Profile = types.StringValue(config.Profile)
105+
106+
updater := modelupdate.NewConfigurationProfileUpdater(*config)
107+
defaultOwners, diags := updater.AccountOwnersDefault()
108+
resp.Diagnostics.Append(diags...)
109+
if resp.Diagnostics.HasError() {
110+
return
111+
}
112+
data.Default = defaultOwners
113+
114+
data.OrgDomain = types.StringPointerValue(config.Record.AccountOwnersConfiguration.OrgDomain)
115+
data.OrgDomainTag = types.StringPointerValue(config.Record.AccountOwnersConfiguration.OrgDomainTag)
116+
data.Tags = tftypes.StringsList(config.Record.AccountOwnersConfiguration.Tags)
117+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
118+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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/providerdata"
16+
tftypes "github.com/stacklet/terraform-provider-stacklet/internal/types"
17+
)
18+
19+
var (
20+
_ datasource.DataSource = &configurationProfileResourceOwnerDataSource{}
21+
)
22+
23+
func NewConfigurationProfileResourceOwnerDataSource() datasource.DataSource {
24+
return &configurationProfileResourceOwnerDataSource{}
25+
}
26+
27+
type configurationProfileResourceOwnerDataSource struct {
28+
api *api.API
29+
}
30+
31+
func (d *configurationProfileResourceOwnerDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
32+
resp.TypeName = req.ProviderTypeName + "_configuration_profile_resource_owner"
33+
}
34+
35+
func (d *configurationProfileResourceOwnerDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
36+
resp.Schema = schema.Schema{
37+
Description: "Retrieve information about the resource owner 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+
"default": schema.ListAttribute{
48+
Description: "List of fallback notification addresses.",
49+
ElementType: types.StringType,
50+
Computed: true,
51+
},
52+
"org_domain": schema.StringAttribute{
53+
Description: "The organization domain to append to users for matching.",
54+
Computed: true,
55+
},
56+
"org_domain_tag": schema.StringAttribute{
57+
Description: "The name of the tag to look up the organization domain.",
58+
Computed: true,
59+
},
60+
"tags": schema.ListAttribute{
61+
Description: "List of tag names to look up the resource owner.",
62+
ElementType: types.StringType,
63+
Computed: true,
64+
},
65+
},
66+
}
67+
}
68+
69+
func (d *configurationProfileResourceOwnerDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
70+
if pd, err := providerdata.GetDataSourceProviderData(req); err != nil {
71+
errors.AddDiagError(&resp.Diagnostics, err)
72+
} else if pd != nil {
73+
d.api = pd.API
74+
}
75+
}
76+
77+
func (d *configurationProfileResourceOwnerDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
78+
var data models.ConfigurationProfileResourceOwnerDataSource
79+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
80+
if resp.Diagnostics.HasError() {
81+
return
82+
}
83+
84+
config, err := d.api.ConfigurationProfile.ReadResourceOwner(ctx)
85+
if err != nil {
86+
errors.AddDiagError(&resp.Diagnostics, err)
87+
return
88+
}
89+
90+
data.ID = types.StringValue(config.ID)
91+
data.Profile = types.StringValue(config.Profile)
92+
data.Default = tftypes.StringsList(config.Record.ResourceOwnerConfiguration.Default)
93+
data.OrgDomain = types.StringPointerValue(config.Record.ResourceOwnerConfiguration.OrgDomain)
94+
data.OrgDomainTag = types.StringPointerValue(config.Record.ResourceOwnerConfiguration.OrgDomainTag)
95+
data.Tags = tftypes.StringsList(config.Record.ResourceOwnerConfiguration.Tags)
96+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
97+
}

internal/datasources/datasources.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ var DATASOURCES = []func() datasource.DataSource{
1010
NewAccountDataSource,
1111
NewAccountGroupDataSource,
1212
NewBindingDataSource,
13+
NewConfigurationProfileAccountOwnersDataSource,
1314
NewConfigurationProfileEmailDataSource,
1415
NewConfigurationProfileJiraDataSource,
16+
NewConfigurationProfileResourceOwnerDataSource,
1517
NewConfigurationProfileServiceNowDataSource,
1618
NewConfigurationProfileSlackDataSource,
1719
NewConfigurationProfileSymphonyDataSource,

0 commit comments

Comments
 (0)