Skip to content

Commit

Permalink
azurerm_application_insights_workbook - fix update display_name wi…
Browse files Browse the repository at this point in the history
…thout tags (#22148)

* fix update display_name without tags setting

* fix
  • Loading branch information
teowa authored Jun 14, 2023
1 parent 2eb18aa commit ed8e6f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand All @@ -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),
),
Expand All @@ -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{}
Expand Down Expand Up @@ -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
Expand All @@ -148,7 +169,7 @@ resource "azurerm_application_insights_workbook" "test" {
]
})
}
`, template, data.RandomInteger)
`, template, intValue)
}

func (r ApplicationInsightsWorkbookResource) hiddenTitleInTags(data acceptance.TestData) string {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ed8e6f9

Please sign in to comment.