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

Creating azure app insights resource #3

Merged

Conversation

lstolyarov
Copy link
Contributor

No description provided.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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!

@@ -120,6 +120,8 @@ func Provider() terraform.ResourceProvider {
"azurerm_virtual_network": resourceArmVirtualNetwork(),
"azurerm_virtual_network_peering": resourceArmVirtualNetworkPeering(),

"azurerm_app_insights": resourceArmAppInsights(),
Copy link
Contributor

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?


insightProperties := appinsights.ApplicationInsightsComponent{
Name: &name,
Type: &insightsType,
Copy link
Contributor

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" {
Copy link
Contributor

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
Copy link
Contributor

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


d.Set("name", name)
d.Set("resource_group_name", resGroup)
d.Set("instrumentation_key", instrumentationKey)
Copy link
Contributor

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)
}

"github.com/hashicorp/terraform/helper/schema"
)

func resourceArmAppInsights() *schema.Resource {
Copy link
Contributor

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?

Required: true,
ForceNew: true,
},
"location": locationSchema(),
Copy link
Contributor

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),
},

kind := d.Get("kind").(string)
location := d.Get("location").(string)
tags := d.Get("tags").(map[string]interface{})
requestSource := "IbizaAIExtension"
Copy link
Contributor

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"
)

return fmt.Errorf("Error making Read request on Azure app insights %s: %s", name, err)
}

instrumentationKey := resp.ApplicationInsightsComponentProperties.InstrumentationKey
Copy link
Contributor

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


log.Printf("[DEBUG] Deleting app insights %s: %s", resGroup, name)

_, err = AppInsightsClient.Delete(resGroup, name)
Copy link
Contributor

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)
}

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a 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) {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

(done)

d.Set("name", name)
d.Set("resource_group_name", resGroup)
if resp.ApplicationInsightsComponentProperties != nil {
d.Set("application_id", resp.ApplicationInsightsComponentProperties.ApplicationID)
Copy link
Contributor

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)
Copy link
Contributor

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

(done)

Create: resourceArmApplicationInsightsCreateOrUpdate,
Read: resourceArmApplicationInsightsRead,
Update: resourceArmApplicationInsightsCreateOrUpdate,
Delete: resourceArmApplicationInsightsDelete,
Copy link
Contributor

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,
},

}

d.Set("name", name)
d.Set("resource_group_name", resGroup)
Copy link
Contributor

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))

Copy link
Contributor

Choose a reason for hiding this comment

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

(done)

}
}

var testAccAzureRMApplicationInsights_basic = `
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

(done)

"github.com/hashicorp/terraform/helper/validation"
)

func resourceArmApplicationInsights() *schema.Resource {
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

(done)

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

LGTM

@lstolyarov
Copy link
Contributor Author

@tombuildsstuff that's great. Thanks for the support.

@tombuildsstuff tombuildsstuff merged commit 28bbe92 into hashicorp:master Jun 23, 2017
tombuildsstuff added a commit that referenced this pull request Jun 23, 2017
tombuildsstuff added a commit that referenced this pull request Jul 4, 2017
tombuildsstuff added a commit that referenced this pull request Jul 4, 2017
tombuildsstuff pushed a commit that referenced this pull request Sep 14, 2017
tombuildsstuff pushed a commit that referenced this pull request Feb 27, 2019
mcdafydd added a commit to mcdafydd/terraform-provider-azurerm that referenced this pull request Feb 1, 2020
mbfrahry added a commit that referenced this pull request Mar 4, 2020
…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
@ghost
Copy link

ghost commented Apr 1, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants