Skip to content

Commit

Permalink
global alert policy import fixed (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fahri YARDIMCI authored Feb 11, 2021
1 parent 2bfcf02 commit c79bcb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.3 (February 11, 2021)
BUGFIX:
* **Alert Policy:** Global alert policy import fixed

## 0.6.2 (January 29, 2021)
BUGFIX:
* **User:** Timezone diff problem fixed.
Expand Down
12 changes: 8 additions & 4 deletions opsgenie/resource_opsgenie_alert_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ func resourceOpsGenieAlertPolicy() *schema.Resource {
Importer: &schema.ResourceImporter{
StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
idParts := strings.Split(d.Id(), "/")
if len(idParts) != 2 || idParts[0] == "" || idParts[1] == "" {
if len(idParts) == 1 {
//if its not team_id/policy_id it can be global policy
return []*schema.ResourceData{d}, nil
} else if len(idParts) == 2 && idParts[0] != "" && idParts[1] != "" {
d.Set("team_id", idParts[0])
d.SetId(idParts[1])
return []*schema.ResourceData{d}, nil
} else {
return nil, fmt.Errorf("Unexpected format of ID (%q), expected team_id/notification_policy_id", d.Id())
}
d.Set("team_id", idParts[0])
d.SetId(idParts[1])
return []*schema.ResourceData{d}, nil
},
},
Schema: map[string]*schema.Schema{
Expand Down
15 changes: 15 additions & 0 deletions website/docs/r/alert_policy.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,18 @@ The following attributes are exported:

* `id` - The ID of the Opsgenie Alert Policy.

## Import

Alert policies can be imported using the `team id` and `policy_id`, e.g.

`$ terraform import opsgenie_notification_policy.test teamId/Id`

For this example:
- Team Id = `c827c472-31f2-497b-9ec6-8ec855d7d94c`
- Alert Policy Id = `2d1a78d0-c13e-47d3-af0a-8b6d0cc2b7b1`

`$ terraform import opsgenie_alert_policy.test c827c472-31f2-497b-9ec6-8ec855d7d94c/2d1a78d0-c13e-47d3-af0a-8b6d0cc2b7b1`

You can import global polices using only policy identifier

`$ terraform import opsgenie_alert_policy.test c827c472-31f2-497b-9ec6-8ec855d7d94c`

0 comments on commit c79bcb2

Please sign in to comment.