-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Creating azure app insights resource #3
Creating azure app insights resource #3
Conversation
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.
Hey @lstolyarov
Thanks for this PR / porting the others over to the new repo :)
I've reviewed and left some comments in-line - but this is off to a good start and the main thing missing is acceptance tests
Thanks!
azurerm/provider.go
Outdated
@@ -120,6 +120,8 @@ func Provider() terraform.ResourceProvider { | |||
"azurerm_virtual_network": resourceArmVirtualNetwork(), | |||
"azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(), | |||
|
|||
"azurerm_app_insights": resourceArmAppInsights(), |
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.
can we name this azurerm_application_insights
to match the product name?
azurerm/resource_arm_app_insights.go
Outdated
|
||
insightProperties := appinsights.ApplicationInsightsComponent{ | ||
Name: &name, | ||
Type: &insightsType, |
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.
we can remove this, as it's set automatically by Azure
@@ -0,0 +1,145 @@ | |||
resource "azurerm_network_security_group" "network_security_group" { |
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.
can we remove this file - as I can't see it in the SDK repository?
@@ -0,0 +1,53 @@ | |||
// Package appinsights implements the Azure ARM Appinsights service API version |
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.
can we add this using govendor
? I believe govendor fetch github.com/Azure/azure-sdk-for-go/arm/appinsights@=v10.0.2-beta
should also update the vendor file
azurerm/resource_arm_app_insights.go
Outdated
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resGroup) | ||
d.Set("instrumentation_key", instrumentationKey) |
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.
can we ensure all fields are set here? I've previously looked into this resource and added:
if resp.ApplicationInsightsComponentProperties != nil {
d.Set("application_id", resp.ApplicationInsightsComponentProperties.ApplicationID)
d.Set("application_type", string(resp.ApplicationInsightsComponentProperties.ApplicationType))
d.Set("instrumentation_key", resp.ApplicationInsightsComponentProperties.InstrumentationKey)
}
azurerm/resource_arm_app_insights.go
Outdated
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceArmAppInsights() *schema.Resource { |
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.
can we add acceptance tests and import tests for this resource?
azurerm/resource_arm_app_insights.go
Outdated
Required: true, | ||
ForceNew: true, | ||
}, | ||
"location": locationSchema(), |
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.
there's some other fields we should provide here:
"application_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"application_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{
appinsights.Web,
appinsights.Other,
), true),
},
azurerm/resource_arm_app_insights.go
Outdated
kind := d.Get("kind").(string) | ||
location := d.Get("location").(string) | ||
tags := d.Get("tags").(map[string]interface{}) | ||
requestSource := "IbizaAIExtension" |
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.
From what I can see, this can only be set to:
// RequestSource enumerates the values for request source.
type RequestSource string
const (
// Rest specifies the rest state for request source.
Rest RequestSource = "rest"
)
azurerm/resource_arm_app_insights.go
Outdated
return fmt.Errorf("Error making Read request on Azure app insights %s: %s", name, err) | ||
} | ||
|
||
instrumentationKey := resp.ApplicationInsightsComponentProperties.InstrumentationKey |
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.
we should also check that ApplicationInsightComponentProperties
isn't nil
azurerm/resource_arm_app_insights.go
Outdated
|
||
log.Printf("[DEBUG] Deleting app insights %s: %s", resGroup, name) | ||
|
||
_, err = AppInsightsClient.Delete(resGroup, name) |
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.
can we check to ensure this has been deleted?
if err != nil {
if accResp.StatusCode == http.StatusNotFound {
return nil
}
return fmt.Errorf("Error issuing AzureRM delete request for App Insights '%s': %+v", name, err)
}
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.
Hey @lstolyarov
Thanks for this contribution - I've reviewed and left some comments in-line. Seeing as this was so close to completion, I've pushed commits to resolve each of those comments - I hope you don't mind.
Your contribution is still included (and still credited to you), with the appropriate modifications. Feel free to ask about any of the changes.
Tests pass:
$ TF_ACC=1 envchain azurerm go test ./azurerm -v -timeout 300m -parallel 5 -run TestAccAzureRMApplicationInsights
=== RUN TestAccAzureRMApplicationInsights_importBasicWeb
--- PASS: TestAccAzureRMApplicationInsights_importBasicWeb (50.07s)
=== RUN TestAccAzureRMApplicationInsights_importBasicOther
--- PASS: TestAccAzureRMApplicationInsights_importBasicOther (51.66s)
=== RUN TestAccAzureRMApplicationInsights_basicWeb
--- PASS: TestAccAzureRMApplicationInsights_basicWeb (62.12s)
=== RUN TestAccAzureRMApplicationInsights_basicOther
--- PASS: TestAccAzureRMApplicationInsights_basicOther (52.13s)
PASS
ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 216.001s
Thanks!
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAzureRMAppInsights_importBasic(t *testing.T) { |
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.
could we rename these to ApplicationInsights
for consistency?
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)
azurerm/resource_arm_app_insights.go
Outdated
d.Set("name", name) | ||
d.Set("resource_group_name", resGroup) | ||
if resp.ApplicationInsightsComponentProperties != nil { | ||
d.Set("application_id", resp.ApplicationInsightsComponentProperties.ApplicationID) |
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.
From what I can see, ApplicationID
appears to be the same as the name in all circumstances - as such I think we should be exposing AppID
instead?
func TestAccAzureRMAppInsights_basic(t *testing.T) { | ||
|
||
ri := acctest.RandInt() | ||
config := fmt.Sprintf(testAccAzureRMApplicationInsights_basic, ri, ri) |
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.
for newer resources we're tending to make these functions return a formatted strings, i.e. func testAccAzureRMApplicationInsights_basic(ri)
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)
azurerm/resource_arm_app_insights.go
Outdated
Create: resourceArmApplicationInsightsCreateOrUpdate, | ||
Read: resourceArmApplicationInsightsRead, | ||
Update: resourceArmApplicationInsightsCreateOrUpdate, | ||
Delete: resourceArmApplicationInsightsDelete, |
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.
there's tests for import, but this resource doesn't currently support it - could we add the code to do this?
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
azurerm/resource_arm_app_insights.go
Outdated
} | ||
|
||
d.Set("name", name) | ||
d.Set("resource_group_name", resGroup) |
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.
could we also set the location
field here:
d.Set("location", azureRMNormalizeLocation(*resp.Location))
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)
} | ||
} | ||
|
||
var testAccAzureRMApplicationInsights_basic = ` |
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.
it'd be good to include a test for the other
application_type
here too if possible
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)
azurerm/resource_arm_app_insights.go
Outdated
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func resourceArmApplicationInsights() *schema.Resource { |
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.
could we add some documentation for this resource too?
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)
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.
LGTM
@tombuildsstuff that's great. Thanks for the support. |
Creating azure app insights resource
…m_monitor_scheduled_query_rules_log` (#5053) * New Resource: `azurerm_monitor_scheduled_query_rules` * Acceptance tests passing * Fix linting errors; minor cleanup * Minor updates and bug fixes - Fix some sprintf formatting - Improve documentation for cross-resource query - Don't create an empty metric_trigger {} if user doesn't specify block * Remove heredoc in docs example * fix response import * Update tests and docs to pass checks * Add moved tests to registration * First pass update docs post-review * First pass at separating into two resources * Rename action to alert in docs * Fix code review items * Fix lint issues and minor typos * Fix lint issues #2 * Fix lint issues #3 * Fix documentation error * Add monitor helpers * First pass address latest review * Validate metric_trigger query; add example to docs * Address review comments - Fix test crash - Move common functions to helpers - Add more schema validations - Add Update tests * Fix type assertions; simplify cross-resource query example * Review updates - Add metric alerts to LogToMetric tests and docs - Fix type assert from change to TypeList - Fix a couple typos * Add MaxItems for cross-resource query * Address review comments - Improve docs - Use heredoc strings in docs and test queries - Move shared functions into monitor package - Add underscores to test function names * Fix markdown formatting
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
No description provided.