Skip to content

Commit 6296b7d

Browse files
feat(newrelic_cloud_azure_integrations): addition of the integration 'azureMonitor'
1 parent dc93cbd commit 6296b7d

6 files changed

+197
-5
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/mitchellh/go-homedir v1.1.0
88
github.com/newrelic/go-agent/v3 v3.20.3
99
github.com/newrelic/go-insights v1.0.3
10-
github.com/newrelic/newrelic-client-go/v2 v2.18.1
10+
github.com/newrelic/newrelic-client-go/v2 v2.19.0
1111
github.com/stretchr/testify v1.8.2
1212
)
1313

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ github.com/newrelic/go-agent/v3 v3.20.3 h1:hUBAMq/Y2Y9as5/yxQbf0zNde/X7w58cWZkm2
273273
github.com/newrelic/go-agent/v3 v3.20.3/go.mod h1:rT6ZUxJc5rQbWLyCtjqQCOcfb01lKRFbc1yMQkcboWM=
274274
github.com/newrelic/go-insights v1.0.3 h1:zSNp1CEZnXktzSIEsbHJk8v6ZihdPFP2WsO/fzau3OQ=
275275
github.com/newrelic/go-insights v1.0.3/go.mod h1:A20BoT8TNkqPGX2nS/Z2fYmKl3Cqa3iKZd4whzedCY4=
276-
github.com/newrelic/newrelic-client-go/v2 v2.18.1 h1:7VRW32f+z+QCiz7VL5h5Dmo7gYoEMHBobkXNskyCCYE=
277-
github.com/newrelic/newrelic-client-go/v2 v2.18.1/go.mod h1:AX08IIL08pYVbnowsR05EqOdfN1Dz+ZXdIwqS0dkT2c=
276+
github.com/newrelic/newrelic-client-go/v2 v2.19.0 h1:iYF4fxotAPsl+/n1B/tbLqprBmU9HOrKeIiau94zAwQ=
277+
github.com/newrelic/newrelic-client-go/v2 v2.19.0/go.mod h1:AX08IIL08pYVbnowsR05EqOdfN1Dz+ZXdIwqS0dkT2c=
278278
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
279279
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
280280
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=

newrelic/resource_newrelic_cloud_aws_govcloud_link_account.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func resourceNewRelicAwsGovCloudLinkAccountCreate(ctx context.Context, d *schema
8888

8989
// Extracting the AWSGovCloud account credentials from Schema using expandAzureCloudLinkAccountInput
9090
func expandAwsGovCloudLinkAccountInput(d *schema.ResourceData) cloud.CloudLinkCloudAccountsInput {
91-
awsGovCloud := cloud.CloudAwsGovcloudLinkAccountInput{}
91+
awsGovCloud := cloud.CloudAwsGovCloudLinkAccountInput{}
9292
if accessKeyID, ok := d.GetOk("access_key_id"); ok {
9393
awsGovCloud.AccessKeyId = accessKeyID.(string)
9494
}
@@ -105,7 +105,7 @@ func expandAwsGovCloudLinkAccountInput(d *schema.ResourceData) cloud.CloudLinkCl
105105
awsGovCloud.SecretAccessKey = secretKeyID.(cloud.SecureValue)
106106
}
107107
input := cloud.CloudLinkCloudAccountsInput{
108-
AwsGovcloud: []cloud.CloudAwsGovcloudLinkAccountInput{awsGovCloud},
108+
AwsGovcloud: []cloud.CloudAwsGovCloudLinkAccountInput{awsGovCloud},
109109
}
110110
return input
111111
}

newrelic/resource_newrelic_cloud_azure_integrations.go

