Skip to content

Commit

Permalink
Add service kind and config to approval settings (#191)
Browse files Browse the repository at this point in the history
* Support service kind and config in approval settings

* Update docs

* Update datasource docs
  • Loading branch information
arhill05 authored Dec 8, 2023
1 parent 477afb0 commit ebc4e9e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/data-sources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 13 additions & 0 deletions docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

<a id="nestedblock--approval_settings_service_config"></a>
### 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

Expand Down
16 changes: 16 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

<a id="nestedblock--approval_settings_service_config"></a>
### 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:
Expand Down
22 changes: 22 additions & 0 deletions launchdarkly/approvals_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
}

Expand All @@ -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}
}
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions launchdarkly/environments_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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),
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions launchdarkly/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ebc4e9e

Please sign in to comment.