From 0a263eeee361caa01bc789c2fcf11fe06d5fdfae Mon Sep 17 00:00:00 2001 From: v-cheye Date: Tue, 21 Jan 2020 10:41:06 +0800 Subject: [PATCH 1/2] Add more support for retention days of azurerm_application_insights --- .../data_source_application_insights.go | 6 ++++++ .../resource_arm_application_insights.go | 20 +++++++++++++++++++ .../resource_arm_application_insights_test.go | 2 ++ .../docs/d/application_insights.html.markdown | 1 + .../docs/r/application_insights.html.markdown | 2 ++ 5 files changed, 31 insertions(+) diff --git a/azurerm/internal/services/applicationinsights/data_source_application_insights.go b/azurerm/internal/services/applicationinsights/data_source_application_insights.go index 3d0909018966..b38e7e96b171 100644 --- a/azurerm/internal/services/applicationinsights/data_source_application_insights.go +++ b/azurerm/internal/services/applicationinsights/data_source_application_insights.go @@ -50,6 +50,11 @@ func dataSourceArmApplicationInsights() *schema.Resource { Computed: true, }, + "retention_in_days": { + Type: schema.TypeInt, + Computed: true, + }, + "tags": { Type: schema.TypeMap, Computed: true, @@ -83,5 +88,6 @@ func dataSourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface d.Set("location", resp.Location) d.Set("app_id", resp.AppID) d.Set("application_type", resp.ApplicationType) + d.Set("retention_in_days", resp.RetentionInDays) return tags.FlattenAndSet(d, resp.Tags) } diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go index 1b415eaff967..5950f40ced7f 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go @@ -64,6 +64,23 @@ func resourceArmApplicationInsights() *schema.Resource { }, true), }, + "retention_in_days": { + Type: schema.TypeInt, + Optional: true, + Default: 90, + ValidateFunc: validation.IntInSlice([]int{ + 30, + 60, + 90, + 120, + 180, + 270, + 365, + 550, + 730, + }), + }, + "sampling_percentage": { Type: schema.TypeFloat, Optional: true, @@ -111,6 +128,7 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int } applicationType := d.Get("application_type").(string) + retentionInDays := d.Get("retention_in_days").(int) samplingPercentage := utils.Float(d.Get("sampling_percentage").(float64)) location := azure.NormalizeLocation(d.Get("location").(string)) t := d.Get("tags").(map[string]interface{}) @@ -118,6 +136,7 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int applicationInsightsComponentProperties := insights.ApplicationInsightsComponentProperties{ ApplicationID: &name, ApplicationType: insights.ApplicationType(applicationType), + RetentionInDays: utils.Int32(int32(retentionInDays)), SamplingPercentage: samplingPercentage, } @@ -186,6 +205,7 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{} d.Set("application_type", string(props.ApplicationType)) d.Set("app_id", props.AppID) d.Set("instrumentation_key", props.InstrumentationKey) + d.Set("retention_in_days", props.RetentionInDays) d.Set("sampling_percentage", props.SamplingPercentage) } diff --git a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go index ecef591fa4e5..dbec9f93435b 100644 --- a/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go +++ b/azurerm/internal/services/applicationinsights/tests/resource_arm_application_insights_test.go @@ -248,6 +248,7 @@ func TestAccAzureRMApplicationInsights_complete(t *testing.T) { Check: resource.ComposeTestCheckFunc( testCheckAzureRMApplicationInsightsExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "application_type", "web"), + resource.TestCheckResourceAttr(data.ResourceName, "retention_in_days", "120"), resource.TestCheckResourceAttr(data.ResourceName, "sampling_percentage", "50"), resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"), resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"), @@ -300,6 +301,7 @@ resource "azurerm_application_insights" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" application_type = "%s" + retention_in_days = 120 sampling_percentage = 50 tags = { diff --git a/website/docs/d/application_insights.html.markdown b/website/docs/d/application_insights.html.markdown index bcfe5060f22c..19925be36fea 100644 --- a/website/docs/d/application_insights.html.markdown +++ b/website/docs/d/application_insights.html.markdown @@ -35,4 +35,5 @@ output "application_insights_instrumentation_key" { * `application_type` - The type of the component. * `instrumentation_key` - The instrumentation key of the Application Insights component. * `location` - The Azure location where the component exists. +* `retention_in_days` - The retention period in days. Possible values are `30`, `60`, `90`, `120`, `180`, `270`, `365`, `550` or `730`. * `tags` - Tags applied to the component. diff --git a/website/docs/r/application_insights.html.markdown b/website/docs/r/application_insights.html.markdown index ffa0ae92fe99..328d71885eee 100644 --- a/website/docs/r/application_insights.html.markdown +++ b/website/docs/r/application_insights.html.markdown @@ -48,6 +48,8 @@ The following arguments are supported: * `application_type` - (Required) Specifies the type of Application Insights to create. Valid values are `ios` for _iOS_, `java` for _Java web_, `MobileCenter` for _App Center_, `Node.JS` for _Node.js_, `other` for _General_, `phone` for _Windows Phone_, `store` for _Windows Store_ and `web` for _ASP.NET_. Please note these values are case sensitive; unmatched values are treated as _ASP.NET_ by Azure. Changing this forces a new resource to be created. +* `retention_in_days` - (Optional) Specifies the retention period in days. Possible values are `30`, `60`, `90`, `120`, `180`, `270`, `365`, `550` or `730`. + * `sampling_percentage` - (Optional) Specifies the percentage of the data produced by the monitored application that is sampled for Application Insights telemetry. * `tags` - (Optional) A mapping of tags to assign to the resource. From f86bba8310484a0c61737c759faec89e95c8bee6 Mon Sep 17 00:00:00 2001 From: v-cheye Date: Wed, 22 Jan 2020 13:44:05 +0800 Subject: [PATCH 2/2] Update code --- .../data_source_application_insights.go | 4 +++- .../resource_arm_application_insights.go | 11 +++++++---- website/docs/d/application_insights.html.markdown | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/azurerm/internal/services/applicationinsights/data_source_application_insights.go b/azurerm/internal/services/applicationinsights/data_source_application_insights.go index b38e7e96b171..fc314c5ac254 100644 --- a/azurerm/internal/services/applicationinsights/data_source_application_insights.go +++ b/azurerm/internal/services/applicationinsights/data_source_application_insights.go @@ -88,6 +88,8 @@ func dataSourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface d.Set("location", resp.Location) d.Set("app_id", resp.AppID) d.Set("application_type", resp.ApplicationType) - d.Set("retention_in_days", resp.RetentionInDays) + if v := resp.RetentionInDays; v != nil { + d.Set("retention_in_days", v) + } return tags.FlattenAndSet(d, resp.Tags) } diff --git a/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go index 5950f40ced7f..272e29f1b5d5 100644 --- a/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go +++ b/azurerm/internal/services/applicationinsights/resource_arm_application_insights.go @@ -67,7 +67,6 @@ func resourceArmApplicationInsights() *schema.Resource { "retention_in_days": { Type: schema.TypeInt, Optional: true, - Default: 90, ValidateFunc: validation.IntInSlice([]int{ 30, 60, @@ -128,7 +127,6 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int } applicationType := d.Get("application_type").(string) - retentionInDays := d.Get("retention_in_days").(int) samplingPercentage := utils.Float(d.Get("sampling_percentage").(float64)) location := azure.NormalizeLocation(d.Get("location").(string)) t := d.Get("tags").(map[string]interface{}) @@ -136,10 +134,13 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int applicationInsightsComponentProperties := insights.ApplicationInsightsComponentProperties{ ApplicationID: &name, ApplicationType: insights.ApplicationType(applicationType), - RetentionInDays: utils.Int32(int32(retentionInDays)), SamplingPercentage: samplingPercentage, } + if v, ok := d.GetOk("retention_in_days"); ok { + applicationInsightsComponentProperties.RetentionInDays = utils.Int32(int32(v.(int))) + } + insightProperties := insights.ApplicationInsightsComponent{ Name: &name, Location: &location, @@ -205,8 +206,10 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{} d.Set("application_type", string(props.ApplicationType)) d.Set("app_id", props.AppID) d.Set("instrumentation_key", props.InstrumentationKey) - d.Set("retention_in_days", props.RetentionInDays) d.Set("sampling_percentage", props.SamplingPercentage) + if v := props.RetentionInDays; v != nil { + d.Set("retention_in_days", v) + } } return tags.FlattenAndSet(d, resp.Tags) diff --git a/website/docs/d/application_insights.html.markdown b/website/docs/d/application_insights.html.markdown index 19925be36fea..e537836077ff 100644 --- a/website/docs/d/application_insights.html.markdown +++ b/website/docs/d/application_insights.html.markdown @@ -35,5 +35,5 @@ output "application_insights_instrumentation_key" { * `application_type` - The type of the component. * `instrumentation_key` - The instrumentation key of the Application Insights component. * `location` - The Azure location where the component exists. -* `retention_in_days` - The retention period in days. Possible values are `30`, `60`, `90`, `120`, `180`, `270`, `365`, `550` or `730`. +* `retention_in_days` - The retention period in days. * `tags` - Tags applied to the component.