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

feat(azure_link_account): adds ability to update credentials of azure link accounts #2764

Merged
merged 2 commits into from
Oct 28, 2024
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 @@ -9,7 +9,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/newrelic/go-agent/v3 v3.30.0
github.com/newrelic/go-insights v1.0.3
github.com/newrelic/newrelic-client-go/v2 v2.50.0
github.com/newrelic/newrelic-client-go/v2 v2.50.1
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ github.com/newrelic/go-agent/v3 v3.30.0 h1:ZXHCT/Cot4iIPwcegCZURuRQOsfmGA6wilW+S
github.com/newrelic/go-agent/v3 v3.30.0/go.mod h1:9utrgxlSryNqRrTvII2XBL+0lpofXbqXApvVWPpbzUg=
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.50.0 h1:rnaNyTzK2RsSgbIDzReQCkmgkKl1lwIF5c+MZuIKFnA=
github.com/newrelic/newrelic-client-go/v2 v2.50.0/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo=
github.com/newrelic/newrelic-client-go/v2 v2.50.1 h1:xwRjfxXO1ZvQc4mvy52lNm60jsx4/YtIBxx9mvw7u38=
github.com/newrelic/newrelic-client-go/v2 v2.50.1/go.mod h1:+RRjI3nDGWT3kLm9Oi3QxpBm70uu8q1upEHBVWCZFpo=
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
47 changes: 23 additions & 24 deletions newrelic/resource_newrelic_cloud_azure_link_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package newrelic

import (
"context"
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -31,14 +32,13 @@ func resourceNewRelicCloudAzureLinkAccount() *schema.Resource {
Type: schema.TypeString,
Description: "Application ID for Azure account",
Required: true,
ForceNew: true,
Sensitive: true,
},
"client_secret": {
Type: schema.TypeString,
Description: "Value of the client secret from Azure",
Required: true,
Sensitive: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Expand All @@ -49,13 +49,13 @@ func resourceNewRelicCloudAzureLinkAccount() *schema.Resource {
Type: schema.TypeString,
Description: "Subscription ID for the Azure account",
Required: true,
ForceNew: true,
Sensitive: true,
},
"tenant_id": {
Type: schema.TypeString,
Description: "Tenant ID for the Azure account",
Required: true,
ForceNew: true,
Sensitive: true,
},
},
}
Expand Down Expand Up @@ -147,38 +147,37 @@ func resourceNewRelicCloudAzureLinkAccountRead(ctx context.Context, d *schema.Re
func readAzureLinkedAccount(d *schema.ResourceData, result *cloud.CloudLinkedAccount) {
_ = d.Set("account_id", result.NrAccountId)
_ = d.Set("name", result.Name)
_ = d.Set("application_id", result.AuthLabel)
_ = d.Set("subscription_id", result.ExternalId)
}

func resourceNewRelicCloudAzureLinkAccountUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
providerConfig := meta.(*ProviderConfig)
client := providerConfig.NewClient
accountID := selectAccountID(providerConfig, d)
id, _ := strconv.Atoi(d.Id())
input := []cloud.CloudRenameAccountsInput{
{
Name: d.Get("name").(string),
LinkedAccountId: id,
linkedAccountID, _ := strconv.Atoi(d.Id())

input := cloud.CloudUpdateCloudAccountsInput{
Azure: []cloud.CloudAzureUpdateAccountInput{
{
ApplicationID: d.Get("application_id").(string),
ClientSecret: cloud.SecureValue(d.Get("client_secret").(string)),
LinkedAccountId: linkedAccountID,
Name: d.Get("name").(string),
SubscriptionId: d.Get("subscription_id").(string),
TenantId: d.Get("tenant_id").(string),
},
},
}
cloudRenameAccountPayload, err := client.Cloud.CloudRenameAccountWithContext(ctx, accountID, input)

cloudUpdateAccountPayload, err := client.Cloud.CloudUpdateAccountWithContext(ctx, accountID, input)

if err != nil {

diag.FromErr(err)
return diag.FromErr(err)
}

var diags diag.Diagnostics

if len(cloudRenameAccountPayload.Errors) > 0 {
for _, err := range cloudRenameAccountPayload.Errors {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: err.Type + " " + err.Message,
})

}

return diags
if len(cloudUpdateAccountPayload.LinkedAccounts) == 0 {
return diag.FromErr(fmt.Errorf("no linked account with 'linked_account_id': %d found", linkedAccountID))
}
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions newrelic/resource_newrelic_cloud_azure_link_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func TestAccNewRelicCloudAzureLinkAccount_Basic(t *testing.T) {
testAzureLinkAccountName := fmt.Sprintf("tf_cloud_link_account_test_azure_%s", acctest.RandString(5))
resourceName := "newrelic_cloud_azure_link_account.foo"

t.Skipf("Skipping test until we can get a better Azure test account")

if subAccountIDExists := os.Getenv("NEW_RELIC_SUBACCOUNT_ID"); subAccountIDExists == "" {
t.Skipf("Skipping this test, as NEW_RELIC_SUBACCOUNT_ID must be set for this test to run.")
}
Expand Down
2 changes: 0 additions & 2 deletions website/docs/r/cloud_azure_link_account.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ The following arguments are supported:
- `tenant_id` - (Required) - Tenant ID of the Azure cloud account.
- `name` - (Required) - The name of the application in New Relic APM.

-> **WARNING:** Starting with [v3.27.2](https://registry.terraform.io/providers/newrelic/newrelic/3.27.2) of the New Relic Terraform Provider, updating any of the aforementioned attributes (except `name`) of a `newrelic_cloud_azure_link_account` resource that has been applied would **force a replacement** of the resource (destruction of the resource, followed by the creation of a new resource). Please carefully review the output of `terraform plan`, which would clearly indicate a replacement of this resource, before performing a `terraform apply`.

## Attributes Reference

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