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_log_analytics_solution: fix update & refactor to typed sdk #23333

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -152,12 +152,23 @@ func resourceLogAnalyticsSolutionCreateUpdate(d *pluginsdk.ResourceData, meta in
Tags: expandTags(d.Get("tags").(map[string]interface{})),
}

err = client.CreateOrUpdateThenPoll(ctx, id, parameters)
if err != nil {
return fmt.Errorf("creating/updating %s: %+v", id, err)
}
if d.IsNewResource() {
err = client.CreateOrUpdateThenPoll(ctx, id, parameters)
if err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}

d.SetId(id.ID())
d.SetId(id.ID())
} else {
patch := solution.SolutionPatch{
Tags: expandTags(d.Get("tags").(map[string]interface{})),
}

err = client.UpdateThenPoll(ctx, id, patch)
if err != nil {
return fmt.Errorf("updating %s: %+v", id, err)
}
}

return resourceLogAnalyticsSolutionRead(d, meta)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ func TestAccLogAnalyticsSolution_basicContainerMonitoring(t *testing.T) {
})
}

func TestAccLogAnalyticsSolution_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_solution", "test")
r := LogAnalyticsSolutionResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.containerMonitoring(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.update(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccLogAnalyticsSolution_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_log_analytics_solution", "test")
r := LogAnalyticsSolutionResource{}
Expand Down Expand Up @@ -117,6 +139,43 @@ resource "azurerm_log_analytics_solution" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (LogAnalyticsSolutionResource) update(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_log_analytics_workspace" "test" {
name = "acctestLAW-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "PerGB2018"
}

resource "azurerm_log_analytics_solution" "test" {
solution_name = "ContainerInsights"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
workspace_resource_id = azurerm_log_analytics_workspace.test.id
workspace_name = azurerm_log_analytics_workspace.test.name

plan {
publisher = "Microsoft"
product = "OMSGallery/ContainerInsights"
}

tags = {
Environment = "Test2"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (r LogAnalyticsSolutionResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down