diff --git a/go.mod b/go.mod index 49037e63d..5077be0a4 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 0b712ded8..0007109ed 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/newrelic/resource_newrelic_cloud_azure_link_account.go b/newrelic/resource_newrelic_cloud_azure_link_account.go index ef1587312..ed5832ba2 100755 --- a/newrelic/resource_newrelic_cloud_azure_link_account.go +++ b/newrelic/resource_newrelic_cloud_azure_link_account.go @@ -2,6 +2,7 @@ package newrelic import ( "context" + "fmt" "strconv" "strings" @@ -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, @@ -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, }, }, } @@ -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 } diff --git a/newrelic/resource_newrelic_cloud_azure_link_account_test.go b/newrelic/resource_newrelic_cloud_azure_link_account_test.go index 60fb5f8cb..b16d4bbb5 100644 --- a/newrelic/resource_newrelic_cloud_azure_link_account_test.go +++ b/newrelic/resource_newrelic_cloud_azure_link_account_test.go @@ -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.") } diff --git a/website/docs/r/cloud_azure_link_account.html.markdown b/website/docs/r/cloud_azure_link_account.html.markdown index d75739ce7..9651aad2c 100644 --- a/website/docs/r/cloud_azure_link_account.html.markdown +++ b/website/docs/r/cloud_azure_link_account.html.markdown @@ -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: