Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_monitor_action_group - Add optional location parameter and default to Global #20151 #20603

Merged
merged 13 commits into from
Mar 9, 2023
Merged
20 changes: 19 additions & 1 deletion internal/services/monitor/monitor_action_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -58,6 +59,21 @@ func resourceMonitorActionGroup() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupName(),

"location": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "global",
ValidateFunc: validation.Any(
location.EnhancedValidate,
validation.StringInSlice([]string{
"global",
}, false),
),
StateFunc: location.StateFunc,
DiffSuppressFunc: location.DiffSuppressFunc,
},

"short_name": {
Type: pluginsdk.TypeString,
Required: true,
Expand Down Expand Up @@ -476,6 +492,7 @@ func resourceMonitorActionGroupCreateUpdate(d *pluginsdk.ResourceData, meta inte
client := meta.(*clients.Client).Monitor.ActionGroupsClient
tenantId := meta.(*clients.Client).Account.TenantId
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
location := location.Normalize(d.Get("location").(string))
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -523,7 +540,7 @@ func resourceMonitorActionGroupCreateUpdate(d *pluginsdk.ResourceData, meta inte
expandedTags := tags.Expand(t)

parameters := insights.ActionGroupResource{
Location: utils.String(azure.NormalizeLocation("Global")),
Location: utils.String(location),
ActionGroup: &insights.ActionGroup{
GroupShortName: utils.String(shortName),
Enabled: utils.Bool(enabled),
Expand Down Expand Up @@ -572,6 +589,7 @@ func resourceMonitorActionGroupRead(d *pluginsdk.ResourceData, meta interface{})

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))

if group := resp.ActionGroup; group != nil {
d.Set("short_name", group.GroupShortName)
Expand Down
36 changes: 36 additions & 0 deletions internal/services/monitor/monitor_action_group_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,21 @@ func TestAccMonitorActionGroup_disabledUpdate(t *testing.T) {
})
}

func TestAccMonitorActionGroup_location(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test")
r := MonitorActionGroupResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.location(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccMonitorActionGroup_singleReceiverUpdate(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test")
r := MonitorActionGroupResource{}
Expand Down Expand Up @@ -1163,3 +1178,24 @@ func (t MonitorActionGroupResource) Exists(ctx context.Context, clients *clients

return utils.Bool(resp.ID != nil), nil
}

func (MonitorActionGroupResource) location(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

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
location = "swedencentral"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
1 change: 1 addition & 0 deletions website/docs/r/monitor_action_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ The following arguments are supported:
* `email_receiver` - (Optional) One or more `email_receiver` blocks as defined below.
* `event_hub_receiver` - (Optional) One or more `event_hub_receiver` blocks as defined below.
* `itsm_receiver` - (Optional) One or more `itsm_receiver` blocks as defined below.
* `location` - (Optional) The Azure Region where the Action Group should exist. Changing this forces a new Action Group to be created. Defaults to `global`.
* `logic_app_receiver` - (Optional) One or more `logic_app_receiver` blocks as defined below.
* `sms_receiver` - (Optional) One or more `sms_receiver` blocks as defined below.
* `voice_receiver` - (Optional) One or more `voice_receiver` blocks as defined below.
Expand Down