Skip to content

azurerm_log_analytics_workspace - add check for soft-deleted but linked workspaces#29137

Merged
sreallymatt merged 1 commit intomainfrom
mp/law-linked-to-lac-fix
Mar 26, 2025
Merged

azurerm_log_analytics_workspace - add check for soft-deleted but linked workspaces#29137
sreallymatt merged 1 commit intomainfrom
mp/law-linked-to-lac-fix

Conversation

@sreallymatt
Copy link
Collaborator

@sreallymatt sreallymatt commented Mar 20, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

Prequisite: #29120

Supersedes #27522

Probably easier to review if #29120 is merged first.

This resolves an issue raised internally, if a workspace is linked to a log analytics cluster outside of Terraform, then deleted without unlinking first, recreation of the resource using Terraform caused an error as the sku cannot be updated while linked and LACluster was not an option for sku.

This PR does 2 things:

  1. Add LACluster to sku to allow a user to update to this value once linked, avoiding a diff.
  2. Adds a check for soft-deleted and linked workspaces, if one is found, the provider will override sku to LACluster during the create.

As testing this requires a manual step, I've added terraform plan/terraform apply outputs to show the fix is working.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)

Existing tests:

image

No additional test added as mentioned in description.

terraform output
#### Destroy linked workspace ####
Terraform will perform the following actions:

  # azurerm_log_analytics_workspace.test will be destroyed
  # (because azurerm_log_analytics_workspace.test is not in configuration)

  ...

  Plan: 0 to add, 0 to change, 1 to destroy.

  ...

  Apply complete! Resources: 0 added, 0 changed, 1 destroyed.

#### Recreate soft-deleted linked workspace on v4.23.0 ####

Terraform will perform the following actions:

  # azurerm_log_analytics_workspace.test will be created

  ...

  Plan: 1 to add, 0 to change, 0 to destroy.

  ...

  azurerm_log_analytics_workspace.test: Creating...
  ╷
  │ Error: performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: InvalidParameter: Sku cannot be changed while workspace is linked to an Log Analytics Cluster.
  │
  │   with azurerm_log_analytics_workspace.test,
  │   on main.tf line 24, in resource "azurerm_log_analytics_workspace" "test":
  │   24: resource "azurerm_log_analytics_workspace" "test" {
  │
  ╵

#### Recreate soft-deleted linked workspace with changes ####

Terraform will perform the following actions:

  # azurerm_log_analytics_workspace.test will be created

  ...

  Plan: 1 to add, 0 to change, 0 to destroy.

  ...

  azurerm_log_analytics_workspace.test: Creating...
  azurerm_log_analytics_workspace.test: Still creating... [10s elapsed]
  azurerm_log_analytics_workspace.test: Still creating... [20s elapsed]
  azurerm_log_analytics_workspace.test: Creation complete after 26s [id=/subscriptions/<id>/resourceGroups/mp-acctestRG-linkedlaw2/providers/Microsoft.OperationalInsights/workspaces/acctest-LAW-0318]

#### Plan output after recreate (without changing config) ####

Terraform will perform the following actions:

  # azurerm_log_analytics_workspace.test will be updated in-place
  ~ resource "azurerm_log_analytics_workspace" "test" {
        id                                      = "/subscriptions/<id>/resourceGroups/mp-acctestRG-linkedlaw2/providers/Microsoft.OperationalInsights/workspaces/acctest-LAW-0318"
        name                                    = "acctest-LAW-0318"
      ~ sku                                     = "LACluster" -> "PerGB2018" // As expected, cluster sku is `LACluster` in state, config still `PerGB2018`
        tags                                    = {}
        # (14 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

#### Plan output after recreate (config updated) ####

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • azurerm_resource - support for the thing1 property [GH-00000]

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #28743

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@sreallymatt sreallymatt force-pushed the mp/law-linked-to-lac-fix branch from 8c510e2 to 4f7ba7b Compare March 24, 2025 16:34
@sreallymatt
Copy link
Collaborator Author

image

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sreallymatt sreallymatt merged commit 3479e73 into main Mar 26, 2025
34 checks passed
@sreallymatt sreallymatt deleted the mp/law-linked-to-lac-fix branch March 26, 2025 14:03
@github-actions github-actions bot added this to the v4.25.0 milestone Mar 26, 2025
sreallymatt added a commit that referenced this pull request Mar 26, 2025
jackofallops added a commit that referenced this pull request Mar 28, 2025
* CHANGELOG.md for v4.25.0

* Update CHANGELOG.md #29126

* Update CHANGELOG.md #28647

* Update CHANGELOG.md #29153

* Update CHANGELOG.md #29131

* Update CHANGELOG.md #29090

* Update CHANGELOG.md #29137

* Update for #28781

* Update for #29158

* Update for #29073

* Update for #28149

* Update for #28730

* Update for #29157

* Update for #29135

* Update for #29184

* Update for #29093

* Update for #29071

* Update for #28371

* Update for #28560

* Update CHANGELOG.md #29199

* Update CHANGELOG.md for #29206

* prep for release

* Update CHANGELOG.md

---------

Co-authored-by: sreallymatt <106555974+sreallymatt@users.noreply.github.com>
Co-authored-by: stephybun <steph@hashicorp.com>
Co-authored-by: jackofallops <11830746+jackofallops@users.noreply.github.com>
Co-authored-by: jackofallops <ste@hashicorp.com>
@github-actions
Copy link
Contributor

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azurerm_log_analytics_workspace - LACluster Workaround no longer in working state.

2 participants