-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 #2430 from terraform-providers/datasource_actiongroup
New DataSource: `azurerm_monitor_action_group`
- Loading branch information
Showing
5 changed files
with
371 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmMonitorActionGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmMonitorActionGroupRead, | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.NoZeroValues, | ||
}, | ||
|
||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"short_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"enabled": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"email_receiver": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"email_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"sms_receiver": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"country_code": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"phone_number": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"webhook_receiver": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"service_uri": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmMonitorActionGroupRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).monitorActionGroupsClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Action Group %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
return fmt.Errorf("Error making Read request on Action Group %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
d.SetId(*resp.ID) | ||
|
||
if group := resp.ActionGroup; group != nil { | ||
d.Set("short_name", group.GroupShortName) | ||
d.Set("enabled", group.Enabled) | ||
|
||
if err = d.Set("email_receiver", flattenMonitorActionGroupEmailReceiver(group.EmailReceivers)); err != nil { | ||
return fmt.Errorf("Error setting `email_receiver`: %+v", err) | ||
} | ||
|
||
if err = d.Set("sms_receiver", flattenMonitorActionGroupSmsReceiver(group.SmsReceivers)); err != nil { | ||
return fmt.Errorf("Error setting `sms_receiver`: %+v", err) | ||
} | ||
|
||
if err = d.Set("webhook_receiver", flattenMonitorActionGroupWebHookReceiver(group.WebhookReceivers)); err != nil { | ||
return fmt.Errorf("Error setting `webhook_receiver`: %+v", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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,181 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceArmMonitorActionGroup_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_monitor_action_group.test" | ||
ri := acctest.RandInt() | ||
config := testAccDataSourceArmMonitorActionGroup_basic(ri, testLocation()) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "enabled", "true"), | ||
resource.TestCheckResourceAttr(dataSourceName, "short_name", "acctestag"), | ||
resource.TestCheckResourceAttr(dataSourceName, "email_receiver.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceArmMonitorActionGroup_disabledBasic(t *testing.T) { | ||
dataSourceName := "data.azurerm_monitor_action_group.test" | ||
ri := acctest.RandInt() | ||
config := testAccDataSourceArmMonitorActionGroup_disabledBasic(ri, testLocation()) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "enabled", "false"), | ||
resource.TestCheckResourceAttr(dataSourceName, "short_name", "acctestag"), | ||
resource.TestCheckResourceAttr(dataSourceName, "email_receiver.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.#", "0"), | ||
resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.#", "0"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceArmMonitorActionGroup_complete(t *testing.T) { | ||
dataSourceName := "data.azurerm_monitor_action_group.test" | ||
ri := acctest.RandInt() | ||
config := testAccDataSourceArmMonitorActionGroup_complete(ri, testLocation()) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "enabled", "true"), | ||
resource.TestCheckResourceAttr(dataSourceName, "email_receiver.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "email_receiver.0.email_address", "[email protected]"), | ||
resource.TestCheckResourceAttr(dataSourceName, "email_receiver.1.email_address", "[email protected]"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.0.country_code", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.0.phone_number", "1231231234"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.1.country_code", "86"), | ||
resource.TestCheckResourceAttr(dataSourceName, "sms_receiver.1.phone_number", "13888888888"), | ||
resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.#", "2"), | ||
resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.0.service_uri", "http://example.com/alert"), | ||
resource.TestCheckResourceAttr(dataSourceName, "webhook_receiver.1.service_uri", "https://backup.example.com/warning"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceArmMonitorActionGroup_basic(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_monitor_action_group" "test" { | ||
name = "acctestActionGroup-%d" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
short_name = "acctestag" | ||
} | ||
data "azurerm_monitor_action_group" "test" { | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
name = "${azurerm_monitor_action_group.test.name}" | ||
} | ||
`, rInt, location, rInt) | ||
} | ||
|
||
func testAccDataSourceArmMonitorActionGroup_disabledBasic(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_monitor_action_group" "test" { | ||
name = "acctestActionGroup-%d" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
short_name = "acctestag" | ||
enabled = false | ||
} | ||
data "azurerm_monitor_action_group" "test" { | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
name = "${azurerm_monitor_action_group.test.name}" | ||
} | ||
`, rInt, location, rInt) | ||
} | ||
|
||
func testAccDataSourceArmMonitorActionGroup_complete(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%d" | ||
location = "%s" | ||
} | ||
resource "azurerm_monitor_action_group" "test" { | ||
name = "acctestActionGroup-%d" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
short_name = "acctestag" | ||
email_receiver { | ||
name = "sendtoadmin" | ||
email_address = "[email protected]" | ||
} | ||
email_receiver { | ||
name = "sendtodevops" | ||
email_address = "[email protected]" | ||
} | ||
sms_receiver { | ||
name = "oncallmsg" | ||
country_code = "1" | ||
phone_number = "1231231234" | ||
} | ||
sms_receiver { | ||
name = "remotesupport" | ||
country_code = "86" | ||
phone_number = "13888888888" | ||
} | ||
webhook_receiver { | ||
name = "callmyapiaswell" | ||
service_uri = "http://example.com/alert" | ||
} | ||
webhook_receiver { | ||
name = "callmybackupapi" | ||
service_uri = "https://backup.example.com/warning" | ||
} | ||
} | ||
data "azurerm_monitor_action_group" "test" { | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
name = "${azurerm_monitor_action_group.test.name}" | ||
} | ||
`, rInt, location, rInt) | ||
} |
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,60 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_monitor_action_group" | ||
sidebar_current: "docs-azurerm-datasource-monitor-action-group" | ||
description: |- | ||
Get information about the specified Action Group. | ||
--- | ||
|
||
# Data Source: azurerm_monitor_action_group | ||
|
||
Use this data source to access the properties of an Action Group. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_monitor_action_group" "example" { | ||
resource_group_name = "terraform-example-rg" | ||
name = "tfex-actiongroup" | ||
} | ||
output "action_group_id" { | ||
value = "${data.azurerm_monitor_action_group.example.id}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Specifies the name of the Action Group. | ||
* `resource_group_name` - (Required) Specifies the name of the resource group the Action Group is located in. | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The ID of the Action Group. | ||
* `short_name` - The short name of the action group. | ||
* `enabled` - Whether this action group is enabled. | ||
* `email_receiver` - One or more `email_receiver` blocks as defined below. | ||
* `sms_receiver` - One or more `sms_receiver ` blocks as defined below. | ||
* `webhook_receiver` - One or more `webhook_receiver ` blocks as defined below. | ||
|
||
--- | ||
|
||
`email_receiver` supports the following: | ||
|
||
* `name` - The name of the email receiver. | ||
* `email_address` - The email address of this receiver. | ||
|
||
--- | ||
|
||
`sms_receiver` supports the following: | ||
|
||
* `name` - The name of the SMS receiver. | ||
* `country_code` - The country code of the SMS receiver. | ||
* `phone_number` - The phone number of the SMS receiver. | ||
|
||
--- | ||
|
||
`webhook_receiver` supports the following: | ||
|
||
* `name` - The name of the webhook receiver. | ||
* `service_uri` - The URI where webhooks should be sent. |