Skip to content
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

prepare 2.5.0 release #87

Merged
merged 6 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [2.5.0] (February 7, 2022)

FEATURES:

- Added Slack webhooks to the `launchdarkly_audit_log_subscription` resource and data source. [#16](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/16)
- Added more Datadog host URLs to the Datadog `launchdarkly_audit_log_subscription` resource.

BUG FIXES:

- Fixed an issue where the `config` was not being set on the `launchdarkly_audit_log_subscription` data source.

## [2.4.1] (January 21, 2022)

BUG FIXES:
Expand Down
28 changes: 28 additions & 0 deletions launchdarkly/audit_log_subscription_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ var SUBSCRIPTION_CONFIGURATION_FIELDS = map[string]interface{}{
"allowedValues": []interface{}{
"https://api.datadoghq.com",
"https://api.datadoghq.eu",
"https://us3.datadoghq.com",
"https://us5.datadoghq.com",
"https://app.ddog-gov.com",
},
"defaultValue": "https://api.datadoghq.com",
"isSecret": false,
Expand Down Expand Up @@ -296,3 +299,28 @@ var SUBSCRIPTION_CONFIGURATION_FIELDS = map[string]interface{}{
},
},
}

// There is not currently a manifest for slack webhooks so we have to use this for now.
var EXTRA_SUBSCRIPTION_CONFIGURATION_FIELDS = map[string]interface{}{
"slack": map[string]interface{}{
"url": map[string]interface{}{
"type": "uri",
"isOptional": false,
"allowedValues": nil,
"defaultValue": nil,
"isSecret": false,
},
},
}

func getSubscriptionConfigurationFields() map[string]interface{} {
fields := make(map[string]interface{}, len(SUBSCRIPTION_CONFIGURATION_FIELDS)+len(EXTRA_SUBSCRIPTION_CONFIGURATION_FIELDS))

for k, v := range SUBSCRIPTION_CONFIGURATION_FIELDS {
fields[k] = v
}
for k, v := range EXTRA_SUBSCRIPTION_CONFIGURATION_FIELDS {
fields[k] = v
}
return fields
}
15 changes: 7 additions & 8 deletions launchdarkly/audit_log_subscription_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func auditLogSubscriptionSchema(isDataSource bool) map[string]*schema.Schema {
}

func parseAuditLogSubscriptionConfigs() map[string]IntegrationConfig {
// SUBSCRIPTION_CONFIGURATION_FIELDS can be found in audit_log_subscription_configs.go
configs := make(map[string]IntegrationConfig, len(SUBSCRIPTION_CONFIGURATION_FIELDS))
for integrationKey, rawVariables := range SUBSCRIPTION_CONFIGURATION_FIELDS {
rawConfigFields := getSubscriptionConfigurationFields()
configs := make(map[string]IntegrationConfig, len(rawConfigFields))
for integrationKey, rawVariables := range rawConfigFields {
cfg := IntegrationConfig{}
variables := rawVariables.(map[string]interface{})
for k, v := range variables {
Expand Down Expand Up @@ -162,7 +162,7 @@ func configFromResourceData(d *schema.ResourceData) (map[string]interface{}, err
return convertedConfig, nil
}

func configToResourceData(d *schema.ResourceData, config map[string]interface{}) (map[string]interface{}, error) {
func configToResourceData(d *schema.ResourceData, config map[string]interface{}, isDataSource bool) (map[string]interface{}, error) {
integrationKey := d.Get(INTEGRATION_KEY).(string)
configMap := parseAuditLogSubscriptionConfigs()
configFormat, ok := configMap[integrationKey]
Expand All @@ -174,9 +174,9 @@ func configToResourceData(d *schema.ResourceData, config map[string]interface{})
for k, v := range config {
key := strcase.SnakeCase(k)
// some attributes have defaults that the API will return and terraform will complain since config
// is not a computed attribute (cannot be both required & computed)
// is not a computed attribute (cannot be both required & computed). This does not apply for data sources.
// TODO: handle this in a SuppressDiff function
if _, setByUser := originalConfig[key]; !setByUser {
if _, setByUser := originalConfig[key]; !setByUser && !isDataSource {
continue
}
convertedConfig[key] = v
Expand Down Expand Up @@ -221,10 +221,9 @@ func auditLogSubscriptionRead(ctx context.Context, d *schema.ResourceData, metaR
d.SetId(*sub.Id)
}

_ = d.Set(INTEGRATION_KEY, sub.Kind)
_ = d.Set(NAME, sub.Name)
_ = d.Set(ON, sub.On)
cfg, err := configToResourceData(d, *sub.Config)
cfg, err := configToResourceData(d, *sub.Config, isDataSource)
if err != nil {
return diag.Errorf("failed to set config on integration with id %q: %v", *sub.Id, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,46 @@ func TestAccDataSourceAuditLogSubscription_exists(t *testing.T) {
},
})
}

func TestAccDataSourceAuditLogSubscription_Slack(t *testing.T) {
accTest := os.Getenv("TF_ACC")
if accTest == "" {
t.SkipNow()
}

integrationKey := "slack"
client, err := newClient(os.Getenv(LAUNCHDARKLY_ACCESS_TOKEN), os.Getenv(LAUNCHDARKLY_API_HOST), false)
require.NoError(t, err)

subscriptionBody := ldapi.SubscriptionPost{
Name: "test subscription",
Config: map[string]interface{}{
"url": "https://hooks.slack.com/services/SOME-RANDOM-HOOK",
},
}
sub, err := testAccDataSourceAuditLogSubscriptionCreate(client, integrationKey, subscriptionBody)
require.NoError(t, err)

defer func() {
err := testAccDataSourceAuditLogSubscriptionDelete(client, integrationKey, *sub.Id)
require.NoError(t, err)
}()

resourceName := "data.launchdarkly_audit_log_subscription.test"
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccDataSourceAuditLogSubscriptionExists, *sub.Id, integrationKey),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(resourceName, "id"),
resource.TestCheckResourceAttr(resourceName, "id", *sub.Id),
resource.TestCheckResourceAttr(resourceName, "config.url", "https://hooks.slack.com/services/SOME-RANDOM-HOOK"),
),
},
},
})
}
37 changes: 37 additions & 0 deletions launchdarkly/resource_launchdarkly_audit_log_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,43 @@ func TestAccAuditLogSubscription_CreateMSTeams(t *testing.T) {
})
}

