diff --git a/CHANGELOG.md b/CHANGELOG.md index 70beabc1..ab9d1f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/opsgenie/resource_opsgenie_alert_policy.go b/opsgenie/resource_opsgenie_alert_policy.go index cd6ceed6..64e5477a 100644 --- a/opsgenie/resource_opsgenie_alert_policy.go +++ b/opsgenie/resource_opsgenie_alert_policy.go @@ -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{ diff --git a/website/docs/r/alert_policy.html.markdown b/website/docs/r/alert_policy.html.markdown index e3771e36..7f1b124a 100644 --- a/website/docs/r/alert_policy.html.markdown +++ b/website/docs/r/alert_policy.html.markdown @@ -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`