Skip to content

Commit

Permalink
Add project tags attribute (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
shilgapira authored Jan 9, 2025
1 parent db2163d commit 70afaae
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/raw/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ left unset for development or staging projects.



tags
----

- Type: `list` of `string`

Descriptive tags for your Descope project. Each tag must be no more than 50 characters long.



project_settings
----------------

Expand Down
1 change: 1 addition & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ description: |-
- `jwt_templates` (Attributes) Defines templates for JSON Web Tokens (JWT) used for authentication. (see [below for nested schema](#nestedatt--jwt_templates))
- `project_settings` (Attributes) General settings for the Descope project. (see [below for nested schema](#nestedatt--project_settings))
- `styles` (Attributes) Custom styles that can be applied to the project's authentication flows. (see [below for nested schema](#nestedatt--styles))
- `tags` (List of String) Descriptive tags for your Descope project. Tags can contain any character but must be no more than 50 characters long.

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions internal/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/models/helpers/strlistattr/strlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Get(s []string, data map[string]any, key string) {

func Set(s *[]string, data map[string]any, key string) {
if v, ok := data[key].([]any); ok {
*s = []string{}
if len(v) > 0 {
for i := range v {
str, ok := v[i].(string)
Expand Down
6 changes: 6 additions & 0 deletions internal/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
"github.com/descope/terraform-provider-descope/internal/models/helpers/mapattr"
"github.com/descope/terraform-provider-descope/internal/models/helpers/objectattr"
"github.com/descope/terraform-provider-descope/internal/models/helpers/stringattr"
"github.com/descope/terraform-provider-descope/internal/models/helpers/strlistattr"
"github.com/descope/terraform-provider-descope/internal/models/jwttemplates"
"github.com/descope/terraform-provider-descope/internal/models/settings"
"github.com/hashicorp/terraform-plugin-framework-validators/listvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand All @@ -25,6 +27,7 @@ var ProjectAttributes = map[string]schema.Attribute{
"id": stringattr.Identifier(),
"name": stringattr.Required(),
"environment": stringattr.Optional(stringvalidator.OneOf("", "production")),
"tags": strlistattr.Optional(listvalidator.ValueStringsAre(stringvalidator.LengthBetween(1, 50))),
"project_settings": objectattr.Optional(settings.SettingsAttributes, settings.SettingsValidator),
"authentication": objectattr.Optional(authentication.AuthenticationAttributes),
"authorization": objectattr.Optional(authorization.AuthorizationAttributes, authorization.AuthorizationValidator),
Expand All @@ -40,6 +43,7 @@ type ProjectModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Environment types.String `tfsdk:"environment"`
Tags []string `tfsdk:"tags"`
Settings *settings.SettingsModel `tfsdk:"project_settings"`
Authentication *authentication.AuthenticationModel `tfsdk:"authentication"`
Authorization *authorization.AuthorizationModel `tfsdk:"authorization"`
Expand All @@ -56,6 +60,7 @@ func (m *ProjectModel) Values(h *helpers.Handler) map[string]any {
data["version"] = ModelVersion
stringattr.Get(m.Name, data, "name")
stringattr.Get(m.Environment, data, "environment")
strlistattr.Get(m.Tags, data, "tags")
objectattr.Get(m.Settings, data, "settings", h)
objectattr.Get(m.Authentication, data, "authentication", h)
objectattr.Get(m.Connectors, data, "connectors", h)
Expand All @@ -75,6 +80,7 @@ func (m *ProjectModel) SetValues(h *helpers.Handler, data map[string]any) {

stringattr.Set(&m.Name, data, "name")
stringattr.Set(&m.Environment, data, "environment")
strlistattr.Set(&m.Tags, data, "tags")
objectattr.Set(&m.Settings, data, "settings", h)
objectattr.Set(&m.Authentication, data, "authentication", h)
objectattr.Set(&m.Connectors, data, "connectors", h)
Expand Down
15 changes: 14 additions & 1 deletion internal/models/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestProject(t *testing.T) {
"id": testacc.AttributeIsSet,
"name": p.Name,
"environment": "production",
"tags": []string{},
}),
},
resource.TestStep{
Expand All @@ -38,7 +39,19 @@ func TestProject(t *testing.T) {
},
Config: p.Config(),
Check: p.Check(map[string]any{
"name": p.Name,
"name": p.Name,
"environment": "production",
}),
},
resource.TestStep{
Config: p.Config(`
environment = ""
tags = ["foo", "bar"]
`),
Check: p.Check(map[string]any{
"name": p.Name,
"tags": []string{"foo", "bar"},
"environment": "",
}),
},
)
Expand Down

0 comments on commit 70afaae

Please sign in to comment.