Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new resource
azurerm_alerts_management_action_rule
- Loading branch information
Showing
25 changed files
with
6,293 additions
and
0 deletions.
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
182 changes: 182 additions & 0 deletions
182
azurerm/internal/services/alertsmanagement/action_rule.go
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,182 @@ | ||
package alertsmanagement | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement" | ||
) | ||
|
||
var weekDays = []string{ | ||
"Sunday", | ||
"Monday", | ||
"Tuesday", | ||
"Wednesday", | ||
"Thursday", | ||
"Friday", | ||
"Saturday", | ||
} | ||
|
||
var weekDayMap = map[string]int{ | ||
"Sunday": 0, | ||
"Monday": 1, | ||
"Tuesday": 2, | ||
"Wednesday": 3, | ||
"Thursday": 4, | ||
"Friday": 5, | ||
"Saturday": 6, | ||
} | ||
|
||
func schemaActionRuleAlertContextCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
string(alertsmanagement.Contains), | ||
string(alertsmanagement.DoesNotContain), | ||
}, false), | ||
validation.StringIsNotEmpty, | ||
) | ||
} | ||
|
||
func schemaActionRuleAlertRuleIDCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
string(alertsmanagement.Contains), | ||
string(alertsmanagement.DoesNotContain), | ||
}, false), | ||
validation.StringIsNotEmpty, | ||
) | ||
} | ||
|
||
func schemaActionRuleDescriptionCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
string(alertsmanagement.Contains), | ||
string(alertsmanagement.DoesNotContain), | ||
}, false), | ||
validation.StringIsNotEmpty, | ||
) | ||
} | ||
|
||
func schemaActionRuleMonitorCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
}, false), | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Fired), | ||
string(alertsmanagement.Resolved), | ||
}, false), | ||
) | ||
} | ||
func schemaActionRuleMonitorServiceCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
}, false), | ||
validation.StringInSlice([]string{ | ||
"ActivityLog Administrative", | ||
"ActivityLog Autoscale", | ||
"ActivityLog Policy", | ||
"ActivityLog Recommendation", | ||
"ActivityLog Security", | ||
"Application Insights", | ||
"Azure Backup", | ||
"Data Box Edge", | ||
"Data Box Gateway", | ||
"Health Platform", | ||
"Log Analytics", | ||
"Platform", | ||
"Resource Health", | ||
}, false), | ||
) | ||
} | ||
|
||
func schemaActionRuleSeverityCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
}, false), | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Sev0), | ||
string(alertsmanagement.Sev1), | ||
string(alertsmanagement.Sev2), | ||
string(alertsmanagement.Sev3), | ||
string(alertsmanagement.Sev4), | ||
}, false), | ||
) | ||
} | ||
|
||
func schemaActionRuleTargetResourceTypeCondtion() *schema.Schema { | ||
return schemaActionRuleCondtion( | ||
validation.StringInSlice([]string{ | ||
string(alertsmanagement.Equals), | ||
string(alertsmanagement.NotEquals), | ||
}, false), | ||
validation.StringIsNotEmpty, | ||
) | ||
} | ||
|
||
func schemaActionRuleCondtion(operatorValidateFunc, valuesValidateFunc schema.SchemaValidateFunc) *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"operator": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: operatorValidateFunc, | ||
}, | ||
|
||
"values": { | ||
Type: schema.TypeSet, | ||
Required: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: valuesValidateFunc, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func expandArmActionRuleCondition(input []interface{}) *alertsmanagement.Condition { | ||
if len(input) == 0 { | ||
return nil | ||
} | ||
|
||
v := input[0].(map[string]interface{}) | ||
return &alertsmanagement.Condition{ | ||
Operator: alertsmanagement.Operator(v["operator"].(string)), | ||
Values: utils.ExpandStringSlice(v["values"].(*schema.Set).List()), | ||
} | ||
} | ||
|
||
func flattenArmActionRuleCondition(input *alertsmanagement.Condition) []interface{} { | ||
if input == nil { | ||
return make([]interface{}, 0) | ||
} | ||
|
||
var operator string | ||
if input.Operator != "" { | ||
operator = string(input.Operator) | ||
} | ||
return []interface{}{ | ||
map[string]interface{}{ | ||
"operator": operator, | ||
"values": utils.FlattenStringSlice(input.Values), | ||
}, | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
azurerm/internal/services/alertsmanagement/client/client.go
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,19 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/preview/alertsmanagement/mgmt/2019-05-05/alertsmanagement" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
ActionRulesClient *alertsmanagement.ActionRulesClient | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) *Client { | ||
actionRulesClient := alertsmanagement.NewActionRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&actionRulesClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
ActionRulesClient: &actionRulesClient, | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
azurerm/internal/services/alertsmanagement/parse/alerts_management_action_rule.go
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,31 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type AlertsManagementActionRuleId struct { | ||
ResourceGroup string | ||
Name string | ||
} | ||
|
||
func AlertsManagementActionRuleID(input string) (*AlertsManagementActionRuleId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing AlertsManagementActionRule ID %q: %+v", input, err) | ||
} | ||
|
||
alertsManagementActionRule := AlertsManagementActionRuleId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
if alertsManagementActionRule.Name, err = id.PopSegment("actionRules"); err != nil { | ||
return nil, fmt.Errorf("parsing AlertsManagementActionRule ID %q: %+v", input, err) | ||
} | ||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, fmt.Errorf("parsing AlertsManagementActionRule ID %q: %+v", input, err) | ||
} | ||
|
||
return &alertsManagementActionRule, nil | ||
} |
72 changes: 72 additions & 0 deletions
72
azurerm/internal/services/alertsmanagement/parse/alerts_management_action_rule_test.go
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,72 @@ | ||
package parse | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAlertsManagementActionRuleID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *AlertsManagementActionRuleId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Stores Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AlertsManagement/actionRules/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "App Configuration ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AlertsManagement/actionRules/actionRule1", | ||
Expected: &AlertsManagementActionRuleId{ | ||
Name: "actionRule1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.AlertsManagement/ActionRules/actionRule1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q..", v.Name) | ||
|
||
actual, err := AlertsManagementActionRuleID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
azurerm/internal/services/alertsmanagement/registration.go
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,29 @@ | ||
package alertsmanagement | ||
|
||
import "github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
|
||
type Registration struct{} | ||
|
||
// Name is the name of this Service | ||
func (r Registration) Name() string { | ||
return "Alerts Management" | ||
} | ||
|
||
// WebsiteCategories returns a list of categories which can be used for the sidebar | ||
func (r Registration) WebsiteCategories() []string { | ||
return []string{ | ||
"Alerts Management", | ||
} | ||
} | ||
|
||
// SupportedDataSources returns the supported Data Sources supported by this Service | ||
func (r Registration) SupportedDataSources() map[string]*schema.Resource { | ||
return map[string]*schema.Resource{} | ||
} | ||
|
||
// SupportedResources returns the supported Resources supported by this Service | ||
func (r Registration) SupportedResources() map[string]*schema.Resource { | ||
return map[string]*schema.Resource{ | ||
"azurerm_alerts_management_action_rule": resourceArmAlertsManagementActionRule(), | ||
} | ||
} |
Oops, something went wrong.