Skip to content

Commit f8e82e9

Browse files
authored
🧹 improve the slack integration (#85)
- add markdown description - use variable for slack token - trigger scan with integration after the setup
1 parent 1b3c8ce commit f8e82e9

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

‎docs/resources/integration_slack.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
page_title: "mondoo_integration_slack Resource - terraform-provider-mondoo"
44
subcategory: ""
55
description: |-
6-
6+
Continuously scan your Slack Teams for security misconfigurations.
77
---
88

99
# mondoo_integration_slack (Resource)
1010

11-
11+
Continuously scan your Slack Teams for security misconfigurations.
1212

1313
## Example Usage
1414

@@ -18,6 +18,11 @@ variable "mondoo_org" {
1818
type = string
1919
}
2020
21+
variable "slack_token" {
22+
description = "The Slack Token"
23+
type = string
24+
}
25+
2126
provider "mondoo" {
2227
region = "us"
2328
}
@@ -33,7 +38,7 @@ resource "mondoo_integration_slack" "slack_integration" {
3338
space_id = mondoo_space.my_space.id
3439
name = "My Slack Integration"
3540
36-
slack_token = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
41+
slack_token = var.slack_token
3742
}
3843
```
3944

‎examples/resources/mondoo_integration_slack/resource.tf‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ variable "mondoo_org" {
33
type = string
44
}
55

6+
variable "slack_token" {
7+
description = "The Slack Token"
8+
type = string
9+
}
10+
611
provider "mondoo" {
712
region = "us"
813
}
@@ -18,5 +23,5 @@ resource "mondoo_integration_slack" "slack_integration" {
1823
space_id = mondoo_space.my_space.id
1924
name = "My Slack Integration"
2025

21-
slack_token = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
26+
slack_token = var.slack_token
2227
}

‎internal/provider/integration_slack_resource.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (r *integrationSlackResource) Metadata(ctx context.Context, req resource.Me
4141

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

120+
// trigger integration to gather results quickly after the first setup
121+
// NOTE: we ignore the error since the integration state does not depend on it
122+
_, err = r.client.TriggerAction(ctx, string(integration.Mrn), mondoov1.ActionTypeRunScan)
123+
if err != nil {
124+
resp.Diagnostics.AddWarning("Client Error", fmt.Sprintf("Unable to trigger integration, got error: %s", err))
125+
return
126+
}
127+
119128
// Save space mrn into the Terraform state.
120129
data.Mrn = types.StringValue(string(integration.Mrn))
121130
data.Name = types.StringValue(string(integration.Name))

0 commit comments

Comments
 (0)