-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Add application insights data source #2625
Merged
katbyte
merged 7 commits into
hashicorp:master
from
TheoremOne:feature/appinsights-data-source
Jan 10, 2019
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cc14b88
Add Application Insights data source
inkel 4ae5564
Add documentation for app insights data source
inkel 9898fc3
Add additional attributes on app insights data source
inkel 17741a2
Validate against empty strings instead of zero value
inkel 1dd1d93
Let ResourceData.Set handle dereferencing pointers
inkel 9a082d4
Use helper to set tags
inkel 601fdb9
Update App Insights data source documentation
inkel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmApplicationInsights() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmApplicationInsightsRead, | ||
Schema: map[string]*schema.Schema{ | ||
"resource_group_name": resourceGroupNameForDataSourceSchema(), | ||
|
||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"instrumentation_key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"location": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"application_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"app_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": { | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmApplicationInsightsRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).appInsightsClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
resGroup := d.Get("resource_group_name").(string) | ||
name := d.Get("name").(string) | ||
|
||
resp, err := client.Get(ctx, resGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
return fmt.Errorf("Error: Application Insights bucket %q (Resource Group %q) was not found", name, resGroup) | ||
} | ||
|
||
return fmt.Errorf("Error making Read request on Application Insights bucket %q (Resource Group %q): %+v", name, resGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
d.Set("instrumentation_key", resp.InstrumentationKey) | ||
d.Set("location", resp.Location) | ||
d.Set("app_id", resp.AppID) | ||
d.Set("application_type", resp.ApplicationType) | ||
flattenAndSetTags(d, resp.Tags) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceApplicationInsights_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_application_insights.test" | ||
ri := acctest.RandInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccResourceApplicationInsights_complete(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "instrumentation_key"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "app_id"), | ||
resource.TestCheckResourceAttrSet(dataSourceName, "location"), | ||
resource.TestCheckResourceAttr(dataSourceName, "application_type", "other"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.foo", "bar"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccResourceApplicationInsights_complete(rInt int, location string) string { | ||
return fmt.Sprintf(` | ||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-%[1]d" | ||
location = "%[2]s" | ||
} | ||
|
||
resource "azurerm_application_insights" "test" { | ||
name = "acctestappinsights-%[1]d" | ||
location = "${azurerm_resource_group.test.location}" | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
application_type = "other" | ||
|
||
tags { | ||
"foo" = "bar" | ||
} | ||
} | ||
|
||
data "azurerm_application_insights" "test" { | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
name = "${azurerm_application_insights.test.name}" | ||
} | ||
`, rInt, location) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
layout: "azurerm" | ||
page_title: "Azure Resource Manager: azurerm_application_insights" | ||
sidebar_current: "docs-azurerm-datasource-application-insights" | ||
description: |- | ||
Gets information about an existing Application Insights component. | ||
--- | ||
|
||
# Data Source: azurerm_application_insights | ||
|
||
Use this data source to access information about an existing Application Insights component. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "azurerm_application_insights" "test" { | ||
name = "production" | ||
resource_group_name = "networking" | ||
} | ||
|
||
output "application_insights_instrumentation_key" { | ||
value = "${data.azurerm_application_insights.test.instrumentation_key}" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) Specifies the name of the Application Insights component. | ||
* `resource_group_name` - (Required) Specifies the name of the resource group the Application Insights component is located in. | ||
|
||
## Attributes Reference | ||
inkel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
* `id` - The ID of the Virtual Machine. | ||
* `app_id` - The App ID associated with this Application Insights component. | ||
* `application_type` - The type of the component. | ||
* `instrumentation_key` - The instrumentation key of the Application Insights component. | ||
* `location` - The Azure location where the component exists. | ||
* `tags` - Tags applied to the component. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor could we sort this alphabetically to match the rest of this list? it helps when skimming it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. I did an alphabetical sort of this list and there actually many elements out of order:
Would you prefer leaving sorting all the lines for another PR and just place
azurerm_application_insights
where it should be, or should I send the change for all the lines? Sorting all the lines is a bit out of scope of this PR, IMO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another PR for this would be great 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll mark this one as resolved and then send a subsequent PR once this gets merged with the sorting. Sounds good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #2638
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@inkel sorry I didn't realise they weren't in order! Thanks for #2638 in any case, I'll take a look now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem! <3