Skip to content

Commit

Permalink
azurerm_application_insights - support for `sampling_percenta… (#4925)
Browse files Browse the repository at this point in the history
Fixes #4487
  • Loading branch information
aqche authored and katbyte committed Nov 21, 2019
1 parent 5a7ede9 commit 517c543
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
14 changes: 12 additions & 2 deletions azurerm/resource_arm_application_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions azurerm/resource_arm_application_insights_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
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 @@ -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
Expand Down

0 comments on commit 517c543

Please sign in to comment.