Skip to content

Commit

Permalink
Workflows can be configured to require a Jira ticket (#149)
Browse files Browse the repository at this point in the history
* Add has Jira ticket to validation on workflows

* changeset

* Generate documentation

* bump sdk

---------

Co-authored-by: JoshuaWilkes <[email protected]>
Co-authored-by: Calvin <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent 6530457 commit a9e6218
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-bats-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@common-fate/terraform-provider-commonfate": patch
---

Add has_jira_ticket to workflow validation block
1 change: 1 addition & 0 deletions docs/resources/access_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Required:

Optional:

- `has_jira_ticket` (Boolean) Whether a jira ticket is required for this workflow
- `has_reason` (Boolean) Whether a reason is required for this workflow
- `reason_regex` (Attributes List) Regex validation requirements for the reason (see [below for nested schema](#nestedatt--validation--reason_regex))

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.21.4
require (
connectrpc.com/connect v1.14.0
github.com/common-fate/grab v1.1.0
github.com/common-fate/sdk v1.70.1
github.com/common-fate/sdk v1.71.0
github.com/hashicorp/terraform-plugin-docs v0.13.0
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/hashicorp/terraform-plugin-log v0.9.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ github.com/common-fate/grab v1.1.0 h1:HLZPtltdHScYu6qtt/UC78rvwylCTWuyoZoiQXV4QH
github.com/common-fate/grab v1.1.0/go.mod h1:L0qa03RwqOMZz9PrrWw9eI145i5FQRf+iLtNSJypQvY=
github.com/common-fate/sdk v1.68.0 h1:Dh4C7oDlmiHRmeDI4TkVkQtM/eAoFqJERo2nKGG/OdA=
github.com/common-fate/sdk v1.68.0/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.69.2-0.20241113070817-3ecc2451b18c h1:UZwxZfZQ95cyv9IbYQd7XnDgV1CueX7e56qXt/OiZ+I=
github.com/common-fate/sdk v1.69.2-0.20241113070817-3ecc2451b18c/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.70.1 h1:EB4sxv1OrdNA0kZ4vVDom1nGOwbvzVUb6xO4mFYB8oo=
github.com/common-fate/sdk v1.70.1/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.70.1-0.20241122042851-f058c24acb42 h1:d6Pdla8OFHzCVK0FwyN2EOj8Q6AnpagqvVOAU0mV3/s=
github.com/common-fate/sdk v1.70.1-0.20241122042851-f058c24acb42/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/common-fate/sdk v1.71.0 h1:SA+KZdbkOWBR6SrTculoUlALAGj6ftULdUPgr3Yw7RY=
github.com/common-fate/sdk v1.71.0/go.mod h1:OrXhzB2Y1JSrKGHrb4qRmY+6MF2M3MFb+3edBnessXo=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
Expand Down
26 changes: 18 additions & 8 deletions internal/access/resource_access_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
)

type Validations struct {
HasReason types.Bool `tfsdk:"has_reason"`
ReasonRegex []RegexValidation `tfsdk:"reason_regex"`
HasReason types.Bool `tfsdk:"has_reason"`
ReasonRegex []RegexValidation `tfsdk:"reason_regex"`
HasJiraTicket types.Bool `tfsdk:"has_jira_ticket"`
}

type RegexValidation struct {
Expand Down Expand Up @@ -168,6 +169,12 @@ func (r *AccessWorkflowResource) Schema(ctx context.Context, req resource.Schema
},
},
},
"has_jira_ticket": schema.BoolAttribute{
MarkdownDescription: "Whether a jira ticket is required for this workflow",
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
},
},
"extension_conditions": schema.SingleNestedAttribute{
Expand Down Expand Up @@ -273,8 +280,9 @@ func (r *AccessWorkflowResource) Create(ctx context.Context, req resource.Create
}

createReq.Validation = &configv1alpha1.ValidationConfig{
HasReason: data.Validation.HasReason.ValueBool(),
ReasonRegex: regexValidations,
HasReason: data.Validation.HasReason.ValueBool(),
ReasonRegex: regexValidations,
HasJiraTicket: data.Validation.HasJiraTicket.ValueBool(),
}
}

Expand Down Expand Up @@ -403,8 +411,9 @@ func (r *AccessWorkflowResource) Read(ctx context.Context, req resource.ReadRequ
}

state.Validation = &Validations{
HasReason: types.BoolValue(res.Msg.Workflow.Validation.HasReason),
ReasonRegex: regexValidations,
HasReason: types.BoolValue(res.Msg.Workflow.Validation.HasReason),
ReasonRegex: regexValidations,
HasJiraTicket: types.BoolValue(res.Msg.Workflow.Validation.HasJiraTicket),
}
}

Expand Down Expand Up @@ -488,8 +497,9 @@ func (r *AccessWorkflowResource) Update(ctx context.Context, req resource.Update
}

updateReq.Workflow.Validation = &configv1alpha1.ValidationConfig{
HasReason: data.Validation.HasReason.ValueBool(),
ReasonRegex: regexValidations,
HasReason: data.Validation.HasReason.ValueBool(),
ReasonRegex: regexValidations,
HasJiraTicket: data.Validation.HasJiraTicket.ValueBool(),
}
}

Expand Down

0 comments on commit a9e6218

Please sign in to comment.