使用terraform使用azure insights记录应用程序日志并将其移动到Blob存储[已关闭]

tv6aics1  于 2022-12-24  发布在  其他
关注(0)|答案(1)|浏览(104)

已关闭。此问题需要超过focused。当前不接受答案。
**想要改进此问题吗?**更新此问题,使其仅关注editing this post的一个问题。

3天前关闭。
Improve this question
我是初学者在这方面,任何人都可以给我的想法,我可以做使用terraform日志记录的应用程序使用azure的见解,并将这些移动到Blob存储与github的行动。

vh0rcniy

vh0rcniy1#

要了解Terraform本身,Hashicorp站点是一个很好的起点
如果您只想创建应用洞察、存储帐户、日志分析工作区(这是应用洞察和所需内容的后台存储)以及将规则导出到存储,您的Terraform脚本可以如下所示作为示例

# Configure the Azure provider
provider "azurerm" {
  version = "~> 2.24.0"
}

# Create a resource group
resource "azurerm_resource_group" "example" {
  name     = "example-resource-group"
  location = "East US"
}

# Create a log analytics workspace
resource "azurerm_log_analytics_workspace" "example" {
  name                = "example-log-analytics-workspace"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

# Create a storage account
resource "azurerm_storage_account" "example" {
  name                     = "examplestorageaccount"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

# Create a log analytics solution
resource "azurerm_log_analytics_solution" "example" {
  name                = "example-log-analytics-solution"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  workspace_id        = azurerm_log_analytics_workspace.example.id
  solution_type       = "ApplicationInsights"
}

# Create an export rule to move logs from Azure Insights to Azure Blob storage
resource "azurerm_log_analytics_export_rule" "example" {
  name                = "example-export-rule"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  workspace_id        = azurerm_log_analytics_workspace.example.id
  storage_account_id  = azurerm_storage_account.example.id
  container_name      = "logs"
  export_name         = "example-logs"
}

此配置文件将在你的Azure订阅中创建以下资源:
Azure资源组Azure Insights日志分析工作区Azure存储帐户Azure Insights日志分析解决方案用于将日志从日志分析工作区导出到存储帐户的Azure Insights日志分析导出规则
创建这些资源后,你可以将应用程序配置为将日志发送到日志分析工作区,并且导出规则会定期自动将日志移动到Azure Blob存储(默认值为1天,您可以始终通过添加属性scheduled_transfer_period对其进行自定义)。
就GitHub操作而言,潜在操作如下所示

name: Deploy Terraform configuration

on: [push]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Login to Azure
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
      - name: Deploy Terraform configuration
        uses: azure/terraform@v1
        with:
          working-directory: path/to/terraform/configuration
          terraform-version: 0.14.4
          backend-config: |
            resource_group_name = "example-resource-group"
            storage_account_name = "examplestorageaccount"
            container_name = "tfstate"
            key = "terraform.tfstate"
          init-options: |
            -backend-config=backend-config
            -upgrade=true
          plan-options: |
            -input=false
            -no-color
            -out=tfplan
          apply-options: |
            -input=false
            -auto-approve
            tfplan

相关问题