diff --git a/azurerm/resource_arm_application_insights.go b/azurerm/resource_arm_application_insights.go index 04e1a01a1b95..dba18cf56124 100644 --- a/azurerm/resource_arm_application_insights.go +++ b/azurerm/resource_arm_application_insights.go @@ -63,6 +63,13 @@ func resourceArmApplicationInsights() *schema.Resource { }, true), }, + "sampling_percentage": { + Type: schema.TypeFloat, + Optional: true, + Default: 100, + ValidateFunc: validation.FloatBetween(0, 100), + }, + "tags": tags.Schema(), "app_id": { @@ -103,12 +110,14 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int } applicationType := d.Get("application_type").(string) + 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), + ApplicationID: &name, + ApplicationType: insights.ApplicationType(applicationType), + SamplingPercentage: samplingPercentage, } insightProperties := insights.ApplicationInsightsComponent{ @@ -176,6 +185,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("sampling_percentage", props.SamplingPercentage) } return tags.FlattenAndSet(d, resp.Tags) diff --git a/azurerm/resource_arm_application_insights_test.go b/azurerm/resource_arm_application_insights_test.go index 7b0e0e3a7006..c92886f815dd 100644 --- a/azurerm/resource_arm_application_insights_test.go +++ b/azurerm/resource_arm_application_insights_test.go @@ -279,6 +279,35 @@ func testCheckAzureRMApplicationInsightsExists(resourceName string) resource.Tes } } +func TestAccAzureRMApplicationInsights_complete(t *testing.T) { + resourceName := "azurerm_application_insights.test" + ri := tf.AccRandTimeInt() + config := testAccAzureRMApplicationInsights_complete(ri, testLocation(), "web") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMApplicationInsightsDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMApplicationInsightsExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "application_type", "web"), + resource.TestCheckResourceAttr(resourceName, "sampling_percentage", "50"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + resource.TestCheckResourceAttr(resourceName, "tags.Hello", "World"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccAzureRMApplicationInsights_basic(rInt int, location string, applicationType string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { @@ -308,3 +337,24 @@ resource "azurerm_application_insights" "import" { } `, template) } + +func testAccAzureRMApplicationInsights_complete(rInt int, location string, applicationType string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%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" + sampling_percentage = 50 + + tags = { + Hello = "World" + } +} +`, rInt, location, rInt, applicationType) +} diff --git a/website/docs/r/application_insights.html.markdown b/website/docs/r/application_insights.html.markdown index 80922b18dc3c..062259870be0 100644 --- a/website/docs/r/application_insights.html.markdown +++ b/website/docs/r/application_insights.html.markdown @@ -49,6 +49,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. +* `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. ## Attributes Reference