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

azurerm_application_insights - support for sampling_percentage #4925

Merged
merged 7 commits into from
Nov 21, 2019
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
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),
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

As this is a percentage could we validate it is between 0 and 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