-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We only use Slack and PagerDuty here, but adding support for others should be straightforward.
- Loading branch information
1 parent
b0bdeda
commit a9b3aa0
Showing
4 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Integration | ||
|
||
SignalFx supports integrations to ingest metrics from other monitoring systems, connect to Single Sign-On providers, and to report notifications for messaging and incident management. Note that your SignalForm API key must have admin permissions to use the SignalFx integration API. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "signalform_integration" "pagerduty_myteam" { | ||
provider = "signalform" | ||
name = "PD - My Team" | ||
enabled = true | ||
type = "PagerDuty" | ||
api_key = "1234567890" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Name of the integration. | ||
* `enabled` - (Required) Whether the integration is enabled. | ||
* `type` - (Required) Type of the integration. See the full list at <https://developers.signalfx.com/reference#integrations-overview>. | ||
* `api_key` - (Required for `PagerDuty`) PagerDuty API key. | ||
* `webhook_url` - (Required for `Slack`) Slack incoming webhook URL. | ||
|
||
**Notes** | ||
|
||
This resource does not support all known types of integration. Contributions are welcome to implement more types. |
116 changes: 116 additions & 0 deletions
116
src/terraform-provider-signalform/signalform/integration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package signalform | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"strings" | ||
) | ||
|
||
const ( | ||
INTEGRATION_API_URL = "https://api.signalfx.com/v2/integration" | ||
) | ||
|
||
func integrationResource() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the integration", | ||
}, | ||
"enabled": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Required: true, | ||
Description: "Whether the integration is enabled or not", | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Type of the integration", | ||
ValidateFunc: validateIntegrationType, | ||
}, | ||
"api_key": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "PagerDuty API key", | ||
Sensitive: true, | ||
}, | ||
"webhook_url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Slack Incoming Webhook URL", | ||
Sensitive: true, | ||
}, | ||
}, | ||
|
||
Create: integrationCreate, | ||
Read: integrationRead, | ||
Update: integrationUpdate, | ||
Delete: integrationDelete, | ||
} | ||
} | ||
|
||
func validateIntegrationType(v interface{}, k string) (we []string, errors []error) { | ||
value := v.(string) | ||
allowedWords := []string{"PagerDuty", "Slack"} | ||
for _, word := range allowedWords { | ||
if value == word { | ||
return | ||
} | ||
} | ||
errors = append(errors, fmt.Errorf("%s not allowed; must be one of: %s", value, strings.Join(allowedWords, ", "))) | ||
return | ||
} | ||
|
||
func getPayloadIntegration(d *schema.ResourceData) ([]byte, error) { | ||
integrationType := d.Get("type").(string) | ||
payload := map[string]interface{}{ | ||
"name": d.Get("name").(string), | ||
"enabled": d.Get("enabled").(bool), | ||
"type": integrationType, | ||
} | ||
|
||
switch integrationType { | ||
case "PagerDuty": | ||
payload["apiKey"] = d.Get("api_key").(string) | ||
case "Slack": | ||
payload["webhookUrl"] = d.Get("webhook_url").(string) | ||
} | ||
|
||
return json.Marshal(payload) | ||
} | ||
|
||
func integrationCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*signalformConfig) | ||
payload, err := getPayloadIntegration(d) | ||
if err != nil { | ||
return fmt.Errorf("Failed creating json payload: %s", err.Error()) | ||
} | ||
|
||
return resourceCreate(INTEGRATION_API_URL, config.AuthToken, payload, d) | ||
} | ||
|
||
func integrationRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*signalformConfig) | ||
url := fmt.Sprintf("%s/%s", INTEGRATION_API_URL, d.Id()) | ||
|
||
return resourceRead(url, config.AuthToken, d) | ||
} | ||
|
||
func integrationUpdate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*signalformConfig) | ||
payload, err := getPayloadIntegration(d) | ||
if err != nil { | ||
return fmt.Errorf("Failed creating json payload: %s", err.Error()) | ||
} | ||
url := fmt.Sprintf("%s/%s", INTEGRATION_API_URL, d.Id()) | ||
|
||
return resourceUpdate(url, config.AuthToken, payload, d) | ||
} | ||
|
||
func integrationDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*signalformConfig) | ||
url := fmt.Sprintf("%s/%s", INTEGRATION_API_URL, d.Id()) | ||
return resourceDelete(url, config.AuthToken, d) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters