Skip to content

feat(newrelic_cloud_azure_integrations): addition of the integration 'azureMonitor' #2338

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

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/go-agent/v3 v3.20.3
github.com/newrelic/go-insights v1.0.3
github.com/newrelic/newrelic-client-go/v2 v2.18.1
github.com/newrelic/newrelic-client-go/v2 v2.19.0
github.com/stretchr/testify v1.8.2
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ github.com/newrelic/go-agent/v3 v3.20.3 h1:hUBAMq/Y2Y9as5/yxQbf0zNde/X7w58cWZkm2
github.com/newrelic/go-agent/v3 v3.20.3/go.mod h1:rT6ZUxJc5rQbWLyCtjqQCOcfb01lKRFbc1yMQkcboWM=
github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ=
github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4=
github.com/newrelic/newrelic-client-go/v2 v2.18.1 h1:7VRW32f+z+QCiz7VL5h5Dmo7gYoEMHBobkXNskyCCYE=
github.com/newrelic/newrelic-client-go/v2 v2.18.1/go.mod h1:AX08IIL08pYVbnowsR05EqOdfN1Dz+ZXdIwqS0dkT2c=
github.com/newrelic/newrelic-client-go/v2 v2.19.0 h1:iYF4fxotAPsl+/n1B/tbLqprBmU9HOrKeIiau94zAwQ=
github.com/newrelic/newrelic-client-go/v2 v2.19.0/go.mod h1:AX08IIL08pYVbnowsR05EqOdfN1Dz+ZXdIwqS0dkT2c=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand Down
4 changes: 2 additions & 2 deletions newrelic/resource_newrelic_cloud_aws_govcloud_link_account.go
Copy link
Member Author

Choose a reason for hiding this comment

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

A note for the reviewer: The changes in this file are not associated with the changes made to add the new Azure Integration; yet, they have been made as this datatype has been renamed ("C" made a capital letter in Govcloud) in client-go, as per the latest changes fetched via Tutone.

Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func resourceNewRelicAwsGovCloudLinkAccountCreate(ctx context.Context, d *schema

// Extracting the AWSGovCloud account credentials from Schema using expandAzureCloudLinkAccountInput
func expandAwsGovCloudLinkAccountInput(d *schema.ResourceData) cloud.CloudLinkCloudAccountsInput {
awsGovCloud := cloud.CloudAwsGovcloudLinkAccountInput{}
awsGovCloud := cloud.CloudAwsGovCloudLinkAccountInput{}
if accessKeyID, ok := d.GetOk("access_key_id"); ok {
awsGovCloud.AccessKeyId = accessKeyID.(string)
}
Expand All @@ -105,7 +105,7 @@ func expandAwsGovCloudLinkAccountInput(d *schema.ResourceData) cloud.CloudLinkCl
awsGovCloud.SecretAccessKey = secretKeyID.(cloud.SecureValue)
}
input := cloud.CloudLinkCloudAccountsInput{
AwsGovcloud: []cloud.CloudAwsGovcloudLinkAccountInput{awsGovCloud},
AwsGovcloud: []cloud.CloudAwsGovCloudLinkAccountInput{awsGovCloud},
}
return input
}
Expand Down
158 changes: 158 additions & 0 deletions newrelic/resource_newrelic_cloud_azure_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ func resourceNewRelicCloudAzureIntegrations() *schema.Resource {
Elem: cloudAzureIntegrationMariadbElem(),
MaxItems: 1,
},
"monitor": {
Type: schema.TypeList,
Optional: true,
Description: "The Azure Monitor",
Elem: cloudAzureIntegrationMonitorElem(),
MaxItems: 1,
},
"mysql": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -571,6 +578,61 @@ func cloudAzureIntegrationMysqlElem() *schema.Resource {

}

// cloudAzureIntegrationMonitorElem defines the schema of elements in the "monitor" Azure integration.
func cloudAzureIntegrationMonitorElem() *schema.Resource {
s := mergeSchemas(
cloudAzureIntegrationSchemaBase(),
cloudAzureIntegrationMonitorSchema())

return &schema.Resource{
Schema: s,
}
}

