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 1 commit
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,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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ func resourceArmApplicationInsights() *schema.Resource {
}, true),
},

"retention_in_days": {
Type: schema.TypeInt,
Optional: true,
Default: 90,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is a breaking change since the API doesn't provide retention_in_days by default. This means that users migrating to this update will see a change like retention_in_days = 0 -> 90. We can't have this so this default should be removed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the API returns a default we can probably just use computed instead

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API returns nil. So I removed the default value.

ValidateFunc: validation.IntInSlice([]int{
30,
60,
90,
120,
180,
270,
365,
550,
730,
}),
},

"sampling_percentage": {
Type: schema.TypeFloat,
Optional: true,
Expand Down Expand Up @@ -111,13 +128,15 @@ 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{})

applicationInsightsComponentProperties := insights.ApplicationInsightsComponentProperties{
ApplicationID: &name,
ApplicationType: insights.ApplicationType(applicationType),
RetentionInDays: utils.Int32(int32(retentionInDays)),
SamplingPercentage: samplingPercentage,
}

Expand Down Expand Up @@ -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)
}

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. Possible values are `30`, `60`, `90`, `120`, `180`, `270`, `365`, `550` or `730`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a datasource so can we word this as such

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* `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