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

Feature: azurem_application_insights add support for retention_in_days #5457

Merged
merged 2 commits into from
Jan 22, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func dataSourceArmApplicationInsights() *schema.Resource {
Computed: true,
},

"retention_in_days": {
Type: schema.TypeInt,
Computed: true,
},

"tags": {
Type: schema.TypeMap,
Computed: true,
Expand Down Expand Up @@ -83,5 +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)
if v := resp.RetentionInDays; v != nil {
d.Set("retention_in_days", v)
}
return tags.FlattenAndSet(d, resp.Tags)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ func resourceArmApplicationInsights() *schema.Resource {
}, true),
},

"retention_in_days": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntInSlice([]int{
30,
60,
90,
120,
180,
270,
365,
550,
730,
}),
},

"sampling_percentage": {
Type: schema.TypeFloat,
Optional: true,
Expand Down Expand Up @@ -121,6 +137,10 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int
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,
Expand Down Expand Up @@ -187,6 +207,9 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}
d.Set("app_id", props.AppID)
d.Set("instrumentation_key", props.InstrumentationKey)
d.Set("sampling_percentage", props.SamplingPercentage)
if v := props.RetentionInDays; v != nil {
d.Set("retention_in_days", v)
}
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/application_insights.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* `tags` - Tags applied to the component.
2 changes: 2 additions & 0 deletions website/docs/r/application_insights.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down