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 2 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
13 changes: 13 additions & 0 deletions azurerm/resource_arm_application_insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func resourceArmApplicationInsights() *schema.Resource {
}, true),
},

"sampling_percentage": {
Type: schema.TypeFloat,
Optional: true,
},
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 @@ -111,6 +116,10 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int
ApplicationType: insights.ApplicationType(applicationType),
}

if v, ok := d.GetOk("sampling_percentage"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is a float it'll have a default value of 0.0 so this won't be valid; as such is it worth defaulting this value to 100% in the schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good to know, making 100% the default sounds good to me

applicationInsightsComponentProperties.SamplingPercentage = utils.Float(v.(float64))
}

insightProperties := insights.ApplicationInsightsComponent{
Name: &name,
Location: &location,
Expand Down Expand Up @@ -176,6 +185,10 @@ 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)

if v := props.SamplingPercentage; v != nil {
d.Set("sampling_percentage", v)
}
aqche marked this conversation as resolved.
Show resolved Hide resolved
}

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