+158
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ func resourceNewRelicCloudAzureIntegrations() *schema.Resource {
153153
Elem: cloudAzureIntegrationMariadbElem(),
154154
MaxItems: 1,
155155
},
156+
"monitor": {
157+
Type: schema.TypeList,
158+
Optional: true,
159+
Description: "The Azure Monitor",
160+
Elem: cloudAzureIntegrationMonitorElem(),
161+
MaxItems: 1,
162+
},
156163
"mysql": {
157164
Type: schema.TypeList,
158165
Optional: true,
@@ -571,6 +578,61 @@ func cloudAzureIntegrationMysqlElem() *schema.Resource {
571578

572579
}
573580

581+
// cloudAzureIntegrationMonitorElem defines the schema of elements in the "monitor" Azure integration.
582+
func cloudAzureIntegrationMonitorElem() *schema.Resource {
583+
s := mergeSchemas(
584+
cloudAzureIntegrationSchemaBase(),
585+
cloudAzureIntegrationMonitorSchema())
586+
587+
return &schema.Resource{
588+
Schema: s,
589+
}
590+
}
591+
592+
// cloudAzureIntegrationMonitorSchema defines the schema of elements specific to the "monitor" Azure integration.
593+
func cloudAzureIntegrationMonitorSchema() map[string]*schema.Schema {
594+
return map[string]*schema.Schema{
595+
"enabled": {
596+
Type: schema.TypeBool,
597+
Optional: true,
598+
Default: true,
599+
Description: "A flag that specifies if the integration is active",
600+
},
601+
"exclude_tags": {
602+
Type: schema.TypeList,
603+
Optional: true,
604+
Description: "Specify resource tags in 'key:value' form to be excluded from monitoring",
605+
Elem: &schema.Schema{
606+
Type: schema.TypeString,
607+
},
608+
},
609+
"include_tags": {
610+
Type: schema.TypeList,
611+
Optional: true,
612+
Description: "Specify resource tags in 'key:value' form to be monitored",
613+
Elem: &schema.Schema{
614+
Type: schema.TypeString,
615+
},
616+
},
617+
"resource_types": {
618+
Type: schema.TypeList,
619+
Optional: true,
620+
Description: "Specify each Azure resource type that needs to be monitored",
621+
Elem: &schema.Schema{
622+
Type: schema.TypeString,
623+
},
624+
},
625+
"resource_groups": {
626+
Type: schema.TypeList,
627+
Optional: true,
628+
Description: "Specify each Resource group associated with the resources that you want to monitor. Filter values are case-sensitive",
629+
Elem: &schema.Schema{
630+
Type: schema.TypeString,
631+
},
632+
},
633+
}
634+
}
635+
574636
// function to add schema for azure mysql
575637
func cloudAzureIntegrationMysqlFlexElem() *schema.Resource {
576638
s := cloudAzureIntegrationSchemaBase()
@@ -940,6 +1002,12 @@ func expandCloudAzureIntegrationsInput(d *schema.ResourceData) (cloud.CloudInteg
9401002
cloudDisableAzureIntegration.AzureMariadb = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
9411003
}
9421004

1005+
if v, ok := d.GetOk("monitor"); ok {
1006+
cloudAzureIntegration.AzureMonitor = expandCloudAzureIntegrationMonitorInput(v.([]interface{}), linkedAccountID)
1007+
} else if o, n := d.GetChange("monitor"); len(n.([]interface{})) < len(o.([]interface{})) {
1008+
cloudDisableAzureIntegration.AzureMonitor = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
1009+
}
1010+
9431011
if v, ok := d.GetOk("mysql"); ok {
9441012
cloudAzureIntegration.AzureMysql = expandCloudAzureIntegrationMysqlInput(v.([]interface{}), linkedAccountID)
9451013
} else if o, n := d.GetChange("mysql"); len(n.([]interface{})) < len(o.([]interface{})) {
@@ -1649,6 +1717,73 @@ func expandCloudAzureIntegrationMariadbInput(b []interface{}, linkedAccountID in
16491717
return expanded
16501718
}
16511719

1720+
// Expanding the input for the azureMonitor integration
1721+
func expandCloudAzureIntegrationMonitorInput(b []interface{}, linkedAccountID int) []cloud.CloudAzureMonitorIntegrationInput {
1722+
expanded := make([]cloud.CloudAzureMonitorIntegrationInput, len(b))
1723+
1724+
for i, azureMonitor := range b {
1725+
var azureMonitorInput cloud.CloudAzureMonitorIntegrationInput
1726+
1727+
if azureMonitor == nil {
1728+
azureMonitorInput.LinkedAccountId = linkedAccountID
1729+
expanded[i] = azureMonitorInput
1730+
return expanded
1731+
}
1732+
1733+
in := azureMonitor.(map[string]interface{})
1734+
1735+
azureMonitorInput.LinkedAccountId = linkedAccountID
1736+
1737+
if m, ok := in["metrics_polling_interval"]; ok {
1738+
azureMonitorInput.MetricsPollingInterval = m.(int)
1739+
}
1740+
if r, ok := in["resource_groups"]; ok {
1741+
resourceGroups := r.([]interface{})
1742+
var groups []string
1743+
1744+
for _, group := range resourceGroups {
1745+
groups = append(groups, group.(string))
1746+
}
1747+
azureMonitorInput.ResourceGroups = groups
1748+
}
1749+
if rt, ok := in["resource_types"]; ok {
1750+
resourceTypes := rt.([]interface{})
1751+
var rTypes []string
1752+
1753+
for _, rType := range resourceTypes {
1754+
rTypes = append(rTypes, rType.(string))
1755+
}
1756+
azureMonitorInput.ResourceTypes = rTypes
1757+
}
1758+
if et, ok := in["exclude_tags"]; ok {
1759+
excludeTags := et.([]interface{})
1760+
var eTags []string
1761+
1762+
for _, eTag := range excludeTags {
1763+
eTags = append(eTags, eTag.(string))
1764+
}
1765+
azureMonitorInput.ExcludeTags = eTags
1766+
}
1767+
1768+
if it, ok := in["include_tags"]; ok {
1769+
includeTags := it.([]interface{})
1770+
var iTags []string
1771+
1772+
for _, iTag := range includeTags {
1773+
iTags = append(iTags, iTag.(string))
1774+
}
1775+
azureMonitorInput.IncludeTags = iTags
1776+
}
1777+
1778+
if enabled, ok := in["enabled"]; ok {
1779+
azureMonitorInput.Enabled = enabled.(bool)
1780+
}
1781+
expanded[i] = azureMonitorInput
1782+
}
1783+
1784+
return expanded
1785+
}
1786+
16521787
// Expanding the Azure_mysql
16531788

16541789
func expandCloudAzureIntegrationMysqlInput(b []interface{}, linkedAccountID int) []cloud.CloudAzureMysqlIntegrationInput {
@@ -2220,6 +2355,8 @@ func flattenCloudAzureLinkedAccount(d *schema.ResourceData, result *cloud.CloudL
22202355
_ = d.Set("machine_learning", flattenCloudAzureMachineLearningIntegration(t))
22212356
case *cloud.CloudAzureMariadbIntegration:
22222357
_ = d.Set("maria_db", flattenCloudAzureMariadbIntegration(t))
2358+
case *cloud.CloudAzureMonitorIntegration:
2359+
_ = d.Set("monitor", flattenCloudAzureMonitorIntegration(t))
22232360
case *cloud.CloudAzureMysqlIntegration:
22242361
_ = d.Set("mysql", flattenCloudAzureMysqlIntegration(t))
22252362
case *cloud.CloudAzureMysqlflexibleIntegration:
@@ -2508,6 +2645,24 @@ func flattenCloudAzureMariadbIntegration(in *cloud.CloudAzureMariadbIntegration)
25082645
return flattened
25092646
}
25102647

2648+
// Flatten values for the azureMonitor integration
2649+
func flattenCloudAzureMonitorIntegration(in *cloud.CloudAzureMonitorIntegration) []interface{} {
2650+
flattened := make([]interface{}, 1)
2651+
2652+
out := make(map[string]interface{})
2653+
2654+
out["metrics_polling_interval"] = in.MetricsPollingInterval
2655+
out["resource_groups"] = in.ResourceGroups
2656+
out["exclude_tags"] = in.ExcludeTags
2657+
out["include_tags"] = in.IncludeTags
2658+
out["resource_types"] = in.ResourceTypes
2659+
out["enabled"] = in.Enabled
2660+
2661+
flattened[0] = out
2662+
2663+
return flattened
2664+
}
2665+
25112666
// flatten for azure_mysql
25122667

25132668
func flattenCloudAzureMysqlIntegration(in *cloud.CloudAzureMysqlIntegration) []interface{} {
@@ -2843,6 +2998,9 @@ func expandCloudAzureDisableInputs(d *schema.ResourceData) cloud.CloudDisableInt
28432998
if _, ok := d.GetOk("maria_db"); ok {
28442999
cloudAzureDisableInput.AzureMariadb = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
28453000
}
3001+
if _, ok := d.GetOk("monitor"); ok {
3002+
cloudAzureDisableInput.AzureMonitor = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
3003+
}
28463004
if _, ok := d.GetOk("mysql"); ok {
28473005
cloudAzureDisableInput.AzureMysql = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
28483006
}

newrelic/resource_newrelic_cloud_azure_integrations_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ resource "newrelic_cloud_azure_integrations" "bar" {
222222
resource_groups = ["beyond"]
223223
}
224224
225+
monitor {
226+
metrics_polling_interval = 3600
227+
resource_groups = ["beyond"]
228+
include_tags = ["env:testing", "env:production"]
229+
exclude_tags = ["env:staging"]
230+
enabled = true
231+
resource_types = ["microsoft.datashare/accounts"]
232+
}
233+
225234
mysql {
226235
metrics_polling_interval = 3600
227236
resource_groups = ["beyond"]
@@ -386,6 +395,15 @@ resource "newrelic_cloud_azure_integrations" "bar" {
386395
resource_groups = ["beyond"]
387396
}
388397
398+
monitor {
399+
metrics_polling_interval = 3600
400+
resource_groups = ["beyond"]
401+
include_tags = ["env:production"]
402+
exclude_tags = ["env:staging"]
403+
enabled = true
404+
resource_types = ["microsoft.datashare/accounts", "microsoft.eventhub/clusters"]
405+
}
406+
389407
mysql {
390408
metrics_polling_interval = 3600
391409
resource_groups = ["beyond"]

website/docs/r/cloud_azure_integrations.html.markdown

+16
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,15 @@ resource "newrelic_cloud_azure_integrations" "foo" {
122122
resource_groups = ["resource_groups"]
123123
}
124124
125+
monitor {
126+
metrics_polling_interval = 1200
127+
resource_groups = ["resource_groups"]
128+
include_tags = ["env:production"]
129+
exclude_tags = ["env:staging", "env:testing"]
130+
enabled = true
131+
resource_types = ["microsoft.datashare/accounts"]
132+
}
133+
125134
mysql {
126135
metrics_polling_interval = 1200
127136
resource_groups = ["resource_groups"]
@@ -215,6 +224,7 @@ The following arguments are supported with minimum metric polling interval of 30
215224
* `logic_apps` - (Optional) Azure Logic Apps. See [Integration blocks](#integration-blocks) below for details.
216225
* `machine_learning` - (Optional) Azure Machine Learning. See [Integration blocks](#integration-blocks) below for details.
217226
* `maria_db` - (Optional) Azure MariaDB. See [Integration blocks](#integration-blocks) below for details.
227+
* `monitor` - (Optional) Azure Monitor. See [Integration blocks](#integration-blocks) below for details.
218228
* `mysql` - (Optional) Azure MySQL. See [Integration blocks](#integration-blocks) below for details.
219229
* `mysql_flexible` - (Optional) Azure MySQL Flexible Server. See [Integration blocks](#integration-blocks) below for details.
220230
* `postgresql` - (Optional) Azure PostgreSQL. See [Integration blocks](#integration-blocks) below for details.
@@ -249,6 +259,12 @@ Other integration type support an additional argument:
249259
* `cost_management`
250260
* `tag_keys` - (Optional) Specify a Tag key associated with the resources that you want to monitor. Filter values are case-sensitive.
251261

262+
* `monitor`
263+
* `resource_types` - (Optional) A list of Azure resource types that need to be monitored.
264+
* `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.
265+
* `exclude_tags` - (Optional) A list of resource tags associated with the resources that need to be excluded from monitoring.
266+
* `enabled` - (Optional) A boolean value, that specifies if the integration needs to be active. Defaults to 'true' if not specified.
267+
252268
## Attributes Reference
253269

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

0 commit comments

Comments
 (0)