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

azurerm_application_insights_workbook - fix update display_name without tags #22148

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
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