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 the daily_data_cap_in_gb & daily_data_cap_notifications_disabled properties #5480

Merged
merged 5 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Client struct {
APIKeysClient *insights.APIKeysClient
ComponentsClient *insights.ComponentsClient
WebTestsClient *insights.WebTestsClient
BillingFeatureClient *insights.ComponentCurrentBillingFeaturesClient
wasfree marked this conversation as resolved.
Show resolved Hide resolved
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -25,10 +26,14 @@ func NewClient(o *common.ClientOptions) *Client {
webTestsClient := insights.NewWebTestsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&webTestsClient.Client, o.ResourceManagerAuthorizer)

billingFeatureClient := insights.NewComponentCurrentBillingFeaturesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&billingFeatureClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AnalyticsItemsClient: &analyticsItemsClient,
APIKeysClient: &apiKeysClient,
ComponentsClient: &componentsClient,
WebTestsClient: &webTestsClient,
BillingFeatureClient: &billingFeatureClient,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ func resourceArmApplicationInsights() *schema.Resource {

"tags": tags.Schema(),

"daily_cap": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be better as

Suggested change
"daily_cap": {
"daily_traffic_cap_in_gb": {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This option is related to data which is actually stored in applications insight. So my recommendation would be daily_data_cap_in_gb. What you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

works for me!

Type: schema.TypeFloat,
Optional: true,
Default: 100,
wasfree marked this conversation as resolved.
Show resolved Hide resolved
ValidateFunc: validation.FloatBetween(0, 1000),
},

"stop_send_notification_when_hit_cap": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This property is awfully odd, could we invert and reword it to

Suggested change
"stop_send_notification_when_hit_cap": {
"daily_traffic_cap_notifications_enabled": {

where true -> sends false, false -> send true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @katbyte,
agree with you awfully odd. But i think we should name it the other way. Because in general people will only touch this option if they want to stop notifications if cap is hit e.g. disabled = true.

daily_data_cap_notifications_disabled
true -> don't send messages
false -> send messages
default is false

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok with daily_data_cap_notifications_disabled, thanks!

Type: schema.TypeBool,
Optional: true,
Default: false,
wasfree marked this conversation as resolved.
Show resolved Hide resolved
},

"app_id": {
Type: schema.TypeString,
Computed: true,
Expand All @@ -105,7 +118,9 @@ func resourceArmApplicationInsights() *schema.Resource {

func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).AppInsights.ComponentsClient
billingFeatureClient := meta.(*clients.Client).AppInsights.BillingFeatureClient
wasfree marked this conversation as resolved.
Show resolved Hide resolved
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)

defer cancel()

log.Printf("[INFO] preparing arguments for AzureRM Application Insights creation.")
Expand All @@ -128,6 +143,8 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int

applicationType := d.Get("application_type").(string)
samplingPercentage := utils.Float(d.Get("sampling_percentage").(float64))
dailyCap := utils.Float(d.Get("daily_cap").(float64))
stopSendNotificationWhenHitCap := utils.Bool(d.Get("stop_send_notification_when_hit_cap").(bool))
location := azure.NormalizeLocation(d.Get("location").(string))
t := d.Get("tags").(map[string]interface{})

Expand Down Expand Up @@ -167,13 +184,32 @@ func resourceArmApplicationInsightsCreateUpdate(d *schema.ResourceData, meta int
return fmt.Errorf("Cannot read AzureRM Application Insights '%s' (Resource Group %s) ID", name, resGroup)
}

billingFeatureRead, err := billingFeatureClient.Get(ctx, resGroup, name)
if err != nil {
return fmt.Errorf("Error read Application Insights Billing Features %q (Resource Group %q): %+v", name, resGroup, err)
}

applicationInsightsComponentBillingFeatures := insights.ApplicationInsightsComponentBillingFeatures{
CurrentBillingFeatures: billingFeatureRead.CurrentBillingFeatures,
DataVolumeCap: &insights.ApplicationInsightsComponentDataVolumeCap{
Cap: dailyCap,
StopSendNotificationWhenHitCap: stopSendNotificationWhenHitCap,
},
}

_, err = billingFeatureClient.Update(ctx, resGroup, name, applicationInsightsComponentBillingFeatures)
if err != nil {
wasfree marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("Error update Application Insights Billing Feature %q (Resource Group %q): %+v", name, resGroup, err)
}

d.SetId(*read.ID)

return resourceArmApplicationInsightsRead(d, meta)
}

func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).AppInsights.ComponentsClient
billingFeatureClient := meta.(*clients.Client).AppInsights.BillingFeatureClient
wasfree marked this conversation as resolved.
Show resolved Hide resolved
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -196,6 +232,11 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error making Read request on AzureRM Application Insights '%s': %+v", name, err)
}

billingFeatureResp, err := billingFeatureClient.Get(ctx, resGroup, name)
wasfree marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("Error making Read request on AzureRM Application Insights Billing Feature '%s': %+v", name, err)
}

d.Set("name", name)
d.Set("resource_group_name", resGroup)
if location := resp.Location; location != nil {
Expand All @@ -212,6 +253,11 @@ func resourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}
}
}

if billingFeatureProps := billingFeatureResp.DataVolumeCap; billingFeatureProps != nil {
d.Set("daily_cap", billingFeatureProps.Cap)
d.Set("stop_send_notification_when_hit_cap", billingFeatureProps.StopSendNotificationWhenHitCap)
}

return tags.FlattenAndSet(d, resp.Tags)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func TestAccAzureRMApplicationInsights_complete(t *testing.T) {
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, "daily_cap", "50"),
resource.TestCheckResourceAttr(data.ResourceName, "stop_send_notification_when_hit_cap", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.Hello", "World"),
),
Expand Down Expand Up @@ -297,12 +299,14 @@ resource "azurerm_resource_group" "test" {
}

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"
retention_in_days = 120
sampling_percentage = 50
name = "acctestappinsights-%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
application_type = "%s"
retention_in_days = 120
sampling_percentage = 50
daily_cap = 50
stop_send_notification_when_hit_cap = true

tags = {
Hello = "World"
Expand Down
4 changes: 4 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,10 @@ 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.

* `daily_cap` - (Optional) Specifies the Application Insights component daily data volume cap in GB. Default is `100`.

* `stop_send_notification_when_hit_cap` - (Optional) Specifies if a notification email will be send when the daily data volume cap is met. Default to `false`.

* `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.
Expand Down