From 139db4629bd0c9e52c32573209e18730a3896f28 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:59:16 -0600 Subject: [PATCH 01/13] Updated location on monitor_action_group doc --- website/docs/r/monitor_action_group.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/monitor_action_group.html.markdown b/website/docs/r/monitor_action_group.html.markdown index c264f23b4aba..cc1c30ece09f 100644 --- a/website/docs/r/monitor_action_group.html.markdown +++ b/website/docs/r/monitor_action_group.html.markdown @@ -122,6 +122,7 @@ The following arguments are supported: * `name` - (Required) The name of the Action Group. Changing this forces a new resource to be created. * `resource_group_name` - (Required) The name of the resource group in which to create the Action Group instance. Changing this forces a new resource to be created. +* `location` - (Optional) The Azure Region where the Action Group should exist. Changing this forces a new Action Group to be created. Defaults to `Global`. * `short_name` - (Required) The short name of the action group. This will be used in SMS messages. * `enabled` - (Optional) Whether this action group is enabled. If an action group is not enabled, then none of its receivers will receive communications. Defaults to `true`. * `arm_role_receiver` - (Optional) One or more `arm_role_receiver` blocks as defined below. From ef312eb3fbb82c908b36b6b70026dcfc9be36071 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Tue, 21 Feb 2023 16:00:56 -0600 Subject: [PATCH 02/13] Add loc parameter to monitor_action_group_resource --- .../services/monitor/monitor_action_group_resource.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_action_group_resource.go b/internal/services/monitor/monitor_action_group_resource.go index b01d32e7677c..eb2250f00fc4 100644 --- a/internal/services/monitor/monitor_action_group_resource.go +++ b/internal/services/monitor/monitor_action_group_resource.go @@ -58,6 +58,13 @@ func resourceMonitorActionGroup() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupName(), + "location": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Global", + ForceNew: true, + }, + "short_name": { Type: pluginsdk.TypeString, Required: true, @@ -476,6 +483,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 := d.Get("location").(string) ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -523,7 +531,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), From 89b1c13e20a54ba3f96fdb2fd25f652e99287300 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Thu, 23 Feb 2023 08:35:05 -0600 Subject: [PATCH 03/13] Updated per recommendations --- .../monitor/monitor_action_group_resource.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/services/monitor/monitor_action_group_resource.go b/internal/services/monitor/monitor_action_group_resource.go index eb2250f00fc4..2b85acd7a980 100644 --- a/internal/services/monitor/monitor_action_group_resource.go +++ b/internal/services/monitor/monitor_action_group_resource.go @@ -59,10 +59,18 @@ func resourceMonitorActionGroup() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupName(), "location": { - Type: pluginsdk.TypeString, - Optional: true, - Default: "Global", - ForceNew: true, + 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": { @@ -483,7 +491,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 := d.Get("location").(string) + location := location.Normalize(d.Get("location").(string)) ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() From 4ccc7cde666c6347526b9b384ff20134e37a3db9 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Thu, 23 Feb 2023 09:07:48 -0600 Subject: [PATCH 04/13] Added schema dependency --- internal/services/monitor/monitor_action_group_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/monitor/monitor_action_group_resource.go b/internal/services/monitor/monitor_action_group_resource.go index 2b85acd7a980..3607c41555eb 100644 --- a/internal/services/monitor/monitor_action_group_resource.go +++ b/internal/services/monitor/monitor_action_group_resource.go @@ -22,6 +22,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceMonitorActionGroup() *pluginsdk.Resource { From dc0abcaa48d4a3b24f12b7bf57811152162921e8 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Thu, 23 Feb 2023 09:13:54 -0600 Subject: [PATCH 05/13] fixed fmt --- .../monitor/monitor_action_group_resource.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/services/monitor/monitor_action_group_resource.go b/internal/services/monitor/monitor_action_group_resource.go index 3607c41555eb..fc823edccfca 100644 --- a/internal/services/monitor/monitor_action_group_resource.go +++ b/internal/services/monitor/monitor_action_group_resource.go @@ -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" @@ -22,7 +23,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) func resourceMonitorActionGroup() *pluginsdk.Resource { @@ -60,11 +60,11 @@ func resourceMonitorActionGroup() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupName(), "location": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "global", - ValidateFunc: validation.Any( + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: "global", + ValidateFunc: validation.Any( location.EnhancedValidate, validation.StringInSlice([]string{ "global", From d3fcc9c378142c98833cf00e8deadef37c981bf2 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Thu, 23 Feb 2023 09:38:03 -0600 Subject: [PATCH 06/13] lowercased global for location... --- website/docs/r/monitor_action_group.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/monitor_action_group.html.markdown b/website/docs/r/monitor_action_group.html.markdown index cc1c30ece09f..b37f0754b023 100644 --- a/website/docs/r/monitor_action_group.html.markdown +++ b/website/docs/r/monitor_action_group.html.markdown @@ -122,7 +122,7 @@ The following arguments are supported: * `name` - (Required) The name of the Action Group. Changing this forces a new resource to be created. * `resource_group_name` - (Required) The name of the resource group in which to create the Action Group instance. Changing this forces a new resource to be created. -* `location` - (Optional) The Azure Region where the Action Group should exist. Changing this forces a new Action Group to be created. Defaults to `Global`. +* `location` - (Optional) The Azure Region where the Action Group should exist. Changing this forces a new Action Group to be created. Defaults to `global`. * `short_name` - (Required) The short name of the action group. This will be used in SMS messages. * `enabled` - (Optional) Whether this action group is enabled. If an action group is not enabled, then none of its receivers will receive communications. Defaults to `true`. * `arm_role_receiver` - (Optional) One or more `arm_role_receiver` blocks as defined below. From ecfbb94c4893a1265e18d6c60df5f5b57fd17910 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Thu, 23 Feb 2023 09:55:03 -0600 Subject: [PATCH 07/13] Added test for Global location --- .../monitor_action_group_resource_test.go | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/internal/services/monitor/monitor_action_group_resource_test.go b/internal/services/monitor/monitor_action_group_resource_test.go index 3fe749a893fb..c13012663905 100644 --- a/internal/services/monitor/monitor_action_group_resource_test.go +++ b/internal/services/monitor/monitor_action_group_resource_test.go @@ -300,6 +300,38 @@ func TestAccMonitorActionGroup_disabledUpdate(t *testing.T) { }) } +func TestAccMonitorActionGroup_locationBasic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") + r := MonitorActionGroupResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.locationBasic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("location").HasValue("global"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("location").HasValue("global"), + ), + }, + data.ImportStep(), + { + Config: r.locationBasic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("enabled").HasValue("global"), + ), + }, + data.ImportStep(), + }) +} + func TestAccMonitorActionGroup_singleReceiverUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_monitor_action_group", "test") r := MonitorActionGroupResource{} @@ -1163,3 +1195,24 @@ func (t MonitorActionGroupResource) Exists(ctx context.Context, clients *clients return utils.Bool(resp.ID != nil), nil } + +func (MonitorActionGroupResource) locationBasic(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 = "global" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) +} From 95a42543d715a2e7196cb70e58a815edd4168078 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Thu, 23 Feb 2023 16:14:03 -0600 Subject: [PATCH 08/13] fixed test fmt --- internal/services/monitor/monitor_action_group_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_action_group_resource_test.go b/internal/services/monitor/monitor_action_group_resource_test.go index c13012663905..4d69fe013846 100644 --- a/internal/services/monitor/monitor_action_group_resource_test.go +++ b/internal/services/monitor/monitor_action_group_resource_test.go @@ -1212,7 +1212,7 @@ resource "azurerm_monitor_action_group" "test" { resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" enabled = false - location = "global" + location = "global" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 0186544d677c8dc94c00e74a15a2873447ee1b77 Mon Sep 17 00:00:00 2001 From: Mike Madeja Date: Fri, 24 Feb 2023 09:04:02 -0600 Subject: [PATCH 09/13] fixed location test on ImportStep() --- internal/services/monitor/monitor_action_group_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/monitor/monitor_action_group_resource_test.go b/internal/services/monitor/monitor_action_group_resource_test.go index 4d69fe013846..c8d45e6ec6cf 100644 --- a/internal/services/monitor/monitor_action_group_resource_test.go +++ b/internal/services/monitor/monitor_action_group_resource_test.go @@ -325,7 +325,7 @@ func TestAccMonitorActionGroup_locationBasic(t *testing.T) { Config: r.locationBasic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("enabled").HasValue("global"), + check.That(data.ResourceName).Key("location").HasValue("global"), ), }, data.ImportStep(), From 7172011b4fd58ef1751f97bd19db6d4fd715c297 Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Tue, 7 Mar 2023 09:50:29 -0600 Subject: [PATCH 10/13] Update internal/services/monitor/monitor_action_group_resource_test.go Co-authored-by: stephybun --- .../monitor_action_group_resource_test.go | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/internal/services/monitor/monitor_action_group_resource_test.go b/internal/services/monitor/monitor_action_group_resource_test.go index c8d45e6ec6cf..8be0a5372658 100644 --- a/internal/services/monitor/monitor_action_group_resource_test.go +++ b/internal/services/monitor/monitor_action_group_resource_test.go @@ -300,32 +300,15 @@ func TestAccMonitorActionGroup_disabledUpdate(t *testing.T) { }) } -func TestAccMonitorActionGroup_locationBasic(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.locationBasic(data), + Config: r.location(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("location").HasValue("global"), - ), - }, - data.ImportStep(), - { - Config: r.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("location").HasValue("global"), - ), - }, - data.ImportStep(), - { - Config: r.locationBasic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("location").HasValue("global"), ), }, data.ImportStep(), From 8bc3fd7088b1bbde562fcecd66175b3ba9f3737d Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Tue, 7 Mar 2023 09:50:41 -0600 Subject: [PATCH 11/13] Update internal/services/monitor/monitor_action_group_resource_test.go Co-authored-by: stephybun --- .../services/monitor/monitor_action_group_resource_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/monitor/monitor_action_group_resource_test.go b/internal/services/monitor/monitor_action_group_resource_test.go index 8be0a5372658..bd7ae6feca80 100644 --- a/internal/services/monitor/monitor_action_group_resource_test.go +++ b/internal/services/monitor/monitor_action_group_resource_test.go @@ -1179,7 +1179,7 @@ func (t MonitorActionGroupResource) Exists(ctx context.Context, clients *clients return utils.Bool(resp.ID != nil), nil } -func (MonitorActionGroupResource) locationBasic(data acceptance.TestData) string { +func (MonitorActionGroupResource) location(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -1195,7 +1195,7 @@ resource "azurerm_monitor_action_group" "test" { resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" enabled = false - location = "global" + location = "swedencentral" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } From 7e7fe586057cabd3ae19012f01c8a6c576df6caf Mon Sep 17 00:00:00 2001 From: Michael Madeja <28938328+mikemadeja@users.noreply.github.com> Date: Tue, 7 Mar 2023 09:53:33 -0600 Subject: [PATCH 12/13] Update monitor_action_group_resource.go --- internal/services/monitor/monitor_action_group_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/monitor/monitor_action_group_resource.go b/internal/services/monitor/monitor_action_group_resource.go index fc823edccfca..0472bd326a23 100644 --- a/internal/services/monitor/monitor_action_group_resource.go +++ b/internal/services/monitor/monitor_action_group_resource.go @@ -589,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) From 11d3b645d7c7782249476b003313c0ec90fb77d1 Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 9 Mar 2023 16:08:57 +0100 Subject: [PATCH 13/13] format test config and reorder location property in docs --- internal/services/monitor/monitor_action_group_resource_test.go | 2 +- website/docs/r/monitor_action_group.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/monitor/monitor_action_group_resource_test.go b/internal/services/monitor/monitor_action_group_resource_test.go index bd7ae6feca80..96110bc7d8c0 100644 --- a/internal/services/monitor/monitor_action_group_resource_test.go +++ b/internal/services/monitor/monitor_action_group_resource_test.go @@ -1195,7 +1195,7 @@ resource "azurerm_monitor_action_group" "test" { resource_group_name = azurerm_resource_group.test.name short_name = "acctestag" enabled = false - location = "swedencentral" + location = "swedencentral" } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/website/docs/r/monitor_action_group.html.markdown b/website/docs/r/monitor_action_group.html.markdown index b37f0754b023..fc8d62ad7a06 100644 --- a/website/docs/r/monitor_action_group.html.markdown +++ b/website/docs/r/monitor_action_group.html.markdown @@ -122,7 +122,6 @@ The following arguments are supported: * `name` - (Required) The name of the Action Group. Changing this forces a new resource to be created. * `resource_group_name` - (Required) The name of the resource group in which to create the Action Group instance. Changing this forces a new resource to be created. -* `location` - (Optional) The Azure Region where the Action Group should exist. Changing this forces a new Action Group to be created. Defaults to `global`. * `short_name` - (Required) The short name of the action group. This will be used in SMS messages. * `enabled` - (Optional) Whether this action group is enabled. If an action group is not enabled, then none of its receivers will receive communications. Defaults to `true`. * `arm_role_receiver` - (Optional) One or more `arm_role_receiver` blocks as defined below. @@ -132,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.