From ebc4e9ea03049081ef533abab034a4c6e2c3f49b Mon Sep 17 00:00:00 2001 From: Andrew Hill Date: Fri, 8 Dec 2023 09:01:10 -0500 Subject: [PATCH] Add service kind and config to approval settings (#191) * Support service kind and config in approval settings * Update docs * Update datasource docs --- docs/data-sources/environment.md | 2 ++ docs/resources/environment.md | 13 +++++++++++++ docs/resources/project.md | 16 ++++++++++++++++ launchdarkly/approvals_helper.go | 22 ++++++++++++++++++++++ launchdarkly/environments_helper_test.go | 4 ++++ launchdarkly/keys.go | 2 ++ 6 files changed, 59 insertions(+) diff --git a/docs/data-sources/environment.md b/docs/data-sources/environment.md index ea42b068..c37b7953 100644 --- a/docs/data-sources/environment.md +++ b/docs/data-sources/environment.md @@ -56,3 +56,5 @@ Read-Only: - `min_num_approvals` (Number) - `required` (Boolean) - `required_approval_tags` (List of String) +- `service_kind` (String) +- `service_config` (Block List) diff --git a/docs/resources/environment.md b/docs/resources/environment.md index a5b91f36..1dce053e 100644 --- a/docs/resources/environment.md +++ b/docs/resources/environment.md @@ -82,6 +82,19 @@ Optional: - `min_num_approvals` (Number) The number of approvals required before an approval request can be applied. This number must be between 1 and 5. Defaults to 1. - `required` (Boolean) Set to `true` for changes to flags in this environment to require approval. You may only set `required` to true if `required_approval_tags` is not set and vice versa. Defaults to `false`. - `required_approval_tags` (List of String) An array of tags used to specify which flags with those tags require approval. You may only set `required_approval_tags` if `required` is not set to `true` and vice versa. +- `service_kind` (String) The kind of service to use when requesting an approval. Use this to switch which system approval requests go to. Valid values are `launchdarkly` and `servicenow`. The default is `launchdarkly`. +- `service_config` (Block List) The config for the approval service. This will differ for different kinds of services. (See [below for nested schema](#nestedblock--approval_settings_service_config)) + + +### Nested Schema for `service_config` +The structure of the `service_config` object will be different for each different service kind. + +For a `service_kind` of `servicenow`: + +- `detail_column` (String) The name of the column to place the details in when creating the change request in ServiceNow. +- `template` (String) The sys_id of the Standard Change Request Template in ServiceNow to use when creating the change request. + +For a `service_kind` of `launchdarkly`: No properties are required. ## Import diff --git a/docs/resources/project.md b/docs/resources/project.md index bee28b51..d57a9f21 100644 --- a/docs/resources/project.md +++ b/docs/resources/project.md @@ -98,6 +98,22 @@ Nested environments `approval_settings` blocks have the following structure: - `required_approval_tags` - An array of tags used to specify which flags with those tags require approval. You may only set `required_approval_tags` if `required` is not set to `true` and vice versa. +- `service_kind` (String) The kind of service to use when requesting an approval. Use this to switch which system approval requests go to. Valid values are `launchdarkly` and `servicenow`. The default is `launchdarkly`. +- +- `service_config` (Block List) The config for the approval service. This will differ for different kinds of services. (See [below for nested schema](#nestedblock--approval_settings_service_config)) + + +### Nested Schema for `service_config` + +The structure of the `service_config` object will be different for each different service kind. + +For a `service_kind` of `servicenow`: + +- `detail_column` (String) The name of the column to place the details in when creating the change request in ServiceNow. +- `template` (String) The sys_id of the Standard Change Request Template in ServiceNow to use when creating the change request. + +For a `service_kind` of `launchdarkly`: No properties are required. + ### Nested Client side Availability Block The nested `default_client_side_availability` block describes which client-side SDKs can use new flags by default. To learn more about this setting, read [Making flags available to client-side and mobile SDKs](https://docs.launchdarkly.com/home/getting-started/feature-flags#making-flags-available-to-client-side-and-mobile-sdks). This block has the following structure: diff --git a/launchdarkly/approvals_helper.go b/launchdarkly/approvals_helper.go index 5b5517f4..9b7852c1 100644 --- a/launchdarkly/approvals_helper.go +++ b/launchdarkly/approvals_helper.go @@ -55,6 +55,19 @@ func approvalSchema(options approvalSchemaOptions) *schema.Schema { ValidateFunc: validateTagsNoDiag(), }, }, + SERVICE_KIND: { + Type: schema.TypeString, + Optional: !options.isDataSource, + Computed: options.isDataSource, + Description: "The kind of service that is associated with this approval. This is used to determine which platform is used for requesting approval. Valid values are `servicenow`, `launchdarkly`.", + Default: "launchdarkly", + }, + SERVICE_CONFIG: { + Type: schema.TypeMap, + Optional: !options.isDataSource, + Computed: options.isDataSource, + Description: "The configuration for the service that is associated with this approval. This will be specific to each approval service.", + }, } if options.isDataSource { @@ -81,6 +94,8 @@ func approvalSettingsFromResourceData(val interface{}) (ldapi.ApprovalSettings, CanReviewOwnRequest: approvalSettingsMap[CAN_REVIEW_OWN_REQUEST].(bool), MinNumApprovals: int32(approvalSettingsMap[MIN_NUM_APPROVALS].(int)), CanApplyDeclinedChanges: approvalSettingsMap[CAN_APPLY_DECLINED_CHANGES].(bool), + ServiceKind: approvalSettingsMap[SERVICE_KIND].(string), + ServiceConfig: approvalSettingsMap[SERVICE_CONFIG].(map[string]interface{}), } // Required and RequiredApprovalTags should never be defined simultaneously // unfortunately since they default to their null values and are nested we cannot tell if the @@ -99,6 +114,9 @@ func approvalSettingsFromResourceData(val interface{}) (ldapi.ApprovalSettings, } else { settings.Required = required } + + settings.ServiceKind = approvalSettingsMap[SERVICE_KIND].(string) + settings.ServiceConfig = approvalSettingsMap[SERVICE_CONFIG].(map[string]interface{}) return settings, nil } @@ -109,6 +127,8 @@ func approvalSettingsToResourceData(settings ldapi.ApprovalSettings) interface{} CAN_APPLY_DECLINED_CHANGES: settings.CanApplyDeclinedChanges, REQUIRED_APPROVAL_TAGS: settings.RequiredApprovalTags, REQUIRED: settings.Required, + SERVICE_KIND: settings.ServiceKind, + SERVICE_CONFIG: settings.ServiceConfig, } return []map[string]interface{}{transformed} } @@ -135,6 +155,8 @@ func approvalPatchFromSettings(oldApprovalSettings, newApprovalSettings interfac patchReplace("/approvalSettings/minNumApprovals", settings.MinNumApprovals), patchReplace("/approvalSettings/canApplyDeclinedChanges", settings.CanApplyDeclinedChanges), patchReplace("/approvalSettings/requiredApprovalTags", settings.RequiredApprovalTags), + patchReplace("/approvalSettings/serviceKind", settings.ServiceKind), + patchReplace("/approvalSettings/serviceConfig", settings.ServiceConfig), } return patch, nil } diff --git a/launchdarkly/environments_helper_test.go b/launchdarkly/environments_helper_test.go index 82432c8f..da786fca 100644 --- a/launchdarkly/environments_helper_test.go +++ b/launchdarkly/environments_helper_test.go @@ -79,6 +79,8 @@ func TestEnvironmentToResourceData(t *testing.T) { CanApplyDeclinedChanges: true, RequiredApprovalTags: []string{"approval"}, CanReviewOwnRequest: true, + ServiceKind: "launchdarkly", + ServiceConfig: map[string]interface{}(nil), }, }, expected: envResourceData{ @@ -101,6 +103,8 @@ func TestEnvironmentToResourceData(t *testing.T) { CAN_APPLY_DECLINED_CHANGES: true, REQUIRED_APPROVAL_TAGS: []string{"approval"}, REQUIRED: true, + SERVICE_KIND: "launchdarkly", + SERVICE_CONFIG: map[string]interface{}(nil), }, }, }, diff --git a/launchdarkly/keys.go b/launchdarkly/keys.go index 3c23b29e..a91efd3c 100644 --- a/launchdarkly/keys.go +++ b/launchdarkly/keys.go @@ -95,6 +95,8 @@ const ( SECRET = "secret" SECURE_MODE = "secure_mode" SELECTOR = "selector" + SERVICE_CONFIG = "service_config" + SERVICE_KIND = "service_kind" SERVICE_TOKEN = "service_token" STATEMENTS = "statements" SUBSTRING = "substring"