diff --git a/examples/Microsoft.OperationalInsights_workspaces_tables@2022-10-01/log_analytics_workspace_audit/main.tf b/examples/Microsoft.OperationalInsights_workspaces_tables@2022-10-01/log_analytics_workspace_audit/main.tf new file mode 100644 index 000000000..64b2e528e --- /dev/null +++ b/examples/Microsoft.OperationalInsights_workspaces_tables@2022-10-01/log_analytics_workspace_audit/main.tf @@ -0,0 +1,99 @@ +terraform { + required_providers { + azapi = { + source = "Azure/azapi" + } + } +} + +provider "azapi" { + skip_provider_registration = false +} + +variable "resource_name" { + type = string + default = "acctest0001" +} + +variable "location" { + type = string + default = "westeurope" +} + +locals { + audit_log_table_name = "AuditLog_CL" + audit_log_columns = [ + { + "name" : "appId", + "type" : "string" + }, + { + "name" : "correlationId", + "type" : "string" + }, + { + "name" : "TimeGenerated", + "type" : "datetime" + } + ] +} + +resource "azapi_resource" "resourceGroup" { + type = "Microsoft.Resources/resourceGroups@2020-06-01" + name = var.resource_name + location = var.location +} + +resource "azapi_resource" "workspace" { + type = "Microsoft.OperationalInsights/workspaces@2022-10-01" + parent_id = azapi_resource.resourceGroup.id + name = var.resource_name + location = var.location + body = { + properties = { + features = { + disableLocalAuth = false + enableLogAccessUsingOnlyResourcePermissions = true + } + publicNetworkAccessForIngestion = "Enabled" + publicNetworkAccessForQuery = "Enabled" + retentionInDays = 30 + sku = { + name = "PerGB2018" + } + workspaceCapping = { + dailyQuotaGb = -1 + } + } + } + schema_validation_enabled = false + response_export_values = ["*"] +} + +resource "azapi_resource" "table" { + type = "Microsoft.OperationalInsights/workspaces/tables@2022-10-01" + parent_id = azapi_resource.workspace.id + name = local.audit_log_table_name + body = { + properties = { + schema = { + name = local.audit_log_table_name + columns = local.audit_log_columns + } + } + } + schema_validation_enabled = false + response_export_values = ["*"] +} + +resource "azapi_resource_action" "logAnalyticsWorkspaceAuditTable" { + type = "Microsoft.OperationalInsights/workspaces/tables@2022-10-01" + resource_id = azapi_resource.table.id + method = "PUT" + body = { + properties = { + retentionInDays = 730 + totalRetentionInDays = 1826 + } + } +}