Ability to pass in a custom log analytics workspace ID #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Why?
How?
log_analytics_workspace_id
that defaults tonull
.azurerm_log_analytics_workspace
resource so it is only created when the new variable is undefined.try(azurerm_log_analytics_workspace.workspace[0].id, var.azurerm_log_analytics_workspace_id)
.Testing?
I first ran this against an existing deployment of the module that I have in my development environment to ensure that everything left default would be non-destructive (screenshot 1).
I then ran it with
var.log_analytics_workspace_id
defined to ensure that it could plan + apply without breaking anything other than deleting the existing workspace (screenshot 2).Screenshots
Plan showing that with everything default the only change is an update to TF state because the resource now has a count index:

Plan + apply showing successful deletion of the old log analytics workspace and updating the application insights to point at the custom workspace:

Anything Else?
If you'd rather it were more explicit we could quite easily add a
use_custom_workspace
flag or similar rather than having it decided implicitly based on the new variable being defined.We can also quite easily move away from
count
tofor_each = var.log_analytics_workspace_id == null ? [1] : []
if you'd prefer not to introduce count.I also moved the existing example about, added an example for using the custom log analytics workspace, added a new GitHub action for the custom log analytics workspace example and updated the working directory for the 'validate-example.yml' GitHub action to use the new directory structure.