From 2248d007d87178f65ec3fdc16aacfca94a74bc95 Mon Sep 17 00:00:00 2001 From: Scott McAllister Date: Mon, 9 Mar 2020 18:24:25 -0700 Subject: [PATCH] rolling back rulesets until API is ready --- pagerduty/provider.go | 2 - pagerduty/resource_pagerduty_ruleset.go | 163 ---------- pagerduty/resource_pagerduty_ruleset_rule.go | 299 ------------------ .../resource_pagerduty_ruleset_rule_test.go | 221 ------------- pagerduty/resource_pagerduty_ruleset_test.go | 161 ---------- website/docs/r/ruleset.html.markdown | 49 --- website/docs/r/ruleset_rule.html.markdown | 102 ------ 7 files changed, 997 deletions(-) delete mode 100644 pagerduty/resource_pagerduty_ruleset.go delete mode 100644 pagerduty/resource_pagerduty_ruleset_rule.go delete mode 100644 pagerduty/resource_pagerduty_ruleset_rule_test.go delete mode 100644 pagerduty/resource_pagerduty_ruleset_test.go delete mode 100644 website/docs/r/ruleset.html.markdown delete mode 100644 website/docs/r/ruleset_rule.html.markdown diff --git a/pagerduty/provider.go b/pagerduty/provider.go index 042942cb7..25f7a6ffa 100644 --- a/pagerduty/provider.go +++ b/pagerduty/provider.go @@ -50,8 +50,6 @@ func Provider() terraform.ResourceProvider { "pagerduty_user_contact_method": resourcePagerDutyUserContactMethod(), "pagerduty_extension": resourcePagerDutyExtension(), "pagerduty_event_rule": resourcePagerDutyEventRule(), - "pagerduty_ruleset": resourcePagerDutyRuleset(), - "pagerduty_ruleset_rule": resourcePagerDutyRulesetRule(), }, } diff --git a/pagerduty/resource_pagerduty_ruleset.go b/pagerduty/resource_pagerduty_ruleset.go deleted file mode 100644 index b29b4b37d..000000000 --- a/pagerduty/resource_pagerduty_ruleset.go +++ /dev/null @@ -1,163 +0,0 @@ -package pagerduty - -import ( - "fmt" - "log" - "time" - - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/heimweh/go-pagerduty/pagerduty" -) - -func resourcePagerDutyRuleset() *schema.Resource { - return &schema.Resource{ - Create: resourcePagerDutyRulesetCreate, - Read: resourcePagerDutyRulesetRead, - Update: resourcePagerDutyRulesetUpdate, - Delete: resourcePagerDutyRulesetDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "team": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - "routing_keys": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - } -} - -func buildRulesetStruct(d *schema.ResourceData) *pagerduty.Ruleset { - ruleset := &pagerduty.Ruleset{ - Name: d.Get("name").(string), - } - - if attr, ok := d.GetOk("team"); ok { - ruleset.Team = expandTeam(attr) - } - - if attr, ok := d.GetOk("routing_keys"); ok { - ruleset.RoutingKeys = expandKeys(attr.([]interface{})) - } - - return ruleset -} - -func expandKeys(v []interface{}) []string { - keys := make([]string, len(v)) - - for i, k := range v { - keys[i] = fmt.Sprintf("%v", k) - } - - return keys -} - -func expandTeam(v interface{}) *pagerduty.RulesetObject { - var team *pagerduty.RulesetObject - t := v.([]interface{})[0].(map[string]interface{}) - team = &pagerduty.RulesetObject{ - ID: t["id"].(string), - } - - return team -} - -func flattenTeam(v *pagerduty.RulesetObject) map[string]interface{} { - team := map[string]interface{}{ - "id": v.ID, - } - return team -} -func resourcePagerDutyRulesetCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - ruleset := buildRulesetStruct(d) - - log.Printf("[INFO] Creating PagerDuty ruleset: %s", ruleset.Name) - - retryErr := resource.Retry(10*time.Second, func() *resource.RetryError { - if ruleset, _, err := client.Rulesets.Create(ruleset); err != nil { - if isErrCode(err, 400) { - return resource.RetryableError(err) - } - - return resource.NonRetryableError(err) - } else if ruleset != nil { - d.SetId(ruleset.ID) - } - return nil - }) - - if retryErr != nil { - return retryErr - } - - return resourcePagerDutyRulesetRead(d, meta) -} - -func resourcePagerDutyRulesetRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - log.Printf("[INFO] Reading PagerDuty ruleset: %s", d.Id()) - - ruleset, _, err := client.Rulesets.Get(d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } - - // if ruleset is found set to ResourceData - if ruleset.Team != nil { - d.Set("team", flattenTeam(ruleset.Team)) - } - d.Set("routing_keys", ruleset.RoutingKeys) - return nil -} -func resourcePagerDutyRulesetUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - ruleset := buildRulesetStruct(d) - - log.Printf("[INFO] Updating PagerDuty ruleset: %s", d.Id()) - - if _, _, err := client.Rulesets.Update(d.Id(), ruleset); err != nil { - return err - } - - return nil -} - -func resourcePagerDutyRulesetDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - log.Printf("[INFO] Deleting PagerDuty ruleset: %s", d.Id()) - - if _, err := client.Rulesets.Delete(d.Id()); err != nil { - return err - } - - d.SetId("") - - return nil -} diff --git a/pagerduty/resource_pagerduty_ruleset_rule.go b/pagerduty/resource_pagerduty_ruleset_rule.go deleted file mode 100644 index c5e2ed18a..000000000 --- a/pagerduty/resource_pagerduty_ruleset_rule.go +++ /dev/null @@ -1,299 +0,0 @@ -package pagerduty - -import ( - "encoding/json" - "log" - - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/heimweh/go-pagerduty/pagerduty" -) - -func resourcePagerDutyRulesetRule() *schema.Resource { - return &schema.Resource{ - Create: resourcePagerDutyRulesetRuleCreate, - Read: resourcePagerDutyRulesetRuleRead, - Update: resourcePagerDutyRulesetRuleUpdate, - Delete: resourcePagerDutyRulesetRuleDelete, - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - Schema: map[string]*schema.Schema{ - "ruleset": { - Type: schema.TypeString, - Required: true, - }, - "position": { - Type: schema.TypeInt, - Optional: true, - }, - "disabled": { - Type: schema.TypeBool, - Optional: true, - }, - "conditions": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "operator": { - Type: schema.TypeString, - Optional: true, - }, - "subconditions": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "operator": { - Type: schema.TypeString, - Optional: true, - }, - "parameter": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "path": { - Type: schema.TypeString, - Optional: true, - }, - "value": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - "advanced_conditions_json": { - Type: schema.TypeString, - Optional: true, - }, - "action": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "action": { - Type: schema.TypeString, - Optional: true, - }, - "parameters": { - Type: schema.TypeList, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - Optional: true, - }, - "target": { - Type: schema.TypeString, - Optional: true, - }, - "source": { - Type: schema.TypeString, - Optional: true, - }, - "regex": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - Optional: true, - }, - }, - }, - }, - }, - } -} - -func buildRulesetRuleStruct(d *schema.ResourceData) *pagerduty.RulesetRule { - rule := &pagerduty.RulesetRule{ - Ruleset: &pagerduty.RulesetReference{ - Type: "ruleset", - ID: d.Get("ruleset").(string), - }, - Conditions: expandConditions(d.Get("conditions").([]interface{})), - } - - if attr, ok := d.GetOk("advanced_conditions_json"); ok { - rule.AdvancedConditions = expandString(attr.(string)) - } - if attr, ok := d.GetOk("action"); ok { - rule.Actions = expandActions(attr.([]interface{})) - } - if attr, ok := d.GetOk("position"); ok { - rule.Position = attr.(int) - } - if attr, ok := d.GetOk("disabled"); ok { - rule.Disabled = attr.(bool) - } - - return rule -} - -func expandConditions(v interface{}) *pagerduty.RuleConditions { - var conditions *pagerduty.RuleConditions - - for _, vi := range v.([]interface{}) { - vm := vi.(map[string]interface{}) - con := &pagerduty.RuleConditions{ - Operator: vm["operator"].(string), - RuleSubconditions: expandSubConditions(vm["subconditions"].([]interface{})), - } - conditions = con - } - - return conditions -} - -func expandActions(v interface{}) []*pagerduty.RuleAction { - var actions []*pagerduty.RuleAction - - for _, ai := range v.([]interface{}) { - am := ai.(map[string]interface{}) - act := &pagerduty.RuleAction{ - Action: am["action"].(string), - Parameters: expandActionParameters(am["parameters"].([]interface{})), - } - actions = append(actions, act) - } - return actions -} - -func expandSubConditions(v interface{}) []*pagerduty.RuleSubcondition { - var sc []*pagerduty.RuleSubcondition - - for _, sci := range v.([]interface{}) { - scm := sci.(map[string]interface{}) - scon := &pagerduty.RuleSubcondition{ - Operator: scm["operator"].(string), - Parameters: expandSubConditionParameters(scm["parameter"].([]interface{})), - } - sc = append(sc, scon) - } - return sc -} -func expandSubConditionParameters(v interface{}) *pagerduty.ConditionParameter { - var parms *pagerduty.ConditionParameter - - for _, pi := range v.([]interface{}) { - pm := pi.(map[string]interface{}) - cp := &pagerduty.ConditionParameter{ - Path: pm["path"].(string), - Value: pm["value"].(string), - } - parms = cp - } - return parms -} - -func expandActionParameters(v interface{}) map[string]string { - parms := make(map[string]string) - - for _, pi := range v.([]interface{}) { - pm := pi.(map[string]interface{}) - - for key, value := range pm { - if value != nil { - parms[key] = value.(string) - } - } - } - return parms -} - -func flattenConditions(conditions *pagerduty.RuleConditions) interface{} { - b, err := json.Marshal(conditions) - if err != nil { - log.Printf("[ERROR] Could not conditions field: %v", err) - return nil - } - return string(b) -} - -func flattenActions(actions []*pagerduty.RuleAction) interface{} { - b, err := json.Marshal(actions) - if err != nil { - log.Printf("[ERROR] Could not flatten actions field: %v", err) - return nil - } - return string(b) -} - -func resourcePagerDutyRulesetRuleCreate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - rule := buildRulesetRuleStruct(d) - - log.Printf("[INFO] Creating PagerDuty ruleset rule for ruleset: %s", rule.Ruleset.ID) - - rule, _, err := client.Rulesets.CreateRule(rule.Ruleset.ID, rule) - if err != nil { - return err - } - - d.SetId(rule.ID) - - return resourcePagerDutyRulesetRuleRead(d, meta) -} - -func resourcePagerDutyRulesetRuleRead(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - log.Printf("[INFO] Reading PagerDuty ruleset rule: %s", d.Id()) - rulesetID := d.Get("ruleset").(string) - - rule, _, err := client.Rulesets.GetRule(rulesetID, d.Id()) - if err != nil { - return handleNotFoundError(err, d) - } - - d.Set("conditions", flattenConditions(rule.Conditions)) - - if rule.Actions != nil { - d.Set("action", flattenActions(rule.Actions)) - } - d.Set("position", rule.Position) - d.Set("disabled", rule.Disabled) - - return nil -} - -func resourcePagerDutyRulesetRuleUpdate(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - rule := buildRulesetRuleStruct(d) - - log.Printf("[INFO] Updating PagerDuty ruleset rule: %s", d.Id()) - rulesetID := d.Get("ruleset").(string) - - if _, _, err := client.Rulesets.UpdateRule(rulesetID, d.Id(), rule); err != nil { - return err - } - - return nil -} - -func resourcePagerDutyRulesetRuleDelete(d *schema.ResourceData, meta interface{}) error { - client := meta.(*pagerduty.Client) - - log.Printf("[INFO] Deleting PagerDuty ruleset rule: %s", d.Id()) - rulesetID := d.Get("ruleset").(string) - - if _, err := client.Rulesets.DeleteRule(rulesetID, d.Id()); err != nil { - return err - } - - d.SetId("") - - return nil -} diff --git a/pagerduty/resource_pagerduty_ruleset_rule_test.go b/pagerduty/resource_pagerduty_ruleset_rule_test.go deleted file mode 100644 index c0ed75fce..000000000 --- a/pagerduty/resource_pagerduty_ruleset_rule_test.go +++ /dev/null @@ -1,221 +0,0 @@ -package pagerduty - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" -) - -func TestAccPagerDutyRulesetRule_Basic(t *testing.T) { - ruleset := fmt.Sprintf("tf-%s", acctest.RandString(5)) - team := fmt.Sprintf("tf-%s", acctest.RandString(5)) - rule := fmt.Sprintf("tf-%s", acctest.RandString(5)) - ruleUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckPagerDutyRulesetRuleDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckPagerDutyRulesetRuleConfig(team, ruleset, rule), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyRulesetRuleExists("pagerduty_ruleset_rule.foo"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "position", "0"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.#", "1"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.operator", "and"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.subconditions.0.operator", "contains"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.subconditions.0.parameter.#", "1"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.subconditions.0.parameter.0.value", "disk space"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "action.#", "3"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "action.1.parameters.0.value", rule), - ), - }, - { - Config: testAccCheckPagerDutyRulesetRuleConfigUpdated(team, ruleset, ruleUpdated), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyRulesetRuleExists("pagerduty_ruleset_rule.foo"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "position", "0"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.#", "1"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.operator", "and"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.subconditions.0.operator", "contains"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.subconditions.0.parameter.#", "2"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "conditions.0.subconditions.0.parameter.0.path", "payload.summary"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "action.#", "4"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset_rule.foo", "action.2.parameters.0.value", ruleUpdated), - ), - }, - }, - }) -} - -func testAccCheckPagerDutyRulesetRuleDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) - for _, r := range s.RootModule().Resources { - if r.Type != "pagerduty_ruleset_rule" { - continue - } - - ruleset, _ := s.RootModule().Resources["pagerduty_ruleset.foo"] - - if _, _, err := client.Rulesets.GetRule(ruleset.Primary.ID, r.Primary.ID); err == nil { - return fmt.Errorf("Ruleset Rule still exists") - } - } - return nil -} - -func testAccCheckPagerDutyRulesetRuleExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No Ruleset Rule ID is set") - } - - ruleset, _ := s.RootModule().Resources["pagerduty_ruleset.foo"] - - client := testAccProvider.Meta().(*pagerduty.Client) - found, _, err := client.Rulesets.GetRule(ruleset.Primary.ID, rs.Primary.ID) - if err != nil { - return fmt.Errorf("Ruleset Rule not found: %v", rs.Primary.ID) - } - if found.ID != rs.Primary.ID { - return fmt.Errorf("Ruleset Rule not found: %v - %v", rs.Primary.ID, found) - } - - return nil - } -} - -func testAccCheckPagerDutyRulesetRuleConfig(team, ruleset, rule string) string { - return fmt.Sprintf(` -resource "pagerduty_team" "foo" { - name = "%s" -} - -resource "pagerduty_ruleset" "foo" { - name = "%s" - team { - id = pagerduty_team.foo.id - } -} -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" - } - } - } - action { - action = "route" - parameters { - value = "P5DTL0K" - } - } - action { - action = "annotate" - parameters { - value = "%s" - } - } - action { - action = "extract" - parameters { - target = "dedup_key" - source = "details.host" - regex = "(.*)" - } - } -} -`, team, ruleset, rule) -} - -func testAccCheckPagerDutyRulesetRuleConfigUpdated(team, ruleset, rule string) string { - return fmt.Sprintf(` -resource "pagerduty_team" "foo" { - name = "%s" -} - -resource "pagerduty_ruleset" "foo" { - name = "%s" - team { - id = pagerduty_team.foo.id - } -} -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" - } - parameter { - value = "db" - path = "payload.source" - } - } - } - action { - action = "route" - parameters { - value = "P5DTL0K" - } - } - action { - action = "severity" - parameters { - value = "warning" - } - } - action { - action = "annotate" - parameters { - value = "%s" - } - } - action { - action = "extract" - parameters { - target = "dedup_key" - source = "details.host" - regex = "(.*)" - } - } -} -`, team, ruleset, rule) -} diff --git a/pagerduty/resource_pagerduty_ruleset_test.go b/pagerduty/resource_pagerduty_ruleset_test.go deleted file mode 100644 index eca03e267..000000000 --- a/pagerduty/resource_pagerduty_ruleset_test.go +++ /dev/null @@ -1,161 +0,0 @@ -package pagerduty - -import ( - "fmt" - "log" - "strings" - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/terraform" - "github.com/heimweh/go-pagerduty/pagerduty" -) - -func init() { - resource.AddTestSweepers("pagerduty_ruleset", &resource.Sweeper{ - Name: "pagerduty_ruleset", - F: testSweepRuleset, - }) -} - -func testSweepRuleset(region string) error { - config, err := sharedConfigForRegion(region) - if err != nil { - return err - } - - client, err := config.Client() - if err != nil { - return err - } - - resp, _, err := client.Rulesets.List() - if err != nil { - return err - } - - for _, ruleset := range resp.Rulesets { - if strings.HasPrefix(ruleset.Name, "test") || strings.HasPrefix(ruleset.Name, "tf-") { - log.Printf("Destroying ruleset %s (%s)", ruleset.Name, ruleset.ID) - if _, err := client.Rulesets.Delete(ruleset.ID); err != nil { - return err - } - } - } - - return nil -} - -func TestAccPagerDutyRuleset_Basic(t *testing.T) { - ruleset := fmt.Sprintf("tf-%s", acctest.RandString(5)) - rulesetUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) - teamName := fmt.Sprintf("tf-%s", acctest.RandString(5)) - teamNameUpdated := fmt.Sprintf("tf-%s", acctest.RandString(5)) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, - CheckDestroy: testAccCheckPagerDutyRulesetDestroy, - Steps: []resource.TestStep{ - { - Config: testAccCheckPagerDutyRulesetConfig(ruleset, teamName), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyRulesetExists("pagerduty_ruleset.foo"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset.foo", "name", ruleset), - ), - }, - { - Config: testAccCheckPagerDutyRulesetConfigUpdated(rulesetUpdated, teamNameUpdated), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyRulesetExists("pagerduty_ruleset.foo"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset.foo", "name", rulesetUpdated), - ), - }, - { - Config: testAccCheckPagerDutyRulesetConfigNoTeam(ruleset), - Check: resource.ComposeTestCheckFunc( - testAccCheckPagerDutyRulesetExists("pagerduty_ruleset.noteam"), - resource.TestCheckResourceAttr( - "pagerduty_ruleset.noteam", "name", ruleset), - ), - }, - }, - }) -} - -func testAccCheckPagerDutyRulesetDestroy(s *terraform.State) error { - client := testAccProvider.Meta().(*pagerduty.Client) - for _, r := range s.RootModule().Resources { - if r.Type != "pagerduty_ruleset" { - continue - } - if _, _, err := client.Rulesets.Get(r.Primary.ID); err == nil { - return fmt.Errorf("Ruleset still exists") - } - } - return nil -} - -func testAccCheckPagerDutyRulesetExists(n string) resource.TestCheckFunc { - return func(s *terraform.State) error { - rs, ok := s.RootModule().Resources[n] - if !ok { - return fmt.Errorf("Not found: %s", n) - } - if rs.Primary.ID == "" { - return fmt.Errorf("No Ruleset ID is set") - } - - client := testAccProvider.Meta().(*pagerduty.Client) - found, _, err := client.Rulesets.Get(rs.Primary.ID) - if err != nil { - return err - } - if found.ID != rs.Primary.ID { - return fmt.Errorf("Ruleset not found: %v - %v", rs.Primary.ID, found) - } - - return nil - } -} - -func testAccCheckPagerDutyRulesetConfig(rulesetName, team string) string { - return fmt.Sprintf(` -resource "pagerduty_team" "foo" { - name = "%s" -} - -resource "pagerduty_ruleset" "foo" { - name = "%s" - team { - id = pagerduty_team.foo.id - } -} -`, team, rulesetName) -} - -func testAccCheckPagerDutyRulesetConfigUpdated(rulesetName, team string) string { - return fmt.Sprintf(` - -resource "pagerduty_team" "foo" { - name = "%s" -} -resource "pagerduty_ruleset" "foo" { - name = "%s" - team { - id = pagerduty_team.foo.id - } -} -`, team, rulesetName) -} -func testAccCheckPagerDutyRulesetConfigNoTeam(rulesetName string) string { - return fmt.Sprintf(` - -resource "pagerduty_ruleset" "noteam" { - name = "%s" -} -`, rulesetName) -} diff --git a/website/docs/r/ruleset.html.markdown b/website/docs/r/ruleset.html.markdown deleted file mode 100644 index 9b323c38c..000000000 --- a/website/docs/r/ruleset.html.markdown +++ /dev/null @@ -1,49 +0,0 @@ ---- -layout: "pagerduty" -page_title: "PagerDuty: pagerduty_ruleset" -sidebar_current: "docs-pagerduty-resource-ruleset" -description: |- - Creates and manages an ruleset in PagerDuty. ---- - -# pagerduty\_ruleset - -[Rulesets](https://support.pagerduty.com/docs/rulesets) allow you to route events to an endpoint and create collections of event rules, which define sets of actions to take based on event content. - - -## Example Usage - -```hcl -resource "pagerduty_team" "foo" { - name = "Engineering (Seattle)" -} - -resource "pagerduty_ruleset" "foo" { - name = "Primary Ruleset" - team { - id = pagerduty_team.foo.id - } -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) Name of the ruleset. -* `team` - (Optional) Reference to the team that owns the ruleset. If none is specified, only admins have access. - -## Attributes Reference - -The following attributes are exported: -* `id` - The ID of the ruleset. -* `routing_keys` - Routing keys routed to this ruleset. - - -## Import - -Rulesets can be imported using the `id`, e.g. - -``` -$ terraform import pagerduty_ruleset.main 19acac92-027a-4ea0-b06c-bbf516519601 -``` diff --git a/website/docs/r/ruleset_rule.html.markdown b/website/docs/r/ruleset_rule.html.markdown deleted file mode 100644 index a170627ab..000000000 --- a/website/docs/r/ruleset_rule.html.markdown +++ /dev/null @@ -1,102 +0,0 @@ ---- -layout: "pagerduty" -page_title: "PagerDuty: pagerduty_ruleset_rule" -sidebar_current: "docs-pagerduty-resource-ruleset-rule" -description: |- - Creates and manages a ruleset rule in PagerDuty. ---- - -# pagerduty\_event_rule - -An [event rule](https://support.pagerduty.com/docs/rulesets#section-create-event-rules) allows you to set actions that should be taken on events that meet your designated rule criteria. - -## Example Usage - -```hcl -resource "pagerduty_team" "foo" { - name = "Engineering (Seattle)" -} - -resource "pagerduty_ruleset" "foo" { - name = "Primary Ruleset" - team { - id = pagerduty_team.foo.id - } -} -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" - } - parameter { - value = "db" - path = "payload.source" - } - } - } - action { - action = "route" - parameters { - value = "P5DTL0K" - } - } - action { - action = "severity" - parameters { - value = "warning" - } - } - action { - action = "extract" - parameters { - target = "dedup_key" - source = "details.host" - regex = "(.*)" - } - } -} -``` - -## Argument Reference - -The following arguments are supported: - -* `ruleset` - (Required) The ID of the ruleset that the rule belongs to. -* `conditions` - (Required) Conditions evaluated to check if an event matches this event rule. Is always empty for the catch all rule, though. -* `position` - (Optional) Position/index of the rule within the ruleset. -* `disabled` - (Optional) Indicates whether the rule is disabled and would therefore not be evaluated. -* `advanced_conditions` - (Optional) Advanced conditions evaluated to check if an event matches this event rule. -* `action` - (Optional) Actions to apply to an event if the conditions match. - -### Conditions (`conditions`) supports the following: -* `operator` - Operator to combine sub-conditions. Can be `and` or `or`. -* `subconditions` - List of sub-conditions that define the the condition. - -### Sub-Conditions (`subconditions`) supports the following: -* `operator` - Type of operator to apply to the sub-condition. Can be `exists`,`nexists`,`equals`,`nequals`,`contains`,`ncontains`,`matches`, or `nmatches`. -* `parameter` - Parameter for the sub-condition. It requires both a `path` and `value` to be set. -### Action (`action`) supports the following: -* `action` - Type of action to apply. Can be `route`, `suppress`, `priority`, `severity`, `annotate` or `extract`. -* `parameters` - Parameters for the given action. For actions such as `priority`,`route`,`severity`, and `annotate` only a single `value` field is needed. For the `extract` action, use `target`, `source` and `regex` parameter fields. - -## Attributes Reference - -The following attributes are exported: - - * `id` - The ID of the rule. - * `catch_all` - Indicates whether the rule is the last rule of the ruleset that serves as a catch-all. It has limited functionality compared to other rules. - -## Import - -Ruleset rules can be imported using the `id`, e.g. - -``` -$ terraform import pagerduty_ruleset_rule.main 19acac92-027a-4ea0-b06c-bbf516519601 -```