Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions internal/provider/provider_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,12 @@ func TestResourcesDoNotContainLocalAuthenticationDisabled(t *testing.T) {
}
sort.Strings(resourceNames)

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

for _, resourceName := range resourceNames {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/applicationinsights/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -80,10 +81,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
}, false),
},

// NOTE: O+C A Log Analytics Workspace will be attached to the Application Insight by default, which should be computed=true
"workspace_id": {
Type: pluginsdk.TypeString,
Optional: true,
Type: pluginsdk.TypeString,
Optional: true,
// NOTE: O+C A Log Analytics Workspace will be attached to the Application Insight by default, which should be computed=true
Computed: true,
ValidateFunc: workspaces.ValidateWorkspaceID,
},
Expand Down Expand Up @@ -112,10 +113,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
ValidateFunc: validation.FloatBetween(0, 100),
},

"disable_ip_masking": {
"ip_masking_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
Default: true,
},

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

"daily_data_cap_notifications_disabled": {
"daily_data_cap_notifications_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"app_id": {
Expand All @@ -149,10 +151,10 @@ func resourceApplicationInsights() *pluginsdk.Resource {
Sensitive: true,
},

"local_authentication_disabled": {
"local_authentication_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
Default: true,
},

"internet_ingestion_enabled": {
Expand All @@ -174,6 +176,53 @@ func resourceApplicationInsights() *pluginsdk.Resource {
},
}

if !features.FivePointOh() {
resource.Schema["local_authentication_disabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
Deprecated: "`local_authentication_disabled` has been deprecated in favour of `local_authentication_enabled` and will be removed in v5.0 of the AzureRM Provider",
ConflictsWith: []string{"local_authentication_enabled"},
}

resource.Schema["local_authentication_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"local_authentication_disabled"},
}

resource.Schema["disable_ip_masking"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
Deprecated: "`disable_ip_masking` has been deprecated in favour of `ip_masking_enabled` and will be removed in v5.0 of the AzureRM Provider",
ConflictsWith: []string{"ip_masking_enabled"},
}

resource.Schema["ip_masking_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"disable_ip_masking"},
}

resource.Schema["daily_data_cap_notifications_disabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
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",
ConflictsWith: []string{"daily_data_cap_notifications_enabled"},
}

resource.Schema["daily_data_cap_notifications_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Computed: true,
ConflictsWith: []string{"daily_data_cap_notifications_disabled"},
}
}

return resource
}

Expand Down Expand Up @@ -211,13 +260,31 @@ func resourceApplicationInsightsCreate(d *pluginsdk.ResourceData, meta interface
ApplicationId: pointer.To(id.ComponentName),
ApplicationType: components.ApplicationType(d.Get("application_type").(string)),
SamplingPercentage: pointer.To(d.Get("sampling_percentage").(float64)),
DisableIPMasking: pointer.To(d.Get("disable_ip_masking").(bool)),
DisableLocalAuth: pointer.To(d.Get("local_authentication_disabled").(bool)),
DisableIPMasking: pointer.To(!d.Get("ip_masking_enabled").(bool)),
DisableLocalAuth: pointer.To(!d.Get("local_authentication_enabled").(bool)),
PublicNetworkAccessForIngestion: pointer.To(internetIngestionEnabled),
PublicNetworkAccessForQuery: pointer.To(internetQueryEnabled),
ForceCustomerStorageForProfiler: pointer.To(d.Get("force_customer_storage_for_profiler").(bool)),
}

