Skip to content

Commit 8d69824

Browse files
feat(aws_govcloud): revamp of the resource to support ARN based authentication (#2809)
feat(aws_govcloud): revamp of the resource to support ARN based authentication (#2809)
1 parent 992f460 commit 8d69824

3 files changed

+93
-60
lines changed

newrelic/resource_newrelic_cloud_aws_govcloud_link_account.go

+33-17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1011
"github.com/newrelic/newrelic-client-go/v2/pkg/cloud"
1112
)
1213

@@ -25,37 +26,52 @@ func resourceNewRelicAwsGovCloudLinkAccount() *schema.Resource {
2526
Optional: true,
2627
Computed: true,
2728
Description: "The ID of the account in New Relic.",
29+
// since the mutation to update cloud linked accounts does not support "changing" the account ID of a linked account,
30+
// we shall force re-creation of the resource if the account_id is changed after the first apply.
31+
ForceNew: true,
2832
},
2933
"name": {
3034
Type: schema.TypeString,
3135
Description: "Name of the AWS GovCloud 'Linked Account' to identify in New Relic.",
3236
Required: true,
3337
},
3438
"metric_collection_mode": {
35-
Type: schema.TypeString,
36-
Description: "The mode by which metric data is to be collected from the linked AWS GovCloud account. Use 'PUSH' for Metric Streams and 'PULL' for API Polling based metric collection respectively.",
37-
Optional: true,
39+
Type: schema.TypeString,
40+
Description: "The mode by which metric data is to be collected from the linked AWS GovCloud account. Use 'PUSH' for Metric Streams and 'PULL' for API Polling based metric collection respectively.",
41+
Optional: true,
42+
ValidateFunc: validation.StringInSlice([]string{"PULL", "PUSH"}, false),
43+
Default: "PULL",
3844
// since the mutation to update cloud linked accounts does not support updating metric collection mode,
3945
// we shall force re-creation of the resource if the metric_collection_mode is changed after the first apply.
4046
ForceNew: true,
4147
},
42-
"aws_account_id": {
43-
Type: schema.TypeString,
44-
Description: "The ID of the AWS GovCloud account.",
45-
Required: true,
46-
},
47-
"access_key_id": {
48+
"arn": {
4849
Type: schema.TypeString,
49-
Description: "The Access Key used to programmatically access the AWS GovCloud account.",
50+
Description: "The ARN of the identifying AWS GovCloud account.",
5051
Required: true,
51-
Sensitive: true,
52-
},
53-
"secret_access_key": {
54-
Type: schema.TypeString,
55-
Description: "The Secret Access Key used to programmatically access the AWS GovCloud account.",
56-
Required: true,
57-
Sensitive: true,
5852
},
53+
54+
// NOTE: The following arguments are no longer supported, as the establishment of a connection
55+
// with New Relic from AWS GovCloud is no longer supported with these credentials (an ARN is needed
56+
// to facilitate a working connection.
57+
58+
//"aws_account_id": {
59+
// Type: schema.TypeString,
60+
// Description: "The ID of the AWS GovCloud account.",
61+
// Required: true,
62+
//},
63+
//"access_key_id": {
64+
// Type: schema.TypeString,
65+
// Description: "The Access Key used to programmatically access the AWS GovCloud account.",
66+
// Required: true,
67+
// Sensitive: true,
68+
//},
69+
//"secret_access_key": {
70+
// Type: schema.TypeString,
71+
// Description: "The Secret Access Key used to programmatically access the AWS GovCloud account.",
72+
// Required: true,
73+
// Sensitive: true,
74+
//},
5975
},
6076
}
6177
}

newrelic/structures_newrelic_cloud_aws_govcloud_link_account.go

+50-27
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,84 @@ import (
1010
)
1111

