-
Notifications
You must be signed in to change notification settings - Fork 32
feat: Add support for AI Configs and Segment approval settings in environment resource #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ldhenry
wants to merge
12
commits into
main
Choose a base branch
from
feat/approval-settings-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b7b616a
feat: add support for segment and aiconfig approvals
tarqd 7795a7e
feat: add validation for approval_settings with non-flag resources
tarqd 2365e20
test: add acceptance tests for approval_settings validation
tarqd 814f6fb
Run 'make generate'
ldhenry e9a90ef
Run 'make fmt'
ldhenry d50d644
Apply suggestion from @ldhenry
ldhenry dc027bc
fix: only include segment/aiconfig approval settings if configured
tarqd 21eb9f9
fix: handle nil approval_settings in patch generation
tarqd e23c31a
chore: fix formatting
tarqd ebe3895
chore: remove unused functions and fix linter issues
tarqd 419ac96
docs: move approval settings migration guide to docs/guides
tarqd 0db99eb
docs: add front matter to approval settings migration guide
tarqd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 1.22.9 | ||
| 1.24.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,270 @@ | ||
| --- | ||
| page_title: "Migrating to multi-resource approval settings" | ||
| description: |- | ||
| This guide explains how to use the approval_settings block to configure approval requirements for flags, segments, and AI configs within the same environment. Learn about the new resource_kind attribute, validation rules, and how to migrate existing configurations. | ||
| --- | ||
|
|
||
| # Approval Settings Migration Guide | ||
|
|
||
| ## Overview | ||
|
|
||
| The `approval_settings` block now supports multiple resource kinds (flags, segments, and AI configs) while maintaining full backwards compatibility with existing configurations. | ||
|
|
||
| ## What's New | ||
|
|
||
| ### Multiple Approval Settings Blocks | ||
|
|
||
| You can now specify approval settings for different resource types within the same environment: | ||
|
|
||
| **Important**: `service_kind` and `service_config` are **only supported for flag approval settings** (`resource_kind = "flag"`). Using these fields with `resource_kind = "segment"` or `resource_kind = "aiconfig"` will result in a validation error. | ||
|
|
||
| ```hcl | ||
| resource "launchdarkly_environment" "example" { | ||
| name = "Production" | ||
| key = "production" | ||
| color = "FF0000" | ||
| project_key = "my-project" | ||
|
|
||
| # Flag approval settings | ||
| approval_settings { | ||
| resource_kind = "flag" | ||
| required = true | ||
| min_num_approvals = 2 | ||
| can_review_own_request = false | ||
| can_apply_declined_changes = false | ||
| } | ||
|
|
||
| # Segment approval settings | ||
| # Note: service_kind and service_config are not supported for segment approvals | ||
| approval_settings { | ||
| resource_kind = "segment" | ||
| required = true | ||
| min_num_approvals = 1 | ||
| can_apply_declined_changes = true | ||
| } | ||
|
|
||
| # AI Config approval settings | ||
| # Note: service_kind and service_config are not supported for aiconfig approvals | ||
| approval_settings { | ||
| resource_kind = "aiconfig" | ||
| required = false | ||
| min_num_approvals = 1 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### New Attribute: `resource_kind` | ||
|
|
||
| - **Type**: `string` | ||
| - **Optional**: Yes (defaults to `"flag"`) | ||
| - **Valid values**: `"flag"`, `"segment"`, `"aiconfig"` | ||
| - **Description**: Specifies which resource type the approval settings apply to | ||
|
|
||
| ### Validation | ||
|
|
||
| - Each `resource_kind` can only be specified once per environment | ||
| - Attempting to configure duplicate `resource_kind` values will result in a validation error | ||
|
|
||
| ## Backwards Compatibility | ||
|
|
||
| Existing configurations without the `resource_kind` attribute will continue to work exactly as before. The attribute defaults to `"flag"` when not specified: | ||
|
|
||
| ```hcl | ||
| # This configuration is still valid and equivalent to resource_kind = "flag" | ||
| resource "launchdarkly_environment" "example" { | ||
| name = "Production" | ||
| key = "production" | ||
| color = "FF0000" | ||
| project_key = "my-project" | ||
|
|
||
| approval_settings { | ||
| required = true | ||
| min_num_approvals = 1 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## API Mapping | ||
|
|
||
| ### Reading from API | ||
| - `approvalSettings` (root level) → `approval_settings` with `resource_kind = "flag"` | ||
| - `resourceApprovalSettings.segment` → `approval_settings` with `resource_kind = "segment"` | ||
| - `resourceApprovalSettings.aiconfig` → `approval_settings` with `resource_kind = "aiconfig"` | ||
|
|
||
| ### Writing to API | ||
| - `resource_kind = "flag"` → PATCH operations to `/approvalSettings/*` | ||
| - `resource_kind = "segment"` → PATCH operations to `/resourceApprovalSettings/segment/*` | ||
| - `resource_kind = "aiconfig"` → PATCH operations to `/resourceApprovalSettings/aiconfig/*` | ||
|
|
||
| ## Migration Examples | ||
|
|
||
| ### Before: Flag Approvals Only | ||
| ```hcl | ||
| resource "launchdarkly_environment" "prod" { | ||
| name = "Production" | ||
| key = "production" | ||
| project_key = "my-project" | ||
|
|
||
| approval_settings { | ||
| required = true | ||
| min_num_approvals = 2 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### After: Adding Segment Approvals | ||
| ```hcl | ||
| resource "launchdarkly_environment" "prod" { | ||
| name = "Production" | ||
| key = "production" | ||
| project_key = "my-project" | ||
|
|
||
| # Existing flag approvals (add resource_kind for clarity, but optional) | ||
| approval_settings { | ||
| resource_kind = "flag" | ||
| required = true | ||
| min_num_approvals = 2 | ||
| } | ||
|
|
||
| # New segment approvals | ||
| approval_settings { | ||
| resource_kind = "segment" | ||
| required = true | ||
| min_num_approvals = 1 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| ### Code Changes | ||
|
|
||
| 1. **New constant**: `RESOURCE_KIND` added to `keys.go` | ||
| 2. **Schema updated**: `approval_settings` block now supports `resource_kind` attribute | ||
| 3. **Validation added**: `validateUniqueResourceKinds` ensures no duplicate resource kinds | ||
| 4. **Patch generation**: `approvalPatchFromSettings` generates correct API paths based on resource kind | ||
| 5. **Data reading**: `environmentApprovalSettingsToResourceData` handles both API structures | ||
|
|
||
| ### Testing | ||
|
|
||
| Comprehensive unit tests ensure: | ||
| - Multiple resource kinds can be configured simultaneously | ||
| - Correct API paths are generated for each resource kind | ||
| - Backwards compatibility with existing configurations | ||
| - Proper handling of adding/removing resource kinds | ||
|
|
||
| Run tests with: | ||
| ```bash | ||
| go test -v ./launchdarkly -run TestApproval | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Error: "duplicate resource_kind found" | ||
|
|
||
| **Cause**: Multiple `approval_settings` blocks with the same `resource_kind` | ||
|
|
||
| **Solution**: Ensure each `approval_settings` block has a unique `resource_kind` value | ||
|
|
||
| ```hcl | ||
| # ❌ Invalid - duplicate "flag" resource_kind | ||
| approval_settings { | ||
| resource_kind = "flag" | ||
| required = true | ||
| } | ||
| approval_settings { | ||
| resource_kind = "flag" # ERROR: duplicate | ||
| required = false | ||
| } | ||
|
|
||
| # ✅ Valid - unique resource_kind values | ||
| approval_settings { | ||
| resource_kind = "flag" | ||
| required = true | ||
| } | ||
| approval_settings { | ||
| resource_kind = "segment" | ||
| required = false | ||
| } | ||
| ``` | ||
|
|
||
| ### Error: "service_kind cannot be set for resource_kind 'segment'" | ||
|
|
||
| **Cause**: Attempting to use `service_kind` with a non-default value (anything other than `"launchdarkly"`) for segment or aiconfig approval settings | ||
|
|
||
| **Solution**: Remove the `service_kind` field or set it to the default value `"launchdarkly"` (or omit it entirely) | ||
|
|
||
| ```hcl | ||
| # ❌ Invalid - service_kind not supported for segment | ||
| approval_settings { | ||
| resource_kind = "segment" | ||
| service_kind = "servicenow" # ERROR: not supported for segments | ||
| required = true | ||
| } | ||
|
|
||
| # ✅ Valid - service_kind only used with flag resource_kind | ||
| approval_settings { | ||
| resource_kind = "flag" | ||
| service_kind = "servicenow" | ||
| required = true | ||
| } | ||
|
|
||
| approval_settings { | ||
| resource_kind = "segment" | ||
| required = true | ||
| # service_kind omitted or set to default "launchdarkly" | ||
| } | ||
| ``` | ||
|
|
||
| ### Error: "service_config cannot be set for resource_kind 'segment'" | ||
|
|
||
| **Cause**: Attempting to use `service_config` for segment or aiconfig approval settings | ||
|
|
||
| **Solution**: Remove the `service_config` field from non-flag approval settings | ||
|
|
||
| ```hcl | ||
| # ❌ Invalid - service_config not supported for segment | ||
| approval_settings { | ||
| resource_kind = "segment" | ||
| service_config = { | ||
| template = "template-id" | ||
| detail_column = "justification" | ||
| } # ERROR: not supported for segments | ||
| required = true | ||
| } | ||
|
|
||
| # ✅ Valid - service_config only used with flag resource_kind | ||
| approval_settings { | ||
| resource_kind = "flag" | ||
| service_kind = "servicenow" | ||
| service_config = { | ||
| template = "template-id" | ||
| detail_column = "justification" | ||
| } | ||
| required = true | ||
| } | ||
|
|
||
| approval_settings { | ||
| resource_kind = "segment" | ||
| required = true | ||
| # service_config omitted | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| ### Import Considerations | ||
|
|
||
| When you import an existing environment (using `terraform import`), Terraform will read all configured approval settings from the API and represent them as separate `approval_settings` blocks in the state, each with the appropriate `resource_kind` value. | ||
|
|
||
| For example, if you import an environment that has both flag and segment approvals configured: | ||
|
|
||
| ```bash | ||
| terraform import launchdarkly_environment.example project-key/env-key | ||
| ``` | ||
|
|
||
| The resulting state will contain multiple `approval_settings` blocks. You'll need to add corresponding blocks to your Terraform configuration to match the imported state. | ||
|
|
||
| ## Additional Resources | ||
|
|
||
| - [LaunchDarkly Approval Settings Documentation](https://docs.launchdarkly.com/home/feature-workflows/approvals) | ||
| - [Terraform Provider Documentation](https://registry.terraform.io/providers/launchdarkly/launchdarkly/latest/docs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # Example of environment with approval settings for both flags and segments | ||
|
|
||
| resource "launchdarkly_environment" "example" { | ||
| name = "Example Environment" | ||
| key = "example-env" | ||
| color = "FFFFFF" | ||
| project_key = "example-project" | ||
|
|
||
| # Flag approval settings (resource_kind defaults to "flag") | ||
| approval_settings { | ||
| resource_kind = "flag" # Optional, defaults to "flag" | ||
| required = true | ||
| can_review_own_request = false | ||
| min_num_approvals = 2 | ||
| can_apply_declined_changes = false | ||
| service_kind = "launchdarkly" | ||
| } | ||
|
|
||
| # Segment approval settings | ||
| approval_settings { | ||
| resource_kind = "segment" | ||
| required = true | ||
| can_review_own_request = false | ||
| min_num_approvals = 1 | ||
| can_apply_declined_changes = true | ||
| service_kind = "launchdarkly" | ||
| } | ||
|
|
||
| # AI Config approval settings (if needed) | ||
| # approval_settings { | ||
| # resource_kind = "aiconfig" | ||
| # required = false | ||
| # can_review_own_request = true | ||
| # min_num_approvals = 1 | ||
| # can_apply_declined_changes = true | ||
| # service_kind = "launchdarkly" | ||
| # } | ||
| } | ||
|
|
||
| # Example maintaining backwards compatibility (without resource_kind) | ||
| # This will default to flag approval settings | ||
| resource "launchdarkly_environment" "backwards_compatible" { | ||
| name = "Backwards Compatible Environment" | ||
| key = "backwards-compat" | ||
| color = "000000" | ||
| project_key = "example-project" | ||
|
|
||
| approval_settings { | ||
| # No resource_kind specified - defaults to "flag" | ||
| required = true | ||
| can_review_own_request = false | ||
| min_num_approvals = 1 | ||
| can_apply_declined_changes = true | ||
| service_kind = "launchdarkly" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should either be moved to the docs dir or removed altogether.