Skip to content

Commit

Permalink
🧹 improve the slack integration (#85)
Browse files Browse the repository at this point in the history
- add markdown description
- use variable for slack token
- trigger scan with integration after the setup
  • Loading branch information
chris-rock authored Apr 29, 2024
1 parent 1b3c8ce commit f8e82e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
11 changes: 8 additions & 3 deletions docs/resources/integration_slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "mondoo_integration_slack Resource - terraform-provider-mondoo"
subcategory: ""
description: |-
Continuously scan your Slack Teams for security misconfigurations.
---

# mondoo_integration_slack (Resource)


Continuously scan your Slack Teams for security misconfigurations.

## Example Usage

Expand All @@ -18,6 +18,11 @@ variable "mondoo_org" {
type = string
}
variable "slack_token" {
description = "The Slack Token"
type = string
}
provider "mondoo" {
region = "us"
}
Expand All @@ -33,7 +38,7 @@ resource "mondoo_integration_slack" "slack_integration" {
space_id = mondoo_space.my_space.id
name = "My Slack Integration"
slack_token = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
slack_token = var.slack_token
}
```

Expand Down
7 changes: 6 additions & 1 deletion examples/resources/mondoo_integration_slack/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ variable "mondoo_org" {
type = string
}

variable "slack_token" {
description = "The Slack Token"
type = string
}

provider "mondoo" {
region = "us"
}
Expand All @@ -18,5 +23,5 @@ resource "mondoo_integration_slack" "slack_integration" {
space_id = mondoo_space.my_space.id
name = "My Slack Integration"

slack_token = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
slack_token = var.slack_token
}
9 changes: 9 additions & 0 deletions internal/provider/integration_slack_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (r *integrationSlackResource) Metadata(ctx context.Context, req resource.Me

func (r *integrationSlackResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: "Continuously scan your Slack Teams for security misconfigurations.",
Attributes: map[string]schema.Attribute{
"space_id": schema.StringAttribute{
MarkdownDescription: "Mondoo Space Identifier.",
Expand Down Expand Up @@ -116,6 +117,14 @@ func (r *integrationSlackResource) Create(ctx context.Context, req resource.Crea
return
}

// trigger integration to gather results quickly after the first setup
// NOTE: we ignore the error since the integration state does not depend on it
_, err = r.client.TriggerAction(ctx, string(integration.Mrn), mondoov1.ActionTypeRunScan)
if err != nil {
resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Unable to trigger integration, got error: %s", err))
return
}

// Save space mrn into the Terraform state.
data.Mrn = types.StringValue(string(integration.Mrn))
data.Name = types.StringValue(string(integration.Name))
Expand Down

0 comments on commit f8e82e9

Please sign in to comment.