Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Refactoring and new resources (#36)
Browse files Browse the repository at this point in the history
Adds the following resources:
* pingdom_team
* pingdom_user
* pingdom_contact

Adds parameters to existing resource:
* pingdom_check: adds responsetime_threshold
  • Loading branch information
nlamirault authored and russellcardullo committed Oct 30, 2019
1 parent ad4bbfd commit 82b3c75
Show file tree
Hide file tree
Showing 17 changed files with 780 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/terraform-provider-pingdom
/.terraform

examples/*.tfstate*
examples/*.tfstate.backup
examples/*.tfvars
84 changes: 83 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,20 @@ resource "pingdom_check" "example_with_alert" {
12345678,
23456789
]
userids = [
24680,
13579
]
}
resource "pingdom_check" "ping_example" {
type = "ping"
name = "my ping check"
host = "example.com"
resolution = 1
userids = [
24680
]
}
```

Expand Down Expand Up @@ -114,6 +121,56 @@ resource "pingdom_check" "example" {
resolution = 5
}
```

**Teams**

```
resource "pingdom_team" "test" {
name = "The Test team"
}
```

**Users**

```
resource "pingdom_user" "first_user" {
username = "johndoe"
}
resource "pingdom_user" "second_user" {
username = "janedoe"
}
```

**Contacts**

```
resource "pingdom_contact" "first_user_contact_email_2" {
user_id = "${pingdom_user.first_user.id}"
email = "john.doe@doe.com"
severity_level = "LOW"
}
resource "pingdom_contact" "first_user_contact_sms_1" {
user_id = "${pingdom_user.first_user.id}"
number = "700000000"
country_code = "33"
phone_provider = "nexmo"
severity_level = "HIGH"
}
resource "pingdom_user" "second_user" {
username = "janedoe"
}
resource "pingdom_contact" "second_user_contact_email_1" {
user_id = "${pingdom_user.second_user.id}"
email = "jane@doe.com"
severity_level = "high"
}
```

## Resources ##

### Pingdom Check ###
Expand Down Expand Up @@ -176,10 +233,35 @@ For the TCP checks, you can set these attributes:

**port** - Target port for TCP checks.

**stringtosend** - (optional) This string will be sent to the port
**stringtosend** - (optional) This string will be sent to the port

**stringtoexpect** - (optional) This string must be returned by the remote host for the check to pass

The following attributes are exported:

**id** The ID of the Pingdom check


### Pingdom Team ###

**name** - (Required) The name of the team


### Pingdom User ###

**username** - (Required) The name of the user


### Pingdom Contact ###

**user_id**: (Required) ID of the user linked to this contact

**severity_level**: (Required) Severity level for target

**email**: Email

**number**: Cellphone number, without the country code part. (Requires countrycode)

**country_code**: Cellphone country code (Requires number)

**phone_provider**: SMS provider (Requires number and countrycode)
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Pingdom Example
65 changes: 65 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright (C) 2018-2019 Nicolas Lamirault <nicolas.lamirault@gmail.com>

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

terraform {
required_version = ">= 0.11.0"
}

resource "pingdom_team" "test_one" {
name = "Team 1 (updated by Terraform)"
}

provider "pingdom" {
user = "${var.pingdom_user}"
password = "${var.pingdom_password}"
api_key = "${var.pingdom_api_key}"
}

resource "pingdom_team" "test" {
name = "Team for testing"
}

resource "pingdom_user" "first_user" {
username = "johndoe"
}

resource "pingdom_contact" "first_user_contact_email_1" {
user_id = "${pingdom_user.first_user.id}"
email = "john@doe.com"
severity_level = "HIGH"
}

resource "pingdom_contact" "first_user_contact_email_2" {
user_id = "${pingdom_user.first_user.id}"
email = "john.doe@doe.com"
severity_level = "LOW"
}

resource "pingdom_contact" "first_user_contact_sms_1" {
user_id = "${pingdom_user.first_user.id}"
number = "700000000"
country_code = "33"
phone_provider = "nexmo"
severity_level = "HIGH"
}

resource "pingdom_user" "second_user" {
username = "janedoe"
}

resource "pingdom_contact" "second_user_contact_email_1" {
user_id = "${pingdom_user.second_user.id}"
email = "jane@doe.com"
severity_level = "high"
}
7 changes: 7 additions & 0 deletions examples/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
variable "pingdom_user" {}

variable "pingdom_password" {}

variable "pingdom_api_key" {
description = "The API key to used"
}
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -483,4 +483,4 @@ honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
sourcegraph.com/sourcegraph/go-diff v0.5.0/go.mod h1:kuch7UrkMzY0X+p9CRK03kfuPQ2zzQcaEFbx8wA8rck=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3QxT9HOBeFhu6RdvsftgpsbFHBF5Cas6cDKZ0=
42 changes: 42 additions & 0 deletions pingdom/data_source_pingdom_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package pingdom

import (
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"
"github.com/russellcardullo/go-pingdom/pingdom"
)

func dataSourcePingdomUser() *schema.Resource {
return &schema.Resource{
Read: dataSourcePingdomUserRead,

Schema: map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourcePingdomUserRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*pingdom.Client)
username := d.Get("username").(string)
users, err := client.Users.List()
log.Printf("==== users : %v", users)
if err != nil {
return fmt.Errorf("Error retrieving user: %s", err)
}
var found pingdom.UsersResponse
for _, user := range users {
if user.Username == username {
log.Printf("User: %v", user)
found = user
}
}
d.Set("username", found.Username)
d.SetId(fmt.Sprintf("%d", found.Id))
return nil
}
9 changes: 7 additions & 2 deletions pingdom/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ func Provider() terraform.ResourceProvider {
},
},
ResourcesMap: map[string]*schema.Resource{
"pingdom_check": resourcePingdomCheck(),
"pingdom_check": resourcePingdomCheck(),
"pingdom_team": resourcePingdomTeam(),
"pingdom_user": resourcePingdomUser(),
"pingdom_contact": resourcePingdomContact(),
},
DataSourcesMap: map[string]*schema.Resource{
"pingdom_user": dataSourcePingdomUser(),
},

ConfigureFunc: providerConfigure,
}
}
Expand Down
42 changes: 29 additions & 13 deletions pingdom/resource_pingdom_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func resourcePingdomCheck() *schema.Resource {
ForceNew: false,
},

"responsetime_threshold": {
Type: schema.TypeInt,
Optional: true,
ForceNew: false,
Computed: true,
},

"publicreport": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -185,6 +192,7 @@ type commonCheckParams struct {
Hostname string
Resolution int
Paused bool
ResponseTimeThreshold int
SendNotificationWhenDown int
NotifyAgainEvery int
NotifyWhenBackup bool
Expand Down Expand Up @@ -225,6 +233,10 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
checkParams.Resolution = v.(int)
}

if v, ok := d.GetOk("responsetime_threshold"); ok {
checkParams.ResponseTimeThreshold = v.(int)
}

if v, ok := d.GetOk("sendnotificationwhendown"); ok {
checkParams.SendNotificationWhenDown = v.(int)
}
Expand Down Expand Up @@ -322,10 +334,11 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
switch checkType {
case "http":
return &pingdom.HttpCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Resolution: checkParams.Resolution,
Paused: checkParams.Paused,
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Resolution: checkParams.Resolution,
Paused: checkParams.Paused,
ResponseTimeThreshold: checkParams.ResponseTimeThreshold,
SendNotificationWhenDown: checkParams.SendNotificationWhenDown,
NotifyAgainEvery: checkParams.NotifyAgainEvery,
NotifyWhenBackup: checkParams.NotifyWhenBackup,
Expand All @@ -346,10 +359,11 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
}, nil
case "ping":
return &pingdom.PingCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Resolution: checkParams.Resolution,
Paused: checkParams.Paused,
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Resolution: checkParams.Resolution,
Paused: checkParams.Paused,
ResponseTimeThreshold: checkParams.ResponseTimeThreshold,
SendNotificationWhenDown: checkParams.SendNotificationWhenDown,
NotifyAgainEvery: checkParams.NotifyAgainEvery,
NotifyWhenBackup: checkParams.NotifyWhenBackup,
Expand All @@ -361,10 +375,10 @@ func checkForResource(d *schema.ResourceData) (pingdom.Check, error) {
}, nil
case "tcp":
return &pingdom.TCPCheck{
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Resolution: checkParams.Resolution,
Paused: checkParams.Paused,
Name: checkParams.Name,
Hostname: checkParams.Hostname,
Resolution: checkParams.Resolution,
Paused: checkParams.Paused,
SendNotificationWhenDown: checkParams.SendNotificationWhenDown,
NotifyAgainEvery: checkParams.NotifyAgainEvery,
NotifyWhenBackup: checkParams.NotifyWhenBackup,
Expand Down Expand Up @@ -447,6 +461,7 @@ func resourcePingdomCheckRead(d *schema.ResourceData, meta interface{}) error {
d.Set("host", ck.Hostname)
d.Set("name", ck.Name)
d.Set("resolution", ck.Resolution)
d.Set("responsetime_threshold", ck.ResponseTimeThreshold)
d.Set("sendnotificationwhendown", ck.SendNotificationWhenDown)
d.Set("notifyagainevery", ck.NotifyAgainEvery)
d.Set("notifywhenbackup", ck.NotifyWhenBackup)
Expand All @@ -458,7 +473,7 @@ func resourcePingdomCheckRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("tags", strings.Join(tags, ","))

if ck.Status == "paused" {
if ck.Status == "paused" {
d.Set("paused", true)
}

Expand Down Expand Up @@ -491,6 +506,7 @@ func resourcePingdomCheckRead(d *schema.ResourceData, meta interface{}) error {

if ck.Type.HTTP != nil {
d.Set("type", "http")
d.Set("responsetime_threshold", ck.ResponseTimeThreshold)
d.Set("url", ck.Type.HTTP.Url)
d.Set("encryption", ck.Type.HTTP.Encryption)
d.Set("port", ck.Type.HTTP.Port)
Expand Down
Loading

0 comments on commit 82b3c75

Please sign in to comment.