Log Analytics workspace does not see existing data rules via terraform

I have problem with data rule. I create terraform code that create Log Analytics workspace and data rule and diag settings and all is fine all create butt when i want to create transformation it did not see existing data rule. Someone can help me or maybe now how to fix? I use azurerm version = “~>3.103.1”
This is my code
`

resource "azurerm_monitor_diagnostic_setting" "backenddiagnosticsettings" {
  name               = "${var.resource_group_prefix}-${var.application_environment_name}-be${var.instance_name}-logs"
  target_resource_id = azurerm_linux_web_app.backend.id[enter image description here]
  log_analytics_workspace_id = azurerm_log_analytics_workspace.logworkspace.id # data.azurerm_log_analytics_workspace.logworkspace.id
  enabled_log {
    category = "AppServiceConsoleLogs"

    retention_policy {
      enabled = true
    }
  }

  metric {
    category = "AllMetrics"

    retention_policy {
      enabled = true
    }
  }
}





data "azurerm_monitor_data_collection_rule" "example" {
  name                = "example-rule"
  resource_group_name = azurerm_resource_group.example.name
}

output "rule_id" {
  value = data.azurerm_monitor_data_collection_rule.example.id
}

resource "azurerm_log_analytics_workspace" "logworkspace" {
  name                = "${var.resource_group_prefix}-${var.application_environment_name}${var.instance_name}-logs"
  location            = var.location
  resource_group_name = data.azurerm_resource_group.apprg.name
  sku                 = "PerGB2018"
  retention_in_days   = 30
  data_collection_rule_id = ["${azurerm_monitor_data_collection_rule.backendlogs-dcr.id}"]
  
}




resource "azurerm_monitor_data_collection_rule" "backendlogs-dcr" {
  name                = "${var.resource_group_prefix}-${var.application_environment_name}-backend-dcr"
  resource_group_name = data.azurerm_resource_group.apprg.name
  location            = var.location
 
  
  destinations {
    log_analytics {
      name = "${azurerm_log_analytics_workspace.logworkspace.name}"
      workspace_resource_id = azurerm_log_analytics_workspace.logworkspace.id
    }
  }
  

  data_flow {
    streams       = ["Microsoft-Table-AppServiceConsoleLogs"]
    #destinations  = ["example-destination-log"]
    destinations = ["${azurerm_log_analytics_workspace.logworkspace.name}"]
    output_stream = "Microsoft-AppServiceConsoleLogs"
    transform_kql = "sourcen| extend Context = parse_json(ResultDescription)n| extend Thread_CF = tostring(Context.thread)n| extend Level_CF = tostring(Context.level)n| extend Logger_CF = tostring(Context.logger)n| extend Message_CF = tostring(Context.message)n| project-away Context,ResultDescription" 
    #"sourcen| extend LL_CF = substring(ResultDescription, 12, 34)"
  }


  

}


enter image description here
To help with this error

New contributor

Nazar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

It seems like you’re having trouble getting your Terraform code to recognize an existing data rule when creating a Log Analytics workspace. Here are some tips to make it more understandable:

  1. Check Data Rule Existence: Make sure the data rule you’re referring to (azurerm_monitor_data_collection_rule.backendlogs-dcr) exists before you create the Log Analytics workspace. If it’s created later, Terraform might miss it, so you might need to run terraform apply again.

  2. Using Interpolation: Instead of directly mentioning the data rule ID in the Log Analytics workspace setup, try using interpolation with the data rule resource directly. For instance:

    data_collection_rule_id = [azurerm_monitor_data_collection_rule.backendlogs-dcr.id]
    
  3. Verify Data Rule Name and ID: Double-check that the data rule you’re referring to has the correct name (backendlogs-dcr). If the name doesn’t match, Terraform won’t find it.

  4. Managing Dependencies: Ensure you’ve properly managed dependencies between resources. If the Log Analytics workspace depends on the data rule, explicitly specify the dependency like this:

    depends_on = [azurerm_monitor_data_collection_rule.backendlogs-dcr]
    

By following these steps, you should be able to ensure that your Log Analytics workspace recognizes the existing data rule and uses it for transformations. If you’re still having trouble, consult the Terraform documentation or Azure provider documentation for more guidance.

New contributor

Piyush Ranjan Satapathy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật