Skip to content

Commit 43c4772

Browse files
authored
Resolve TODO 4.0 comments for TestResourcesDoNotContainLocalAuthenticationDisabled (#32634)
1 parent 08edd4c commit 43c4772

8 files changed

Lines changed: 284 additions & 43 deletions

internal/provider/provider_schema_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,12 @@ func TestResourcesDoNotContainLocalAuthenticationDisabled(t *testing.T) {
556556
}
557557
sort.Strings(resourceNames)
558558

559-
// TODO: 4.0 - work through this list
560-
resourcesWhichNeedToBeAddressed := map[string]struct{}{
561-
"azurerm_application_insights": {},
562-
"azurerm_cosmosdb_account": {},
563-
"azurerm_log_analytics_workspace": {},
559+
resourcesWhichNeedToBeAddressed := make(map[string]struct{})
560+
if !features.FivePointOh() {
561+
// These have been addressed but while in 4.x we need to ignore them so the test can pass.
562+
resourcesWhichNeedToBeAddressed["azurerm_application_insights"] = struct{}{}
563+
resourcesWhichNeedToBeAddressed["azurerm_cosmosdb_account"] = struct{}{}
564+
resourcesWhichNeedToBeAddressed["azurerm_log_analytics_workspace"] = struct{}{}
564565
}
565566

566567
for _, resourceName := range resourceNames {

internal/services/applicationinsights/application_insights_resource.go

Lines changed: 122 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2323
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
2424
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
25+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
2526
"github.com/hashicorp/terraform-provider-azurerm/internal/services/applicationinsights/migration"
2627
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
2728
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
@@ -80,10 +81,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
8081
}, false),
8182
},
8283

83-
// NOTE: O+C A Log Analytics Workspace will be attached to the Application Insight by default, which should be computed=true
8484
"workspace_id": {
85-
Type: pluginsdk.TypeString,
86-
Optional: true,
85+
Type: pluginsdk.TypeString,
86+
Optional: true,
87+
// NOTE: O+C A Log Analytics Workspace will be attached to the Application Insight by default, which should be computed=true
8788
Computed: true,
8889
ValidateFunc: workspaces.ValidateWorkspaceID,
8990
},
@@ -112,10 +113,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
112113
ValidateFunc: validation.FloatBetween(0, 100),
113114
},
114115

115-
"disable_ip_masking": {
116+
"ip_masking_enabled": {
116117
Type: pluginsdk.TypeBool,
117118
Optional: true,
118-
Default: false,
119+
Default: true,
119120
},
120121

121122
"tags": commonschema.Tags(),
@@ -127,9 +128,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
127128
ValidateFunc: validation.FloatAtLeast(0),
128129
},
129130

130-
"daily_data_cap_notifications_disabled": {
131+
"daily_data_cap_notifications_enabled": {
131132
Type: pluginsdk.TypeBool,
132133
Optional: true,
134+
Default: true,
133135
},
134136

135137
"app_id": {
@@ -149,10 +151,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
149151
Sensitive: true,
150152
},
151153

152-
"local_authentication_disabled": {
154+
"local_authentication_enabled": {
153155
Type: pluginsdk.TypeBool,
154156
Optional: true,
155-
Default: false,
157+
Default: true,
156158
},
157159

158160
"internet_ingestion_enabled": {
@@ -174,6 +176,53 @@ func resourceApplicationInsights() *pluginsdk.Resource {
174176
},
175177
}
176178

179+
if !features.FivePointOh() {
180+
resource.Schema["local_authentication_disabled"] = &pluginsdk.Schema{
181+
Type: pluginsdk.TypeBool,
182+
Optional: true,
183+
Computed: true,
184+
Deprecated: "`local_authentication_disabled` has been deprecated in favour of `local_authentication_enabled` and will be removed in v5.0 of the AzureRM Provider",
185+
ConflictsWith: []string{"local_authentication_enabled"},
186+
}
187+
188+
resource.Schema["local_authentication_enabled"] = &pluginsdk.Schema{
189+
Type: pluginsdk.TypeBool,
190+
Optional: true,
191+
Computed: true,
192+
ConflictsWith: []string{"local_authentication_disabled"},
193+
}
194+
195+
resource.Schema["disable_ip_masking"] = &pluginsdk.Schema{
196+
Type: pluginsdk.TypeBool,
197+
Optional: true,
198+
Computed: true,
199+
Deprecated: "`disable_ip_masking` has been deprecated in favour of `ip_masking_enabled` and will be removed in v5.0 of the AzureRM Provider",
200+
ConflictsWith: []string{"ip_masking_enabled"},
201+
}
202+
203+
resource.Schema["ip_masking_enabled"] = &pluginsdk.Schema{
204+
Type: pluginsdk.TypeBool,
205+
Optional: true,
206+
Computed: true,
207+
ConflictsWith: []string{"disable_ip_masking"},
208+
}
209+
210+
resource.Schema["daily_data_cap_notifications_disabled"] = &pluginsdk.Schema{
211+
Type: pluginsdk.TypeBool,
212+
Optional: true,
213+
Computed: true,
214+
Deprecated: "`daily_data_cap_notifications_disabled` has been deprecated in favour of `daily_data_cap_notifications_enabled` and will be removed in v5.0 of the AzureRM Provider",
215+
ConflictsWith: []string{"daily_data_cap_notifications_enabled"},
216+
}
217+
218+
resource.Schema["daily_data_cap_notifications_enabled"] = &pluginsdk.Schema{
219+
Type: pluginsdk.TypeBool,
220+
Optional: true,
221+
Computed: true,
222+
ConflictsWith: []string{"daily_data_cap_notifications_disabled"},
223+
}
224+
}
225+
177226
return resource
178227
}
179228

@@ -211,13 +260,31 @@ func resourceApplicationInsightsCreate(d *pluginsdk.ResourceData, meta interface
211260
ApplicationId: pointer.To(id.ComponentName),
212261
ApplicationType: components.ApplicationType(d.Get("application_type").(string)),
213262
SamplingPercentage: pointer.To(d.Get("sampling_percentage").(float64)),
214-
DisableIPMasking: pointer.To(d.Get("disable_ip_masking").(bool)),
215-
DisableLocalAuth: pointer.To(d.Get("local_authentication_disabled").(bool)),
263+
DisableIPMasking: pointer.To(!d.Get("ip_masking_enabled").(bool)),
264+
DisableLocalAuth: pointer.To(!d.Get("local_authentication_enabled").(bool)),
216265
PublicNetworkAccessForIngestion: pointer.To(internetIngestionEnabled),
217266
PublicNetworkAccessForQuery: pointer.To(internetQueryEnabled),
218267
ForceCustomerStorageForProfiler: pointer.To(d.Get("force_customer_storage_for_profiler").(bool)),
219268
}
220269

270+
if !features.FivePointOh() {
271+
applicationInsightsComponentProperties.DisableIPMasking = pointer.To(false)
272+
if !pluginsdk.IsExplicitlyNullInConfig(d, "ip_masking_enabled") {
273+
applicationInsightsComponentProperties.DisableIPMasking = pointer.To(!d.Get("ip_masking_enabled").(bool))
274+
}
275+
if !pluginsdk.IsExplicitlyNullInConfig(d, "disable_ip_masking") {
276+
applicationInsightsComponentProperties.DisableIPMasking = pointer.To(d.Get("disable_ip_masking").(bool))
277+
}
278+
279+
applicationInsightsComponentProperties.DisableLocalAuth = pointer.To(false)
280+
if !pluginsdk.IsExplicitlyNullInConfig(d, "local_authentication_enabled") {
281+
applicationInsightsComponentProperties.DisableLocalAuth = pointer.To(!d.Get("local_authentication_enabled").(bool))
282+
}
283+
if !pluginsdk.IsExplicitlyNullInConfig(d, "local_authentication_disabled") {
284+
applicationInsightsComponentProperties.DisableLocalAuth = pointer.To(d.Get("local_authentication_disabled").(bool))
285+
}
286+
}
287+
221288
if workspaceRaw, ok := d.GetOk("workspace_id"); ok {
222289
workspaceID, err := workspaces.ParseWorkspaceID(workspaceRaw.(string))
223290
if err != nil {
@@ -285,8 +352,15 @@ func resourceApplicationInsightsCreate(d *pluginsdk.ResourceData, meta interface
285352
applicationInsightsComponentBillingFeatures.DataVolumeCap.Cap = pointer.To(v.(float64))
286353
}
287354

288-
if v, ok := d.GetOk("daily_data_cap_notifications_disabled"); ok {
289-
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(v.(bool))
355+
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(!d.Get("daily_data_cap_notifications_enabled").(bool))
356+
if !features.FivePointOh() {
357+
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(false)
358+
if !pluginsdk.IsExplicitlyNullInConfig(d, "daily_data_cap_notifications_enabled") {
359+
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(!d.Get("daily_data_cap_notifications_enabled").(bool))
360+
}
361+
if !pluginsdk.IsExplicitlyNullInConfig(d, "daily_data_cap_notifications_disabled") {
362+
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(d.Get("daily_data_cap_notifications_disabled").(bool))
363+
}
290364
}
291365

292366
if _, err = billingClient.ComponentCurrentBillingFeaturesUpdate(ctx, *billingId, applicationInsightsComponentBillingFeatures); err != nil {
@@ -385,9 +459,15 @@ func resourceApplicationInsightsRead(d *pluginsdk.ResourceData, meta interface{}
385459
d.Set("app_id", props.AppId)
386460
d.Set("instrumentation_key", props.InstrumentationKey)
387461
d.Set("sampling_percentage", props.SamplingPercentage)
388-
d.Set("disable_ip_masking", props.DisableIPMasking)
462+
d.Set("ip_masking_enabled", !pointer.From(props.DisableIPMasking))
463+
if !features.FivePointOh() {
464+
d.Set("disable_ip_masking", pointer.From(props.DisableIPMasking))
465+
}
389466
d.Set("connection_string", props.ConnectionString)
390-
d.Set("local_authentication_disabled", props.DisableLocalAuth)
467+
d.Set("local_authentication_enabled", !pointer.From(props.DisableLocalAuth))
468+
if !features.FivePointOh() {
469+
d.Set("local_authentication_disabled", pointer.From(props.DisableLocalAuth))
470+
}
391471
d.Set("internet_ingestion_enabled", pointer.From(props.PublicNetworkAccessForIngestion) == components.PublicNetworkAccessTypeEnabled)
392472
d.Set("internet_query_enabled", pointer.From(props.PublicNetworkAccessForQuery) == components.PublicNetworkAccessTypeEnabled)
393473
d.Set("force_customer_storage_for_profiler", props.ForceCustomerStorageForProfiler)
@@ -407,7 +487,10 @@ func resourceApplicationInsightsRead(d *pluginsdk.ResourceData, meta interface{}
407487
if model := billingResp.Model; model != nil {
408488
if props := model.DataVolumeCap; props != nil {
409489
d.Set("daily_data_cap_in_gb", props.Cap)
410-
d.Set("daily_data_cap_notifications_disabled", props.StopSendNotificationWhenHitCap)
490+
d.Set("daily_data_cap_notifications_enabled", !pointer.From(props.StopSendNotificationWhenHitCap))
491+
if !features.FivePointOh() {
492+
d.Set("daily_data_cap_notifications_disabled", pointer.From(props.StopSendNotificationWhenHitCap))
493+
}
411494
}
412495
}
413496

@@ -447,12 +530,24 @@ func resourceApplicationInsightsUpdate(d *pluginsdk.ResourceData, meta interface
447530
component.Properties.SamplingPercentage = pointer.To(d.Get("sampling_percentage").(float64))
448531
}
449532

450-
if d.HasChange("disable_ip_masking") {
451-
component.Properties.DisableIPMasking = pointer.To(d.Get("disable_ip_masking").(bool))
533+
if d.HasChange("ip_masking_enabled") {
534+
component.Properties.DisableIPMasking = pointer.To(!d.Get("ip_masking_enabled").(bool))
535+
}
536+
537+
if !features.FivePointOh() {
538+
if d.HasChange("disable_ip_masking") {
539+
component.Properties.DisableIPMasking = pointer.To(d.Get("disable_ip_masking").(bool))
540+
}
541+
}
542+
543+
if d.HasChange("local_authentication_enabled") {
544+
component.Properties.DisableLocalAuth = pointer.To(!d.Get("local_authentication_enabled").(bool))
452545
}
453546

454-
if d.HasChange("local_authentication_disabled") {
455-
component.Properties.DisableLocalAuth = pointer.To(d.Get("local_authentication_disabled").(bool))
547+
if !features.FivePointOh() {
548+
if d.HasChange("local_authentication_disabled") {
549+
component.Properties.DisableLocalAuth = pointer.To(d.Get("local_authentication_disabled").(bool))
550+
}
456551
}
457552

458553
if d.HasChange("internet_ingestion_enabled") {
@@ -527,8 +622,14 @@ func resourceApplicationInsightsUpdate(d *pluginsdk.ResourceData, meta interface
527622
billingProps.DataVolumeCap.Cap = pointer.To(d.Get("daily_data_cap_in_gb").(float64))
528623
}
529624

530-
if d.HasChange("daily_data_cap_notifications_disabled") {
531-
billingProps.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(d.Get("daily_data_cap_notifications_disabled").(bool))
625+
if d.HasChange("daily_data_cap_notifications_enabled") {
626+
billingProps.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(!d.Get("daily_data_cap_notifications_enabled").(bool))
627+
}
628+
629+
if !features.FivePointOh() {
630+
if d.HasChange("daily_data_cap_notifications_disabled") {
631+
billingProps.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(d.Get("daily_data_cap_notifications_disabled").(bool))
632+
}
532633
}
533634

534635
if _, err = billingClient.ComponentCurrentBillingFeaturesUpdate(ctx, *billingId, *billingProps); err != nil {

internal/services/applicationinsights/application_insights_resource_test.go

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
1414
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
1515
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
16+
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
1617
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
1718
)
1819

@@ -198,8 +199,8 @@ func TestAccApplicationInsights_complete(t *testing.T) {
198199
check.That(data.ResourceName).Key("retention_in_days").HasValue("120"),
199200
check.That(data.ResourceName).Key("sampling_percentage").HasValue("50"),
200201
check.That(data.ResourceName).Key("daily_data_cap_in_gb").HasValue("50"),
201-
check.That(data.ResourceName).Key("daily_data_cap_notifications_disabled").HasValue("true"),
202-
check.That(data.ResourceName).Key("local_authentication_disabled").HasValue("true"),
202+
check.That(data.ResourceName).Key("daily_data_cap_notifications_enabled").HasValue("false"),
203+
check.That(data.ResourceName).Key("local_authentication_enabled").HasValue("false"),
203204
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
204205
check.That(data.ResourceName).Key("tags.Hello").HasValue("World"),
205206
),
@@ -395,7 +396,8 @@ resource "azurerm_application_insights" "import" {
395396
}
396397

397398
func (ApplicationInsightsResource) complete(data acceptance.TestData, applicationType string) string {
398-
return fmt.Sprintf(`
399+
if !features.FivePointOh() {
400+
return fmt.Sprintf(`
399401
provider "azurerm" {
400402
features {}
401403
}
@@ -422,11 +424,42 @@ resource "azurerm_application_insights" "test" {
422424
Hello = "World"
423425
}
424426
}
427+
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
428+
}
429+
430+
return fmt.Sprintf(`
431+
provider "azurerm" {
432+
features {}
433+
}
434+
435+
resource "azurerm_resource_group" "test" {
436+
name = "acctestRG-appinsights-%d"
437+
location = "%s"
438+
}
439+
440+
resource "azurerm_application_insights" "test" {
441+
name = "acctestappinsights-%d"
442+
location = azurerm_resource_group.test.location
443+
resource_group_name = azurerm_resource_group.test.name
444+
application_type = "%s"
445+
retention_in_days = 120
446+
sampling_percentage = 50
447+
daily_data_cap_in_gb = 50
448+
daily_data_cap_notifications_enabled = false
449+
ip_masking_enabled = false
450+
force_customer_storage_for_profiler = true
451+
local_authentication_enabled = false
452+
453+
tags = {
454+
Hello = "World"
455+
}
456+
}
425457
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
426458
}
427459

428460
func (ApplicationInsightsResource) completeUpdated(data acceptance.TestData, applicationType string) string {
429-
return fmt.Sprintf(`
461+
if !features.FivePointOh() {
462+
return fmt.Sprintf(`
430463
provider "azurerm" {
431464
features {}
432465
}
@@ -453,6 +486,36 @@ resource "azurerm_application_insights" "test" {
453486
Hello = "World"
454487
}
455488
}
489+
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
490+
}
491+
492+
return fmt.Sprintf(`
493+
provider "azurerm" {
494+
features {}
495+
}
496+
497+
resource "azurerm_resource_group" "test" {
498+
name = "acctestRG-appinsights-%d"
499+
location = "%s"
500+
}
501+
502+
resource "azurerm_application_insights" "test" {
503+
name = "acctestappinsights-%d"
504+
location = azurerm_resource_group.test.location
505+
resource_group_name = azurerm_resource_group.test.name
506+
application_type = "%s"
507+
retention_in_days = 60
508+
sampling_percentage = 60
509+
daily_data_cap_in_gb = 60
510+
daily_data_cap_notifications_enabled = true
511+
ip_masking_enabled = true
512+
force_customer_storage_for_profiler = false
513+
local_authentication_enabled = true
514+
515+
tags = {
516+
Hello = "World"
517+
}
518+
}
456519
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
457520
}
458521

0 commit comments

Comments
 (0)