From ed8e6f9d39bfcadc7bb034092cebc1b237d4bf43 Mon Sep 17 00:00:00 2001 From: Tao <104055472+teowa@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:05:05 +0800 Subject: [PATCH] `azurerm_application_insights_workbook ` - fix update display_name without tags (#22148) * fix update display_name without tags setting * fix --- .../application_insights_workbook_resource.go | 5 ++- ...ication_insights_workbook_resource_test.go | 31 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/internal/services/applicationinsights/application_insights_workbook_resource.go b/internal/services/applicationinsights/application_insights_workbook_resource.go index 824c04379ed0..39295b4476a9 100644 --- a/internal/services/applicationinsights/application_insights_workbook_resource.go +++ b/internal/services/applicationinsights/application_insights_workbook_resource.go @@ -203,7 +203,7 @@ func (r ApplicationInsightsWorkbookResource) Update() sdk.ResourceFunc { } properties := resp.Model - if properties == nil { + if properties == nil || properties.Properties == nil { return fmt.Errorf("retrieving %s: properties was nil", id) } @@ -217,6 +217,9 @@ func (r ApplicationInsightsWorkbookResource) Update() sdk.ResourceFunc { if metadata.ResourceData.HasChange("display_name") { properties.Properties.DisplayName = model.DisplayName + if properties.Tags != nil { + delete(*properties.Tags, "hidden-title") + } } if metadata.ResourceData.HasChange("data_json") { diff --git a/internal/services/applicationinsights/application_insights_workbook_resource_test.go b/internal/services/applicationinsights/application_insights_workbook_resource_test.go index dab1fdc98ea3..f7643bff713c 100644 --- a/internal/services/applicationinsights/application_insights_workbook_resource_test.go +++ b/internal/services/applicationinsights/application_insights_workbook_resource_test.go @@ -22,7 +22,7 @@ func TestAccApplicationInsightsWorkbook_basic(t *testing.T) { r := ApplicationInsightsWorkbookResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basic(data, data.RandomInteger), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -36,7 +36,7 @@ func TestAccApplicationInsightsWorkbook_requiresImport(t *testing.T) { r := ApplicationInsightsWorkbookResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basic(data, data.RandomInteger), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -59,6 +59,27 @@ func TestAccApplicationInsightsWorkbook_complete(t *testing.T) { }) } +func TestAccApplicationInsightsWorkbook_updateDisplayName(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_application_insights_workbook", "test") + r := ApplicationInsightsWorkbookResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, 1), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.basic(data, 2), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccApplicationInsightsWorkbook_update(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_application_insights_workbook", "test") r := ApplicationInsightsWorkbookResource{} @@ -121,7 +142,7 @@ resource "azurerm_resource_group" "test" { `, data.RandomInteger, data.Locations.Primary) } -func (r ApplicationInsightsWorkbookResource) basic(data acceptance.TestData) string { +func (r ApplicationInsightsWorkbookResource) basic(data acceptance.TestData, intValue int) string { template := r.template(data) return fmt.Sprintf(` %s @@ -148,7 +169,7 @@ resource "azurerm_application_insights_workbook" "test" { ] }) } -`, template, data.RandomInteger) +`, template, intValue) } func (r ApplicationInsightsWorkbookResource) hiddenTitleInTags(data acceptance.TestData) string { @@ -185,7 +206,7 @@ resource "azurerm_application_insights_workbook" "test" { } func (r ApplicationInsightsWorkbookResource) requiresImport(data acceptance.TestData) string { - config := r.basic(data) + config := r.basic(data, data.RandomInteger) return fmt.Sprintf(` %s