Skip to content

Commit

Permalink
fix(browserapplication): fixes to #2577, export application_id (#2617)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-new-relic authored Mar 26, 2024
1 parent 529f3ed commit 62eb058
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
7 changes: 7 additions & 0 deletions newrelic/resource_newrelic_agent_application_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -55,6 +56,11 @@ func resourceNewRelicBrowserApplication() *schema.Resource {
Computed: true,
Description: "The GUID of the browser application.",
},
"application_id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the browser application.",
},
"account_id": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -131,6 +137,7 @@ func resourceNewRelicBrowserApplicationRead(ctx context.Context, d *schema.Resou
_ = d.Set("loader_type", string(entity.BrowserSettings.BrowserMonitoring.Loader))
_ = d.Set("guid", string(entity.GUID))
_ = d.Set("account_id", entity.AccountID)
_ = d.Set("application_id", strconv.Itoa(entity.ApplicationID))

// The following block of code encodes the JavaScript configuration of the browser application into a JSON,
// that is then exported as a string, which can be accessed from the Terraform Configuration using jsondecode().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestAccNewRelicAgentApplicationBrowser(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckNewRelicAgentApplicationBrowserExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "js_config"),
resource.TestCheckResourceAttrSet(resourceName, "application_id"),
testAccCheckJsConfigNestedAttributes(resourceName, "js_config", []string{"init", "info", "loader_config"}),
),
},
Expand Down Expand Up @@ -138,12 +139,12 @@ func testAccCheckJsConfigNestedAttributes(resourceName, key string, jsConfigNest

func testAccNewRelicAgentApplicationBrowserConfig(accountID int, name string, loaderType string) string {
return fmt.Sprintf(`
resource newrelic_browser_application foo {
account_id = %[1]d
name = "%[2]s"
cookies_enabled = true
distributed_tracing_enabled = true
loader_type = "%[3]s"
}
resource "newrelic_browser_application" "foo" {
account_id = %[1]d
name = "%[2]s"
cookies_enabled = true
distributed_tracing_enabled = true
loader_type = "%[3]s"
}
`, accountID, name, loaderType)
}
23 changes: 12 additions & 11 deletions website/docs/r/browser_application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: "newrelic"
page_title: "New Relic: newrelic_browser_application"
sidebar_current: "docs-newrelic-browser-application"
description: |-
Create, update, and delete a standalone New Relic browser application.
Create, update, and delete a standalone New Relic browser application.
---

# Resource: newrelic\_browser\_application
Expand All @@ -12,13 +12,13 @@ Use this resource to create, update, and delete a standalone New Relic browser a

## Example Usage

Basic usage to create a standalone browser application.
The following Terraform configuration is an example that illustrates the basic use case of creating a standalone browser application.
```hcl
resource "newrelic_browser_application" "foo" {
name = "example-browser-app"
cookies_enabled = true
name = "example-browser-app"
cookies_enabled = true
distributed_tracing_enabled = true
loader_type = "SPA"
loader_type = "SPA"
}
```

Expand All @@ -27,21 +27,22 @@ resource "newrelic_browser_application" "foo" {
The following arguments are supported:

* `name` - (Required) The name of the browser application.
* `cookies_enabled` - (Optional) Configure cookies. The default is enabled: true.
* `distributed_tracing_enabled` - (Optional) Configure distributed tracing in browser apps. The default is enabled: true.
* `loader_type` - (Optional) Determines which browser loader is configured. Valid values are `SPA`, `PRO`, and `LITE`. The default is `SPA`. See the [browser agent loader documentation](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/#agent-types) for a for information on the valid loader types.
* `account_id` - (Optional) The New Relic account ID of the account you wish to create the browser application. Defaults to the account ID set in your environment variable `NEW_RELIC_ACCOUNT_ID`.

* `cookies_enabled` - (Optional) Configures cookies. Defaults to `true`, if not specified.
* `distributed_tracing_enabled` - (Optional) Configures distributed tracing in browser apps. Defaults to `true`, if not specified.
* `loader_type` - (Optional) Determines the browser loader configured. Valid values are `SPA`, `PRO`, and `LITE`. The default is `SPA`. Refer to the [browser agent loader documentation](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/#agent-types) for more information on valid loader types.
* `account_id` - (Optional) The account ID of the New Relic account you wish to create the browser application in. Defaults to the value of the environment variable `NEW_RELIC_ACCOUNT_ID` if not specified.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The GUID of the browser application.
* `application_id` - The application ID of the browser application (not to be confused with GUID).
* `js_config` - The JavaScript configuration of the browser application, encoded into a string.

## Import

Browser applications can be imported using the GUID of the browser application.
A browser application can be imported using its GUID, i.e.

```bash
$ terraform import newrelic_browser_application.foo <GUID>
Expand Down

0 comments on commit 62eb058

Please sign in to comment.