1212
func expandAwsGovCloudLinkAccountInputForCreate(d *schema.ResourceData) cloud.CloudLinkCloudAccountsInput {
13-
awsGovCloud := cloud.CloudAwsGovCloudLinkAccountInput{}
14-
if accessKeyID, ok := d.GetOk("access_key_id"); ok {
15-
awsGovCloud.AccessKeyId = accessKeyID.(string)
16-
}
17-
if awsAccountID, ok := d.GetOk("aws_account_id"); ok {
18-
awsGovCloud.AwsAccountId = awsAccountID.(string)
13+
// NOTE: The AwsGovCloudLinkAccountInput datatype is no longer supported to facilitate linking an AWS GovCloud
14+
// account to New Relic; AwsLinkAccountInput is intended to be used instead, since a link for AWS/AWS GovCloud
15+
// both can now be facilitated via the "aws" field in the CloudLinkCloudAccountsInput datatype, with the same
16+
// authentication mechanism, i.e. an ARN.
17+
18+
awsGovCloud := cloud.CloudAwsLinkAccountInput{}
19+
20+
// NOTE: The following arguments are no longer supported, as the establishment of a connection
21+
// with New Relic from AWS GovCloud is no longer supported with these credentials (an ARN is needed
22+
// to facilitate a working connection.
23+
24+
//if accessKeyID, ok := d.GetOk("access_key_id"); ok {
25+
// awsGovCloud.AccessKeyId = accessKeyID.(string)
26+
//}
27+
//if awsAccountID, ok := d.GetOk("aws_account_id"); ok {
28+
// awsGovCloud.AwsAccountId = awsAccountID.(string)
29+
//}
30+
//if secretKeyID, ok := d.GetOk("secret_access_key"); ok {
31+
// awsGovCloud.SecretAccessKey = cloud.SecureValue(secretKeyID.(string))
32+
//}
33+
34+
if name, ok := d.GetOk("name"); ok {
35+
awsGovCloud.Name = name.(string)
1936
}
2037
if m, ok := d.GetOk("metric_collection_mode"); ok {
2138
awsGovCloud.MetricCollectionMode = cloud.CloudMetricCollectionMode(strings.ToUpper(m.(string)))
2239
}
23-
if name, ok := d.GetOk("name"); ok {
24-
awsGovCloud.Name = name.(string)
25-
}
26-
if secretKeyID, ok := d.GetOk("secret_access_key"); ok {
27-
awsGovCloud.SecretAccessKey = cloud.SecureValue(secretKeyID.(string))
40+
if arn, ok := d.GetOk("arn"); ok {
41+
awsGovCloud.Arn = arn.(string)
2842
}
2943

3044
createAwsGovCloudLinkAccountInput := cloud.CloudLinkCloudAccountsInput{
31-
AwsGovcloud: []cloud.CloudAwsGovCloudLinkAccountInput{awsGovCloud},
45+
Aws: []cloud.CloudAwsLinkAccountInput{awsGovCloud},
3246
}
3347

3448
return createAwsGovCloudLinkAccountInput
3549
}
3650

3751
func expandAwsGovCloudLinkAccountInputForRead(d *schema.ResourceData, result *cloud.CloudLinkedAccount) {
38-
_ = d.Set("metric_collection_mode", result.MetricCollectionMode)
39-
_ = d.Set("name", result.Name)
40-
_ = d.Set("aws_account_id", result.ExternalId)
4152
_ = d.Set("account_id", result.NrAccountId)
53+
_ = d.Set("name", result.Name)
54+
_ = d.Set("metric_collection_mode", result.MetricCollectionMode)
55+
_ = d.Set("arn", result.AuthLabel)
4256
}
4357

4458
func expandAwsGovCloudLinkAccountInputForUpdate(d *schema.ResourceData, linkedAccountID int) cloud.CloudUpdateCloudAccountsInput {
45-
awsGovCloud := cloud.CloudAwsGovCloudUpdateAccountInput{}
59+
awsGovCloud := cloud.CloudAwsUpdateAccountInput{}
4660
awsGovCloud.LinkedAccountId = linkedAccountID
47-
if accessKeyID, ok := d.GetOk("access_key_id"); ok {
48-
awsGovCloud.AccessKeyId = accessKeyID.(string)
49-
}
50-
if awsAccountID, ok := d.GetOk("aws_account_id"); ok {
51-
awsGovCloud.AwsAccountId = awsAccountID.(string)
61+
62+
// NOTE: The following arguments are no longer supported; see `expandAwsGovCloudLinkAccountInputForCreate` to know why
63+
64+
//if accessKeyID, ok := d.GetOk("access_key_id"); ok {
65+
// awsGovCloud.AccessKeyId = accessKeyID.(string)
66+
//}
67+
//if awsAccountID, ok := d.GetOk("aws_account_id"); ok {
68+
// awsGovCloud.AwsAccountId = awsAccountID.(string)
69+
//}
70+
//if secretKeyID, ok := d.GetOk("secret_access_key"); ok {
71+
// awsGovCloud.SecretAccessKey = cloud.SecureValue(secretKeyID.(string))
72+
//}
73+
74+
if name, ok := d.GetOk("name"); ok {
75+
awsGovCloud.Name = name.(string)
5276
}
5377

5478
// The update mutation does not support updating the metric collection mode
79+
// This is also why a 'ForceNew' constraint has been applied on this argument in the schema
80+
5581
//if m, ok := d.GetOk("metric_collection_mode"); ok {
5682
// awsGovCloud.MetricCollectionMode = cloud.CloudMetricCollectionMode(strings.ToUpper(m.(string)))
5783
//}
5884

59-
if name, ok := d.GetOk("name"); ok {
60-
awsGovCloud.Name = name.(string)
61-
}
62-
if secretKeyID, ok := d.GetOk("secret_access_key"); ok {
63-
awsGovCloud.SecretAccessKey = cloud.SecureValue(secretKeyID.(string))
85+
if arn, ok := d.GetOk("arn"); ok {
86+
awsGovCloud.Arn = arn.(string)
6487
}
6588

6689
updateAwsGovCloudLinkAccountInput := cloud.CloudUpdateCloudAccountsInput{
67-
AwsGovcloud: []cloud.CloudAwsGovCloudUpdateAccountInput{awsGovCloud},
90+
Aws: []cloud.CloudAwsUpdateAccountInput{awsGovCloud},
6891
}
6992

7093
return updateAwsGovCloudLinkAccountInput

website/docs/r/cloud_aws_govcloud_link_account.html.markdown

+10-16
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ sidebar_current: "docs-newrelic-cloud-resource-aws-govcloud-link-account"
55
description: |-
66
Link an AWS GovCloud account to New Relic.
77
---
8-
-> **IMPORTANT!** This resource is in alpha state, and could still contain issues and missing functionality. If you encounter any issue please create a ticket on [Github](https://github.com/newrelic/terraform-provider-newrelic/issues/new/choose) with all the required information.
9-
108
# Resource: newrelic_cloud_aws_govcloud_link_account
119

1210
Use this resource to link an AWS GovCloud account to New Relic.
1311

1412
## Prerequisite
1513

16-
Obtain the AwsGovCloud account designed to address the specific regulatory needs of United States (federal, state, and local agencies), education institutions, and the supporting ecosystem.
17-
18-
It is an isolated AWS region designed to host sensitive data and regulated workloads in the cloud, helping customers support their US government compliance requirements.
14+
To link an AWS GovCloud account to New Relic, you need an AWS GovCloud account. AWS GovCloud is designed to address the specific regulatory needs of United States federal, state, and local agencies, educational institutions, and their supporting ecosystem. It is an isolated AWS region designed to host sensitive data and regulated workloads in the cloud, helping customers support their US government compliance requirements.
1915

20-
To pull data from AWSGovCloud, complete the [steps outlined here](https://docs.newrelic.com/docs/infrastructure/amazon-integrations/get-started/connect-aws-govcloud-new-relic).
16+
To pull data from AWS GovCloud, follow the [steps outlined here](https://docs.newrelic.com/docs/infrastructure/amazon-integrations/get-started/connect-aws-govcloud-new-relic).
2117

2218
## Example Usage
2319

@@ -26,23 +22,21 @@ resource "newrelic_cloud_aws_govcloud_link_account" "foo" {
2622
account_id = 1234567
2723
name = "My New Relic - AWS GovCloud Linked Account"
2824
metric_collection_mode = "PUSH"
29-
aws_account_id = "<Your AWS GovCloud Account's ID>"
30-
access_key_id = "<Your AWS GovCloud Account's Access Key ID>"
31-
secret_access_key = "<Your AWS GovCloud Account's Secret Access Key>"
25+
arn = "arn:aws:service:region:account-id:resource-id"
3226
}
3327
```
3428

3529
## Argument Reference
3630

3731
The following arguments are supported:
3832

39-
- `account_id` - (Optional) The New Relic account ID to operate on. This allows the user to override the `account_id` attribute set on the provider. Defaults to the environment variable `NEW_RELIC_ACCOUNT_ID`.
40-
- `name` - (Required) - The name/identifier of the AWS GovCloud - New Relic 'linked' account.
41-
- `metric_collection_mode` - (Optional) The mode by which metric data is to be collected from the linked AWS GovCloud account. Use `PUSH` for Metric Streams and `PULL` for API Polling based metric collection respectively.
42-
- Note: Altering the `metric_collection_mode` of an already applied `newrelic_cloud_aws_govcloud_link_account` resource shall trigger a recreation of the resource, instead of an update.
43-
- `aws_account_id` - (Required) The ID of the AWS GovCloud account.
44-
- `access_key_id` - (Required) The Access Key used to programmatically access the AWS GovCloud account.
45-
- `secret_access_key` - (Required) The Secret Access Key used to programmatically access the AWS GovCloud account.
33+
- `account_id` - (Optional) The New Relic account ID to operate on. This allows the user to override the `account_id` attribute set on the provider. Defaults to the environment variable `NEW_RELIC_ACCOUNT_ID`, if not specified in the configuration.
34+
- `name` - (Required) The name/identifier of the AWS GovCloud - New Relic 'linked' account.
35+
- `metric_collection_mode` - (Optional) The mode by which metric data is to be collected from the linked AWS GovCloud account. Defaults to `PULL`, if not specified in the configuration.
36+
- Use `PUSH` for Metric Streams and `PULL` for API Polling based metric collection respectively.
37+
- `arn` - (Required) The Amazon Resource Name (ARN) of the IAM role.
38+
39+
-> **NOTE:** Altering the `account_id` (or) `metric_collection_mode` of an already applied `newrelic_cloud_aws_govcloud_link_account` resource shall trigger a recreation of the resource, instead of an update.
4640

4741
## Attributes Reference
4842

0 commit comments

Comments
 (0)