terraform.azure.best-practice.azure-appservice-python-version.azure-appservice-python-version

profile photo of semgrepsemgrep
Author
unknown
Download Count*

Ensure that Python version is the latest, if used to run the web app

Run Locally

Run in CI

Defintion

rules:
  - id: azure-appservice-python-version
    message: Ensure that Python version is the latest, if used to run the web app
    patterns:
      - pattern: resource
      - pattern-not-inside: |
          resource "azurerm_app_service" "..." {
          ...
          site_config {
            ...
            python_version = "3.10"
            ...
          }
          ...
          }
      - pattern-inside: |
          resource "azurerm_app_service" "..." {
          ...
          }
    metadata:
      category: best-practice
      technology:
        - terraform
        - azure
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]
    languages:
      - hcl
    severity: INFO

Examples

azure-appservice-python-version.tf

# fail
# ruleid: azure-appservice-python-version
resource "azurerm_app_service" "example" {
  name                = "example-app-service"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id
  https_only          = true
  site_config {
    python_version = "2.7"
    scm_type                 = "someValue"
  }
}

# pass
resource "azurerm_app_service" "example" {
  name                = "example-app-service"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  app_service_plan_id = azurerm_app_service_plan.example.id
  https_only          = true
  site_config {
    python_version = "3.10"
    scm_type                 = "someValue"
  }
}