-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from dheeruk12/main
Add support for TeamlevelPermissions ,OutgoingRules
- Loading branch information
Showing
7 changed files
with
456 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
page_title: "Zenduty Outgoing Rules" | ||
subcategory: "" | ||
description: |- | ||
" `zenduty_outgoing_rules` is a resource to manage outgoing rules in a integration" | ||
--- | ||
# zenduty_outgoing_rules (Resource) | ||
`zenduty_outgoing_rules` is a resource to manage outgoing rules in a integration | ||
|
||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "zenduty_teams" "exampleteam" { | ||
name = "exmaple team" | ||
} | ||
resource "zenduty_services" "exampleservice" { | ||
name = "example service" | ||
team_id = zenduty_teams.exampleteam.id | ||
escalation_policy = zenduty_esp.example_esp.id e | ||
} | ||
resource "zenduty_integrations" "exampleintegration" { | ||
team_id = zenduty_teams.exampleteam.id | ||
service_id = zenduty_services.exampleservice.id | ||
application = "" | ||
name = "exampleintegration" | ||
summary = "This is the summary for the example integration" | ||
} | ||
``` | ||
|
||
```hcl | ||
resource "zenduty_outgoing_rules" "example_outgoingrules" { | ||
team_id = zenduty_teams.exampleteam.id | ||
service_id = zenduty_services.exampleservice.id | ||
integration_id = zenduty_integrations.exampleintegration.id | ||
rule_json = "" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `team_id` (Required) - The unique_id of the team to create the alert rule in. | ||
* `service_id` (Required) - The unique_id of the service to create the alert rule in. | ||
* `integration_id` (Required) - The unique_id of the integration to create the alert rule in. | ||
* `rule_json` (Required)(string) - The rule json of the alert rule.You cannot construct the rule json in terraform as of now.One can construct the rule json in Zenduty's UI.Create an outgoing rule in Zenduty and copy the rule_json from the UI. | ||
* `enabled` (Optional) - boolean value to enable or disabled | ||
|
||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The ID of the Outgoing Rule. | ||
|
||
## Import | ||
|
||
Integrations can be imported using the `team_id`(ie. unique_id of the team), `service_id`(ie. unique_id of the service),`integration_id`(ie. unique_id of the integration) and `outgoing_rule_id`(ie. unique_id of the alert rule). | ||
|
||
```hcl | ||
resource "zenduty_outgoing_rules" "demorule" { | ||
} | ||
``` | ||
|
||
`$ terraform import zenduty_outgoing_rules.demorule team_id/service_id/integration_id/outgoing_rule_id` | ||
|
||
`$ terraform state show zenduty_outgoing_rules.demorule` | ||
|
||
`* copy the output data and paste inside zenduty_outgoing_rules.demorule resource block and remove the id attribute` | ||
|
||
`$ terraform plan` to verify the import | ||
|
||
|
||
|
||
|
||
|
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,70 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "Zenduty: TeamLevelPermissions" | ||
subcategory: "" | ||
description: |- | ||
Provides a Zenduty TeamLevelPermissions Resource. This allows TeamLeveLPermissions to be created, updated, deleted. | ||
--- | ||
|
||
# Resource : zenduty_team_permissions | ||
|
||
Provides a Zenduty TeamLeveLPermissions Resource. This allows TeamLeveLPermissions to be created, updated, deleted. | ||
|
||
|
||
## Example Usage | ||
```hcl | ||
resource "zenduty_teams" "exampleteam" { | ||
name = "exmaple team" | ||
} | ||
``` | ||
|
||
```hcl | ||
resource "zenduty_team_permissions" "restricted" { | ||
team_id = zenduty_teams.exampleteam.id | ||
permissions = [ | ||
"analytics_read", | ||
] | ||
} | ||
``` | ||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Argument Reference | ||
|
||
* `team_id` (Required) - UniqueID of the team | ||
* `permissions` (Required) - List of permissions that your team can give to non-team members within your account | ||
|
||
### Permissions | ||
|
||
Please refer to the following link for detailed documentation https://docs.zenduty.com/rbac#team-level-permissions | ||
|
||
- "analytics_read", | ||
- "escalation_policy_attach", | ||
- "escalation_policy_read", | ||
- "incident_read", | ||
- "incident_role_read", | ||
- "incident_write", | ||
- "integration_read", | ||
- "maintenance_read", | ||
- "member_read", | ||
- "post_incident_task_read", | ||
- "postmortem_read", | ||
- "priority_read", | ||
- "schedule_attach", | ||
- "schedule_read", | ||
- "service_read", | ||
- "sla_read", | ||
- "stakeholder_template_read", | ||
- "tag_read", | ||
- "task_template_read", | ||
- "team_read", | ||
|
||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `id` - The UniqueID of the Zenduty Team. | ||
|
||
|
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
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,167 @@ | ||
package zenduty | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/Zenduty/zenduty-go-sdk/client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceOutgoingRules() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceCreateOutgoingRules, | ||
UpdateContext: resourceUpdateOutgoingRules, | ||
DeleteContext: resourceDeleteOutgoingRules, | ||
ReadContext: resourceReadOutgoingRules, | ||
Importer: &schema.ResourceImporter{ | ||
State: resourceOutgoingRulesImporter, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"rule_json": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"enabled": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
}, | ||
"team_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateDiagFunc: ValidateUUID(), | ||
}, | ||
"service_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateDiagFunc: ValidateUUID(), | ||
}, | ||
"integration_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateDiagFunc: ValidateUUID(), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ValidateAncCreateOutgoingRules(Ctx context.Context, d *schema.ResourceData, m interface{}) (*client.OutgoingRule, diag.Diagnostics) { | ||
newAlertRule := &client.OutgoingRule{} | ||
|
||
if v, ok := d.GetOk("rule_json"); ok { | ||
newAlertRule.RuleJSON = v.(string) | ||
} | ||
enabled := d.Get("enabled") | ||
newAlertRule.Enabled = enabled.(bool) | ||
|
||
if newAlertRule.RuleJSON == "" { | ||
return nil, diag.FromErr(errors.New("rule_json is required")) | ||
} | ||
if !isJSONString(newAlertRule.RuleJSON) { | ||
return nil, diag.FromErr(errors.New("rule_json is not valid JSON")) | ||
} | ||
|
||
return newAlertRule, nil | ||
} | ||
|
||
func resourceCreateOutgoingRules(Ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
apiclient, _ := m.(*Config).Client() | ||
var diags diag.Diagnostics | ||
var teamID, serviceID, integrationID string | ||
|
||
teamID = d.Get("team_id").(string) | ||
serviceID = d.Get("service_id").(string) | ||
integrationID = d.Get("integration_id").(string) | ||
|
||
newRule, ruleErr := ValidateAncCreateOutgoingRules(Ctx, d, m) | ||
if ruleErr != nil { | ||
return ruleErr | ||
} | ||
|
||
alertRule, err := apiclient.OutgoingRules.CreateOutgoingRule(teamID, serviceID, integrationID, newRule) | ||
|
||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(alertRule.UniqueID) | ||
return diags | ||
} | ||
|
||
func resourceUpdateOutgoingRules(Ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
apiclient, _ := m.(*Config).Client() | ||
var diags diag.Diagnostics | ||
var teamID, serviceID, integrationID string | ||
|
||
teamID = d.Get("team_id").(string) | ||
serviceID = d.Get("service_id").(string) | ||
integrationID = d.Get("integration_id").(string) | ||
|
||
newRule, ruleErr := ValidateAncCreateOutgoingRules(Ctx, d, m) | ||
if ruleErr != nil { | ||
return ruleErr | ||
} | ||
|
||
_, err := apiclient.OutgoingRules.UpdateOutgoingRule(teamID, serviceID, integrationID, d.Id(), newRule) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return diags | ||
} | ||
|
||
func resourceReadOutgoingRules(Ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
apiclient, _ := m.(*Config).Client() | ||
var diags diag.Diagnostics | ||
var teamID, serviceID, integrationID string | ||
|
||
teamID = d.Get("team_id").(string) | ||
serviceID = d.Get("service_id").(string) | ||
integrationID = d.Get("integration_id").(string) | ||
|
||
rule, err := apiclient.OutgoingRules.GetOutgoingRule(teamID, serviceID, integrationID, d.Id()) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(rule.UniqueID) | ||
d.Set("rule_json", rule.RuleJSON) | ||
d.Set("enabled", rule.Enabled) | ||
|
||
return diags | ||
} | ||
|
||
func resourceDeleteOutgoingRules(Ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
var diags diag.Diagnostics | ||
apiclient, _ := m.(*Config).Client() | ||
teamID, serviceID, integrationID, uniqueID := d.Get("team_id").(string), d.Get("service_id").(string), d.Get("integration_id").(string), d.Id() | ||
|
||
err := apiclient.OutgoingRules.DeleteOutgoingRule(teamID, serviceID, integrationID, uniqueID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
return diags | ||
} | ||
|
||
func resourceOutgoingRulesImporter(d *schema.ResourceData, m interface{}) ([]*schema.ResourceData, error) { | ||
parts := strings.Split(d.Id(), "/") | ||
if len(parts) != 4 { | ||
return nil, fmt.Errorf("unexpected format of id (%q), expected <team_id>/<service_id>/<integration_id>/<alert_rule_id>", d.Id()) | ||
} else if !IsValidUUID(parts[0]) { | ||
return nil, fmt.Errorf("invalid team_id (%q)", parts[0]) | ||
} else if !IsValidUUID(parts[1]) { | ||
return nil, fmt.Errorf("invalid serviceid (%q)", parts[1]) | ||
} else if !IsValidUUID(parts[2]) { | ||
return nil, fmt.Errorf("invalid integration_id (%q)", parts[2]) | ||
} else if !IsValidUUID(parts[3]) { | ||
return nil, fmt.Errorf("invalid alert_rule_id (%q)", parts[3]) | ||
} | ||
d.SetId(parts[3]) | ||
d.Set("integration_id", parts[2]) | ||
d.Set("team_id", parts[0]) | ||
d.Set("service_id", parts[1]) | ||
|
||
return []*schema.ResourceData{d}, nil | ||
} |
Oops, something went wrong.