Skip to content

Commit 6394d8c

Browse files
feat(cloud): added AWS AutoDiscovery Slug for configure-integration API (#2898)
Co-authored-by: pchawla-NR <[email protected]>
1 parent 3972ca2 commit 6394d8c

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

examples/modules/cloud-integrations/aws/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ resource "newrelic_cloud_aws_integrations" "newrelic_cloud_integration_pull" {
262262
aws_transit_gateway {}
263263
aws_waf {}
264264
aws_wafv2 {}
265+
aws_auto_discovery {}
265266
cloudfront {}
266267
dynamodb {}
267268
ec2 {}

newrelic/resource_newrelic_cloud_aws_integrations.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,13 @@ func resourceNewRelicCloudAwsIntegrations() *schema.Resource {
262262
Elem: cloudAwsIntegrationCommonSchemaElem(),
263263
MaxItems: 1,
264264
},
265+
"aws_auto_discovery": {
266+
Type: schema.TypeList,
267+
Optional: true,
268+
Description: "Aws Auto Discovery Integration",
269+
Elem: cloudAwsIntegrationCommonSchemaElem(),
270+
MaxItems: 1,
271+
},
265272
"cloudfront": {
266273
Type: schema.TypeList,
267274
Optional: true,

newrelic/resource_newrelic_cloud_aws_integrations_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ func testAccNewRelicAwsIntegrationsConfigUpdated(AWSIntegrationsTestConfig map[s
710710
fetch_extended_inventory = true
711711
metrics_polling_interval = 6000
712712
}
713+
aws_auto_discovery {
714+
aws_regions = ["us-east-1"]
715+
metrics_polling_interval = 6000
716+
}
713717
}
714718
`)
715719
}

newrelic/structures_newrelic_cloud_aws_integrations.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,14 @@ func expandCloudAwsIntegrationsInput(d *schema.ResourceData) (cloud.CloudIntegra
281281
cloudDisableAwsIntegration.AwsWafv2 = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: id}}
282282
},
283283
},
284+
"aws_auto_discovery": {
285+
enableFunc: func(a []interface{}, id int) {
286+
cloudAwsIntegration.AwsAutoDiscovery = expandCloudAwsIntegrationAutoDiscoveryInput(a, id)
287+
},
288+
disableFunc: func(id int) {
289+
cloudDisableAwsIntegration.AwsAutoDiscovery = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: id}}
290+
},
291+
},
284292
"cloudfront": {
285293
enableFunc: func(a []interface{}, id int) {
286294
cloudAwsIntegration.Cloudfront = expandCloudAwsIntegrationCloudfrontInput(a, id)
@@ -529,6 +537,8 @@ func flattenCloudAwsLinkedAccount(d *schema.ResourceData, linkedAccount *cloud.C
529537
_ = d.Set("aws_waf", flattenCloudAwsWafIntegration(t))
530538
case *cloud.CloudAwsWafv2Integration:
531539
_ = d.Set("aws_wafv2", flattenCloudAwsWafv2Integration(t))
540+
case *cloud.CloudAwsAutoDiscoveryIntegration:
541+
_ = d.Set("aws_auto_discovery", flattenCloudAwsAutoDiscoveryIntegration(t))
532542
case *cloud.CloudCloudfrontIntegration:
533543
_ = d.Set("cloudfront", flattenCloudCloudfrontIntegration(t))
534544
case *cloud.CloudDynamodbIntegration:
@@ -715,6 +725,10 @@ func buildDeleteInput(d *schema.ResourceData) cloud.CloudDisableIntegrationsInpu
715725
cloudDisableAwsIntegration.AwsWafv2 = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
716726
}
717727

728+
if _, ok := d.GetOk("aws_auto_discovery"); ok {
729+
cloudDisableAwsIntegration.AwsAutoDiscovery = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
730+
}
731+
718732
if _, ok := d.GetOk("cloudfront"); ok {
719733
cloudDisableAwsIntegration.Cloudfront = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
720734
}
@@ -2990,6 +3004,43 @@ func expandCloudAwsIntegrationSnsInput(b []interface{}, linkedAccountID int) []c
29903004
return expanded
29913005
}
29923006

3007+
// Expanding the Aws Auto Discovery input
3008+
3009+
func expandCloudAwsIntegrationAutoDiscoveryInput(b []interface{}, linkedAccountID int) []cloud.CloudAwsAutoDiscoveryIntegrationInput {
3010+
expanded := make([]cloud.CloudAwsAutoDiscoveryIntegrationInput, len(b))
3011+
3012+
for i, iot := range b {
3013+
var autoDiscoveryInput cloud.CloudAwsAutoDiscoveryIntegrationInput
3014+
3015+
if iot == nil {
3016+
autoDiscoveryInput.LinkedAccountId = linkedAccountID
3017+
expanded[i] = autoDiscoveryInput
3018+
return expanded
3019+
}
3020+
3021+
in := iot.(map[string]interface{})
3022+
3023+
autoDiscoveryInput.LinkedAccountId = linkedAccountID
3024+
3025+
if a, ok := in["aws_regions"]; ok {
3026+
awsRegions := a.([]interface{})
3027+
var regions []string
3028+
3029+
for _, region := range awsRegions {
3030+
regions = append(regions, region.(string))
3031+
}
3032+
autoDiscoveryInput.AwsRegions = regions
3033+
}
3034+
3035+
if m, ok := in["metrics_polling_interval"]; ok {
3036+
autoDiscoveryInput.MetricsPollingInterval = m.(int)
3037+
}
3038+
expanded[i] = autoDiscoveryInput
3039+
}
3040+
3041+
return expanded
3042+
}
3043+
29933044
// flatten for Billing integration
29943045

29953046
func flattenCloudAwsBillingIntegration(in *cloud.CloudBillingIntegration) []interface{} {
@@ -3830,3 +3881,17 @@ func flattenCloudSnsIntegration(in *cloud.CloudSnsIntegration) []interface{} {
38303881

38313882
return flattened
38323883
}
3884+
3885+
// flatten for Auto Discovery integration
3886+
func flattenCloudAwsAutoDiscoveryIntegration(in *cloud.CloudAwsAutoDiscoveryIntegration) []interface{} {
3887+
flattened := make([]interface{}, 1)
3888+
3889+
out := make(map[string]interface{})
3890+
3891+
out["aws_regions"] = in.AwsRegions
3892+
out["metrics_polling_interval"] = in.MetricsPollingInterval
3893+
3894+
flattened[0] = out
3895+
3896+
return flattened
3897+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
layout: "newrelic"
3+
page_title: "New Relic Integration with AWS AutoDiscovery"
4+
sidebar_current: "docs-newrelic-provider-aws-auto-discovery-integration-guide"
5+
description: |-
6+
Use this guide to set up the New Relic AWS Auto Discovery fully automated through Terraform.
7+
---
8+
9+
# NewRelic Integration with AWS AutoDiscovery
10+
The below guide provides reference on how to integrate with AWS Auto-Discovery via terraform.
11+
12+
## Documentation Reference
13+
* [AWS Auto Discovery](https://docs.newrelic.com/docs/infrastructure/amazon-integrations/connect/set-up-auto-discovery-of-aws-entities/)
14+
15+
## Pre-Requisites
16+
The below integration process presumes that the client has already integrated with either of the New Relic's integration for monitoring their cloud-infrastructure on AWS, which is either of API Polling or Cloudwatch Metrics Streams integration.
17+
18+
## Variables -
19+
* **New Relic Region** ```new_relic_region``` - The region where your New Relic account is hosted
20+
* **Type** - String
21+
* **Allowed Values** - US or EU
22+
23+
* **New Relic Account Id** ```new_relic_account_id``` - The account id associated with your organisation's New Relic Account.
24+
* **Type** - Integer
25+
* **Example** - 1234567
26+
27+
* **AWS IAM Role Name** ```aws_iam_role_name``` - The IAM role-name that has been used to integrate cloud monitoring with New Relic.
28+
* **Type** - String
29+
* **Example** - "NewRelicInfrastructureIntegrationRole"
30+
31+
* **AWS Account Id** ```aws_account_id``` - The AWS Account Id which has been integrated with New Relic on which Auto-Discovery has to be enabled.
32+
* **Type** - Integer
33+
* **Example** - 123456789012
34+
35+
* **Metric Polling Interval** ```metric_polling_interval``` - The interval at which the auto-discovery scans are to be triggered on the integrated AWS account in seconds
36+
* **Type** - Integer
37+
* **Allowed Values** - 28800, 43200, 86400
38+
39+
* **aws_regions** ```aws_regions``` - The list of regions at which the auto-discovery scans are to be triggered on the integrated AWS account.
40+
* **Type** - StringList
41+
* **Allowed Values** - ["af-south-1", "ap-east-1", "ap-northeast-1", "ap-northeast-2", "ap-northeast-3", "ap-south-1", "ap-southeast-1", "ap-southeast-2", "ca-central-1", "eu-north-1", "eu-south-1", "eu-west-1", "eu-west-2", "eu-west-3", "me-south-1", "sa-east-1",
42+
"us-east-1" "us-east-2", "us-west-1", "us-west-2"]
43+
44+
## Integrating with AWS Auto-Discovery via Terraform
45+
```
46+
provider "newrelic" {
47+
region = var.new_relic_region
48+
account_id = var.newrelic_account_id
49+
}
50+
51+
resource "aws_iam_policy" "newrelic_aws_autodiscovery_permissions" {
52+
name = "NewRelicAwsAutoDiscoveryPermissions"
53+
description = "IAM Policy for Auto-Discovery Permissions"
54+
policy = << EOF
55+
{
56+
"Version": "2012-10-17",
57+
"Statement": [
58+
{
59+
"Action": [
60+
"cloudformation:StartResourceScan"
61+
],
62+
"Effect": "Allow",
63+
"Resource": "*"
64+
}
65+
]
66+
}
67+
EOF
68+
}
69+
70+
resource "aws_iam_role_policy_attachment" "newrelic_aws_policy_attach" {
71+
role = "var.aws_iam_role_name"
72+
policy_arn = aws_iam_policy.newrelic_aws_autodiscovery_permissions.arn
73+
}
74+
75+
resource "newrelic_cloud_aws_integrations" "auto_discovery_integrations" {
76+
linked_account_id = var.aws_account_id
77+
aws_auto_discovery = {
78+
metric_polling_interval = var.metric_polling_interval
79+
aws_regions = var.aws_regions
80+
}
81+
}
82+
```
83+
84+

0 commit comments

Comments
 (0)