func TestAccAuditLogSubscription_CreateSlack(t *testing.T) {
// splunk specifically needs to be converted to kebab case, so we need to handle it specially
integrationKey := "slack"
config := `{
url = "https://hooks.slack.com/services/SOME-RANDOM-HOOK"
}
`

resourceName := fmt.Sprintf("launchdarkly_audit_log_subscription.%s_tf_test", integrationKey)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(testAccAuditLogSubscriptionCreate, integrationKey, integrationKey, config),
Check: resource.ComposeTestCheckFunc(
testAccCheckIntegrationExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, ID),
resource.TestCheckResourceAttr(resourceName, INTEGRATION_KEY, integrationKey),
resource.TestCheckResourceAttr(resourceName, NAME, "terraform test"),
resource.TestCheckResourceAttr(resourceName, ON, "true"),
resource.TestCheckResourceAttr(resourceName, "config.url", "https://hooks.slack.com/services/SOME-RANDOM-HOOK"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "integrations"),
resource.TestCheckResourceAttr(resourceName, "tags.1", "terraform"),
resource.TestCheckResourceAttr(resourceName, "statements.#", "1"),
resource.TestCheckResourceAttr(resourceName, "statements.0.actions.0", "*"),
resource.TestCheckResourceAttr(resourceName, "statements.0.resources.0", "proj/*:env/*:flag/*"),
resource.TestCheckResourceAttr(resourceName, "statements.0.effect", "deny"),
),
},
},
})
}

func TestAccAuditLogSubscription_CreateSplunk(t *testing.T) {
// splunk specifically needs to be converted to kebab case, so we need to handle it specially
integrationKey := "splunk"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/audit_log_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data "launchdarkly_audit_log_subscription" "test" {

- `id` (Required) - The unique subscription ID. This can be found in the URL of the pull-out configuration sidebar for the given subscription on your [LaunchDarkly Integrations page](https://app.launchdarkly.com/default/integrations).

- `integration_key` (Required) - The integration key. As of January 2022, supported integrations are `"datadog"`, `"dynatrace"`, `"elastic"`, `"honeycomb"`, `"logdna"`, `"msteams"`, `"new-relic-apm"`, `"signalfx"`, and `"splunk"`.
- `integration_key` (Required) - The integration key. As of February 2022, supported integrations are `"datadog"`, `"dynatrace"`, `"elastic"`, `"honeycomb"`, `"logdna"`, `"msteams"`, `"new-relic-apm"`, `"signalfx"`, `"slack"`, and `"splunk"`.

## Attributes Reference

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/audit_log_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ resource "launchdarkly_audit_log_subscription" "example" {

## Argument Reference

- `integration_key` (Required) The integration key. As of January 2022, supported integrations are `"datadog"`, `"dynatrace"`, `"elastic"`, `"honeycomb"`, `"logdna"`, `"msteams"`, `"new-relic-apm"`, `"signalfx"`, and `"splunk"`. A change in this field will force the destruction of the existing resource and the creation of a new one.
- `integration_key` (Required) The integration key. As of January 2022, supported integrations are `"datadog"`, `"dynatrace"`, `"elastic"`, `"honeycomb"`, `"logdna"`, `"msteams"`, `"new-relic-apm"`, `"signalfx"`, `"slack"`, and `"splunk"`. A change in this field will force the destruction of the existing resource and the creation of a new one.

- `name` (Required) - A human-friendly name for your audit log subscription viewable from within the LaunchDarkly Integrations page.

Expand Down