// cloudAzureIntegrationMonitorSchema defines the schema of elements specific to the "monitor" Azure integration.
func cloudAzureIntegrationMonitorSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "A flag that specifies if the integration is active",
},
"exclude_tags": {
Type: schema.TypeList,
Optional: true,
Description: "Specify resource tags in 'key:value' form to be excluded from monitoring",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"include_tags": {
Type: schema.TypeList,
Optional: true,
Description: "Specify resource tags in 'key:value' form to be monitored",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"resource_types": {
Type: schema.TypeList,
Optional: true,
Description: "Specify each Azure resource type that needs to be monitored",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"resource_groups": {
Type: schema.TypeList,
Optional: true,
Description: "Specify each Resource group associated with the resources that you want to monitor. Filter values are case-sensitive",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}
}

// function to add schema for azure mysql
func cloudAzureIntegrationMysqlFlexElem() *schema.Resource {
s := cloudAzureIntegrationSchemaBase()
Expand Down Expand Up @@ -940,6 +1002,12 @@ func expandCloudAzureIntegrationsInput(d *schema.ResourceData) (cloud.CloudInteg
cloudDisableAzureIntegration.AzureMariadb = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}

if v, ok := d.GetOk("monitor"); ok {
cloudAzureIntegration.AzureMonitor = expandCloudAzureIntegrationMonitorInput(v.([]interface{}), linkedAccountID)
} else if o, n := d.GetChange("monitor"); len(n.([]interface{})) < len(o.([]interface{})) {
cloudDisableAzureIntegration.AzureMonitor = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}

if v, ok := d.GetOk("mysql"); ok {
cloudAzureIntegration.AzureMysql = expandCloudAzureIntegrationMysqlInput(v.([]interface{}), linkedAccountID)
} else if o, n := d.GetChange("mysql"); len(n.([]interface{})) < len(o.([]interface{})) {
Expand Down Expand Up @@ -1649,6 +1717,73 @@ func expandCloudAzureIntegrationMariadbInput(b []interface{}, linkedAccountID in
return expanded
}

// Expanding the input for the azureMonitor integration
func expandCloudAzureIntegrationMonitorInput(b []interface{}, linkedAccountID int) []cloud.CloudAzureMonitorIntegrationInput {
expanded := make([]cloud.CloudAzureMonitorIntegrationInput, len(b))

for i, azureMonitor := range b {
var azureMonitorInput cloud.CloudAzureMonitorIntegrationInput

if azureMonitor == nil {
azureMonitorInput.LinkedAccountId = linkedAccountID
expanded[i] = azureMonitorInput
return expanded
}

in := azureMonitor.(map[string]interface{})

azureMonitorInput.LinkedAccountId = linkedAccountID

if m, ok := in["metrics_polling_interval"]; ok {
azureMonitorInput.MetricsPollingInterval = m.(int)
}
if r, ok := in["resource_groups"]; ok {
resourceGroups := r.([]interface{})
var groups []string

for _, group := range resourceGroups {
groups = append(groups, group.(string))
}
azureMonitorInput.ResourceGroups = groups
}
if rt, ok := in["resource_types"]; ok {
resourceTypes := rt.([]interface{})
var rTypes []string

for _, rType := range resourceTypes {
rTypes = append(rTypes, rType.(string))
}
azureMonitorInput.ResourceTypes = rTypes
}
if et, ok := in["exclude_tags"]; ok {
excludeTags := et.([]interface{})
var eTags []string

for _, eTag := range excludeTags {
eTags = append(eTags, eTag.(string))
}
azureMonitorInput.ExcludeTags = eTags
}

if it, ok := in["include_tags"]; ok {
includeTags := it.([]interface{})
var iTags []string

for _, iTag := range includeTags {
iTags = append(iTags, iTag.(string))
}
azureMonitorInput.IncludeTags = iTags
}

if enabled, ok := in["enabled"]; ok {
azureMonitorInput.Enabled = enabled.(bool)
}
expanded[i] = azureMonitorInput
}

return expanded
}

// Expanding the Azure_mysql

func expandCloudAzureIntegrationMysqlInput(b []interface{}, linkedAccountID int) []cloud.CloudAzureMysqlIntegrationInput {
Expand Down Expand Up @@ -2220,6 +2355,8 @@ func flattenCloudAzureLinkedAccount(d *schema.ResourceData, result *cloud.CloudL
_ = d.Set("machine_learning", flattenCloudAzureMachineLearningIntegration(t))
case *cloud.CloudAzureMariadbIntegration:
_ = d.Set("maria_db", flattenCloudAzureMariadbIntegration(t))
case *cloud.CloudAzureMonitorIntegration:
_ = d.Set("monitor", flattenCloudAzureMonitorIntegration(t))
case *cloud.CloudAzureMysqlIntegration:
_ = d.Set("mysql", flattenCloudAzureMysqlIntegration(t))
case *cloud.CloudAzureMysqlflexibleIntegration:
Expand Down Expand Up @@ -2508,6 +2645,24 @@ func flattenCloudAzureMariadbIntegration(in *cloud.CloudAzureMariadbIntegration)
return flattened
}

// Flatten values for the azureMonitor integration
func flattenCloudAzureMonitorIntegration(in *cloud.CloudAzureMonitorIntegration) []interface{} {
flattened := make([]interface{}, 1)

out := make(map[string]interface{})

out["metrics_polling_interval"] = in.MetricsPollingInterval
out["resource_groups"] = in.ResourceGroups
out["exclude_tags"] = in.ExcludeTags
out["include_tags"] = in.IncludeTags
out["resource_types"] = in.ResourceTypes
out["enabled"] = in.Enabled

flattened[0] = out

return flattened
}

// flatten for azure_mysql

func flattenCloudAzureMysqlIntegration(in *cloud.CloudAzureMysqlIntegration) []interface{} {
Expand Down Expand Up @@ -2843,6 +2998,9 @@ func expandCloudAzureDisableInputs(d *schema.ResourceData) cloud.CloudDisableInt
if _, ok := d.GetOk("maria_db"); ok {
cloudAzureDisableInput.AzureMariadb = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}
if _, ok := d.GetOk("monitor"); ok {
cloudAzureDisableInput.AzureMonitor = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}
if _, ok := d.GetOk("mysql"); ok {
cloudAzureDisableInput.AzureMysql = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}
Expand Down
18 changes: 18 additions & 0 deletions newrelic/resource_newrelic_cloud_azure_integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ resource "newrelic_cloud_azure_integrations" "bar" {
resource_groups = ["beyond"]
}

monitor {
metrics_polling_interval = 3600
resource_groups = ["beyond"]
include_tags = ["env:testing", "env:production"]
exclude_tags = ["env:staging"]
enabled = true
resource_types = ["microsoft.datashare/accounts"]
}

mysql {
metrics_polling_interval = 3600
resource_groups = ["beyond"]
Expand Down Expand Up @@ -386,6 +395,15 @@ resource "newrelic_cloud_azure_integrations" "bar" {
resource_groups = ["beyond"]
}

monitor {
metrics_polling_interval = 3600
resource_groups = ["beyond"]
include_tags = ["env:production"]
exclude_tags = ["env:staging"]
enabled = true
resource_types = ["microsoft.datashare/accounts", "microsoft.eventhub/clusters"]
}

mysql {
metrics_polling_interval = 3600
resource_groups = ["beyond"]
Expand Down
16 changes: 16 additions & 0 deletions website/docs/r/cloud_azure_integrations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ resource "newrelic_cloud_azure_integrations" "foo" {
resource_groups = ["resource_groups"]
}

monitor {
metrics_polling_interval = 1200
resource_groups = ["resource_groups"]
include_tags = ["env:production"]
exclude_tags = ["env:staging", "env:testing"]
enabled = true
resource_types = ["microsoft.datashare/accounts"]
}

mysql {
metrics_polling_interval = 1200
resource_groups = ["resource_groups"]
Expand Down Expand Up @@ -215,6 +224,7 @@ The following arguments are supported with minimum metric polling interval of 30
* `logic_apps` - (Optional) Azure Logic Apps. See [Integration blocks](#integration-blocks) below for details.
* `machine_learning` - (Optional) Azure Machine Learning. See [Integration blocks](#integration-blocks) below for details.
* `maria_db` - (Optional) Azure MariaDB. See [Integration blocks](#integration-blocks) below for details.
* `monitor` - (Optional) Azure Monitor. See [Integration blocks](#integration-blocks) below for details.
* `mysql` - (Optional) Azure MySQL. See [Integration blocks](#integration-blocks) below for details.
* `mysql_flexible` - (Optional) Azure MySQL Flexible Server. See [Integration blocks](#integration-blocks) below for details.
* `postgresql` - (Optional) Azure PostgreSQL. See [Integration blocks](#integration-blocks) below for details.
Expand Down Expand Up @@ -249,6 +259,12 @@ Other integration type support an additional argument:
* `cost_management`
* `tag_keys` - (Optional) Specify a Tag key associated with the resources that you want to monitor. Filter values are case-sensitive.

* `monitor`
* `resource_types` - (Optional) A list of Azure resource types that need to be monitored.
* `include_tags` - (Optional) A list of resource tags associated with the resources that need to be monitored, in a "key:value" format. If this is not specified, all resources will be monitored.
* `exclude_tags` - (Optional) A list of resource tags associated with the resources that need to be excluded from monitoring.
* `enabled` - (Optional) A boolean value, that specifies if the integration needs to be active. Defaults to 'true' if not specified.

## Attributes Reference

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