-
Notifications
You must be signed in to change notification settings - Fork 212
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
Adding pagerduty_priority data source #219
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,60 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/heimweh/go-pagerduty/pagerduty" | ||
) | ||
|
||
func dataSourcePagerDutyPriority() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourcePagerDutyPriorityRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The name of the priority to find in the PagerDuty API", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourcePagerDutyPriorityRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*pagerduty.Client) | ||
|
||
log.Printf("[INFO] Reading PagerDuty priority") | ||
|
||
searchTeam := d.Get("name").(string) | ||
|
||
resp, _, err := client.Priorities.List() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var found *pagerduty.Priority | ||
|
||
for _, priority := range resp.Priorities { | ||
if strings.EqualFold(priority.Name, searchTeam) { | ||
found = priority | ||
break | ||
} | ||
} | ||
|
||
if found == nil { | ||
return fmt.Errorf("Unable to locate any priority with name: %s", searchTeam) | ||
} | ||
|
||
d.SetId(found.ID) | ||
d.Set("name", found.Name) | ||
d.Set("description", found.Description) | ||
|
||
return nil | ||
} |
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,52 @@ | ||
package pagerduty | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourcePagerDutyPriority_Basic(t *testing.T) { | ||
dataSourceName := "data.pagerduty_priority.p1" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourcePagerDutyPriorityConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", "P1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
func TestAccDataSourcePagerDutyPriority_P2(t *testing.T) { | ||
dataSourceName := "data.pagerduty_priority.p2" | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourcePagerDutyP2Config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "name", "P2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDataSourcePagerDutyPriorityConfig = ` | ||
data "pagerduty_priority" "p1" { | ||
name = "p1" | ||
} | ||
` | ||
|
||
const testAccDataSourcePagerDutyP2Config = ` | ||
data "pagerduty_priority" "p2" { | ||
name = "p2" | ||
} | ||
` |
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
2 changes: 2 additions & 0 deletions
2
vendor/github.com/heimweh/go-pagerduty/pagerduty/pagerduty.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
vendor/github.com/heimweh/go-pagerduty/pagerduty/priority.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
--- | ||
layout: "pagerduty" | ||
page_title: "PagerDuty: pagerduty_priority" | ||
sidebar_current: "docs-pagerduty-datasource-priority" | ||
description: |- | ||
Get information about a priority that you can use with ruleset_rules, etc. | ||
--- | ||
|
||
# pagerduty\_priority | ||
|
||
Use this data source to get information about a specific [priority][1] that you can use for other PagerDuty resources. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "pagerduty_priority" "p1" { | ||
name = "P1" | ||
} | ||
resource "pagerduty_ruleset" "foo" { | ||
name = "Primary Ruleset" | ||
} | ||
resource "pagerduty_ruleset_rule" "foo" { | ||
ruleset = pagerduty_ruleset.foo.id | ||
position = 0 | ||
disabled = "false" | ||
conditions { | ||
operator = "and" | ||
subconditions { | ||
operator = "contains" | ||
parameter { | ||
value = "disk space" | ||
path = "payload.summary" | ||
} | ||
} | ||
subconditions { | ||
operator = "contains" | ||
parameter { | ||
value = "db" | ||
path = "payload.source" | ||
} | ||
} | ||
} | ||
actions { | ||
route { | ||
value = "P5DTL0K" | ||
} | ||
priority { | ||
value = pagerduty_priority.p1.id | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `name` - (Required) The name of the priority to find in the PagerDuty API. | ||
|
||
## Attributes Reference | ||
* `id` - The ID of the found priority. | ||
* `name` - The name of the found priority. | ||
* `description` - A description of the found priority. | ||
|
||
[1]: https://developer.pagerduty.com/api-reference/reference/REST/openapiv3.json/paths/~1priorities/get |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it should be
data.pagerduty_priority.p1.id
instead ofpagerduty_priority.p1.id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stmcallister Any thoughts on this?