From 5cfcd60ffd548517e0e4392ae03b1e172bf5975d Mon Sep 17 00:00:00 2001 From: Tao <104055472+teowa@users.noreply.github.com> Date: Tue, 13 Jun 2023 16:13:06 +0800 Subject: [PATCH 1/2] fix update display_name without tags setting --- .../application_insights_workbook_resource.go | 3 +- ...ication_insights_workbook_resource_test.go | 31 ++++++++++++++++--- 2 files changed, 28 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..ced730d9ad26 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,7 @@ func (r ApplicationInsightsWorkbookResource) Update() sdk.ResourceFunc { if metadata.ResourceData.HasChange("display_name") { properties.Properties.DisplayName = model.DisplayName + 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..63c382dc3734 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_updateDisplanName(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 From adeffc78718813a933ef8e2c7cb3172e1307d3e6 Mon Sep 17 00:00:00 2001 From: Tao <104055472+teowa@users.noreply.github.com> Date: Tue, 13 Jun 2023 23:16:31 +0800 Subject: [PATCH 2/2] fix --- .../application_insights_workbook_resource.go | 4 +++- .../application_insights_workbook_resource_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/services/applicationinsights/application_insights_workbook_resource.go b/internal/services/applicationinsights/application_insights_workbook_resource.go index ced730d9ad26..39295b4476a9 100644 --- a/internal/services/applicationinsights/application_insights_workbook_resource.go +++ b/internal/services/applicationinsights/application_insights_workbook_resource.go @@ -217,7 +217,9 @@ func (r ApplicationInsightsWorkbookResource) Update() sdk.ResourceFunc { if metadata.ResourceData.HasChange("display_name") { properties.Properties.DisplayName = model.DisplayName - delete(*properties.Tags, "hidden-title") + 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 63c382dc3734..f7643bff713c 100644 --- a/internal/services/applicationinsights/application_insights_workbook_resource_test.go +++ b/internal/services/applicationinsights/application_insights_workbook_resource_test.go @@ -59,7 +59,7 @@ func TestAccApplicationInsightsWorkbook_complete(t *testing.T) { }) } -func TestAccApplicationInsightsWorkbook_updateDisplanName(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{