if !features.FivePointOh() {
applicationInsightsComponentProperties.DisableIPMasking = pointer.To(false)
if !pluginsdk.IsExplicitlyNullInConfig(d, "ip_masking_enabled") {
applicationInsightsComponentProperties.DisableIPMasking = pointer.To(!d.Get("ip_masking_enabled").(bool))
}
if !pluginsdk.IsExplicitlyNullInConfig(d, "disable_ip_masking") {
applicationInsightsComponentProperties.DisableIPMasking = pointer.To(d.Get("disable_ip_masking").(bool))
}

applicationInsightsComponentProperties.DisableLocalAuth = pointer.To(false)
if !pluginsdk.IsExplicitlyNullInConfig(d, "local_authentication_enabled") {
applicationInsightsComponentProperties.DisableLocalAuth = pointer.To(!d.Get("local_authentication_enabled").(bool))
}
if !pluginsdk.IsExplicitlyNullInConfig(d, "local_authentication_disabled") {
applicationInsightsComponentProperties.DisableLocalAuth = pointer.To(d.Get("local_authentication_disabled").(bool))
}
}

if workspaceRaw, ok := d.GetOk("workspace_id"); ok {
workspaceID, err := workspaces.ParseWorkspaceID(workspaceRaw.(string))
if err != nil {
Expand Down Expand Up @@ -285,8 +352,15 @@ func resourceApplicationInsightsCreate(d *pluginsdk.ResourceData, meta interface
applicationInsightsComponentBillingFeatures.DataVolumeCap.Cap = pointer.To(v.(float64))
}

if v, ok := d.GetOk("daily_data_cap_notifications_disabled"); ok {
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(v.(bool))
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(!d.Get("daily_data_cap_notifications_enabled").(bool))
if !features.FivePointOh() {
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(false)
if !pluginsdk.IsExplicitlyNullInConfig(d, "daily_data_cap_notifications_enabled") {
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(!d.Get("daily_data_cap_notifications_enabled").(bool))
}
if !pluginsdk.IsExplicitlyNullInConfig(d, "daily_data_cap_notifications_disabled") {
applicationInsightsComponentBillingFeatures.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(d.Get("daily_data_cap_notifications_disabled").(bool))
}
}

if _, err = billingClient.ComponentCurrentBillingFeaturesUpdate(ctx, *billingId, applicationInsightsComponentBillingFeatures); err != nil {
Expand Down Expand Up @@ -385,9 +459,15 @@ func resourceApplicationInsightsRead(d *pluginsdk.ResourceData, meta interface{}
d.Set("app_id", props.AppId)
d.Set("instrumentation_key", props.InstrumentationKey)
d.Set("sampling_percentage", props.SamplingPercentage)
d.Set("disable_ip_masking", props.DisableIPMasking)
d.Set("ip_masking_enabled", !pointer.From(props.DisableIPMasking))
if !features.FivePointOh() {
d.Set("disable_ip_masking", pointer.From(props.DisableIPMasking))
}
d.Set("connection_string", props.ConnectionString)
d.Set("local_authentication_disabled", props.DisableLocalAuth)
d.Set("local_authentication_enabled", !pointer.From(props.DisableLocalAuth))
if !features.FivePointOh() {
d.Set("local_authentication_disabled", pointer.From(props.DisableLocalAuth))
}
d.Set("internet_ingestion_enabled", pointer.From(props.PublicNetworkAccessForIngestion) == components.PublicNetworkAccessTypeEnabled)
d.Set("internet_query_enabled", pointer.From(props.PublicNetworkAccessForQuery) == components.PublicNetworkAccessTypeEnabled)
d.Set("force_customer_storage_for_profiler", props.ForceCustomerStorageForProfiler)
Expand All @@ -407,7 +487,10 @@ func resourceApplicationInsightsRead(d *pluginsdk.ResourceData, meta interface{}
if model := billingResp.Model; model != nil {
if props := model.DataVolumeCap; props != nil {
d.Set("daily_data_cap_in_gb", props.Cap)
d.Set("daily_data_cap_notifications_disabled", props.StopSendNotificationWhenHitCap)
d.Set("daily_data_cap_notifications_enabled", !pointer.From(props.StopSendNotificationWhenHitCap))
if !features.FivePointOh() {
d.Set("daily_data_cap_notifications_disabled", pointer.From(props.StopSendNotificationWhenHitCap))
}
}
}

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

if d.HasChange("disable_ip_masking") {
component.Properties.DisableIPMasking = pointer.To(d.Get("disable_ip_masking").(bool))
if d.HasChange("ip_masking_enabled") {
component.Properties.DisableIPMasking = pointer.To(!d.Get("ip_masking_enabled").(bool))
}

if !features.FivePointOh() {
if d.HasChange("disable_ip_masking") {
component.Properties.DisableIPMasking = pointer.To(d.Get("disable_ip_masking").(bool))
}
}

if d.HasChange("local_authentication_enabled") {
component.Properties.DisableLocalAuth = pointer.To(!d.Get("local_authentication_enabled").(bool))
}

if d.HasChange("local_authentication_disabled") {
component.Properties.DisableLocalAuth = pointer.To(d.Get("local_authentication_disabled").(bool))
if !features.FivePointOh() {
if d.HasChange("local_authentication_disabled") {
component.Properties.DisableLocalAuth = pointer.To(d.Get("local_authentication_disabled").(bool))
}
}

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

if d.HasChange("daily_data_cap_notifications_disabled") {
billingProps.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(d.Get("daily_data_cap_notifications_disabled").(bool))
if d.HasChange("daily_data_cap_notifications_enabled") {
billingProps.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(!d.Get("daily_data_cap_notifications_enabled").(bool))
}

if !features.FivePointOh() {
if d.HasChange("daily_data_cap_notifications_disabled") {
billingProps.DataVolumeCap.StopSendNotificationWhenHitCap = pointer.To(d.Get("daily_data_cap_notifications_disabled").(bool))
}
}

if _, err = billingClient.ComponentCurrentBillingFeaturesUpdate(ctx, *billingId, *billingProps); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
)

Expand Down Expand Up @@ -198,8 +199,8 @@ func TestAccApplicationInsights_complete(t *testing.T) {
check.That(data.ResourceName).Key("retention_in_days").HasValue("120"),
check.That(data.ResourceName).Key("sampling_percentage").HasValue("50"),
check.That(data.ResourceName).Key("daily_data_cap_in_gb").HasValue("50"),
check.That(data.ResourceName).Key("daily_data_cap_notifications_disabled").HasValue("true"),
check.That(data.ResourceName).Key("local_authentication_disabled").HasValue("true"),
check.That(data.ResourceName).Key("daily_data_cap_notifications_enabled").HasValue("false"),
check.That(data.ResourceName).Key("local_authentication_enabled").HasValue("false"),
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("tags.Hello").HasValue("World"),
),
Expand Down Expand Up @@ -395,7 +396,8 @@ resource "azurerm_application_insights" "import" {
}

func (ApplicationInsightsResource) complete(data acceptance.TestData, applicationType string) string {
return fmt.Sprintf(`
if !features.FivePointOh() {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
Expand All @@ -422,11 +424,42 @@ resource "azurerm_application_insights" "test" {
Hello = "World"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
}

return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-appinsights-%d"
location = "%s"
}

resource "azurerm_application_insights" "test" {
name = "acctestappinsights-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
application_type = "%s"
retention_in_days = 120
sampling_percentage = 50
daily_data_cap_in_gb = 50
daily_data_cap_notifications_enabled = false
ip_masking_enabled = false
force_customer_storage_for_profiler = true
local_authentication_enabled = false

tags = {
Hello = "World"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
}

func (ApplicationInsightsResource) completeUpdated(data acceptance.TestData, applicationType string) string {
return fmt.Sprintf(`
if !features.FivePointOh() {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
Expand All @@ -453,6 +486,36 @@ resource "azurerm_application_insights" "test" {
Hello = "World"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
}

return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-appinsights-%d"
location = "%s"
}

resource "azurerm_application_insights" "test" {
name = "acctestappinsights-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
application_type = "%s"
retention_in_days = 60
sampling_percentage = 60
daily_data_cap_in_gb = 60
daily_data_cap_notifications_enabled = true
ip_masking_enabled = true
force_customer_storage_for_profiler = false
local_authentication_enabled = true

tags = {
Hello = "World"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, applicationType)
}

Expand Down
Loading
Loading