### Example Usage of azurerm_app_service_connection Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_connection This snippet demonstrates the creation of an Azure App Service connection. It includes the setup of prerequisite resources such as a resource group, a Cosmos DB account with a SQL database and container, and a Linux web app with a service plan. This example is useful for establishing a connection between an App Service and a data source like Cosmos DB. ```Terraform resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_cosmosdb_account" "example" { name = "example-cosmosdb-account" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name offer_type = "Standard" kind = "GlobalDocumentDB" consistency_policy { consistency_level = "BoundedStaleness" max_interval_in_seconds = 10 max_staleness_prefix = 200 } geo_location { location = azurerm_resource_group.example.location failover_priority = 0 } } resource "azurerm_cosmosdb_sql_database" "example" { name = "cosmos-sql-db" resource_group_name = azurerm_cosmosdb_account.example.resource_group_name account_name = azurerm_cosmosdb_account.example.name throughput = 400 } resource "azurerm_cosmosdb_sql_container" "example" { name = "example-container" resource_group_name = azurerm_cosmosdb_account.example.resource_group_name account_name = azurerm_cosmosdb_account.example.name database_name = azurerm_cosmosdb_sql_database.example.name partition_key_path = "/definition" } resource "azurerm_service_plan" "example" { location = azurerm_resource_group.example.location name = "example-serviceplan" resource_group_name = azurerm_resource_group.example.name sku_name = "P1v2" os_type = "Linux" } resource "azurerm_linux_web_app" "example" { location = azurerm_resource_group.example.location name = "example-linuxwebapp" resource_group_name = azurerm_resource_group.example.name service_plan_id = azurerm_service_plan.example.id site_config {} } ``` -------------------------------- ### Windows Function App Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/function_app_active_slot Example of how to configure an active slot for a Windows Function App. ```APIDOC ## azurerm_function_app_active_slot Manages a Function App Active Slot. ### Arguments Reference The following arguments are supported: * `slot_id` - (Required) The ID of the Slot to swap with `Production`. * `overwrite_network_config` - (Optional) The swap action should overwrite the Production slot's network configuration with the configuration from this slot. Defaults to `true`. Changing this forces a new resource to be created. ### Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: * `id` - The ID of the Function App Active Slot * `last_successful_swap` - The timestamp of the last successful swap with `Production` ### Timeouts The `timeouts` block allows you to specify timeouts for certain actions: * `create` - (Defaults to 30 minutes) Used when creating the Function App Active Slot. * `read` - (Defaults to 5 minutes) Used when retrieving the Function App Active Slot. * `update` - (Defaults to 30 minutes) Used when updating the Function App Active Slot. * `delete` - (Defaults to 5 minutes) Used when deleting the Function App Active Slot. ### Import a Function App Active Slot can be imported using the `resource id`, e.g. ```terraform terraform import azurerm_function_app_active_slot.example "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/sites/site1" ``` ``` -------------------------------- ### Basic azurerm_security_center_storage_defender Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/security_center_storage_defender This example shows how to enable Defender for Storage for a given storage account. It requires a pre-existing resource group and storage account. ```terraform resource "azurerm_resource_group" "example" { name = "example-rg" location = "westus2" } resource "azurerm_storage_account" "example" { name = "exampleacc" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_security_center_storage_defender" "example" { storage_account_id = azurerm_storage_account.example.id } ``` -------------------------------- ### Example Usage (using a role definition name) Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/marketplace_role_assignment This example demonstrates how to assign a role to a principal using the role definition name. ```APIDOC ## azurerm_marketplace_role_assignment (using role definition name) ### Description Assigns a given Principal (User or Group) to a given Role in a Private Azure Marketplace using the role definition name. ### Arguments Reference * `principal_id` - (Required) The ID of the Principal (User, Group or Service Principal) to assign the Role Definition to. Changing this forces a new resource to be created. * `role_definition_name` - (Optional) The name of a built-in Role. Changing this forces a new resource to be created. Conflicts with `role_definition_id`. * `name` - (Optional) A unique UUID/GUID for this Role Assignment - one will be generated if not specified. Changing this forces a new resource to be created. * `condition` - (Optional) The condition that limits the resources that the role can be assigned to. Changing this forces a new resource to be created. * `condition_version` - (Optional) The version of the condition. Possible values are `1.0` or `2.0`. Changing this forces a new resource to be created. * `delegated_managed_identity_resource_id` - (Optional) The delegated Azure Resource ID which contains a Managed Identity. Changing this forces a new resource to be created. * `description` - (Optional) The description for this Role Assignment. Changing this forces a new resource to be created. * `skip_service_principal_aad_check` - (Optional) If the `principal_id` is a newly provisioned `Service Principal` set this value to `true` to skip the `Azure Active Directory` check which may fail due to replication lag. This argument is only valid if the `principal_id` is a `Service Principal` identity. Defaults to `false`. Changing this forces a new resource to be created. ### Attributes Reference * `id` - The Role Assignment ID. * `principal_type` - The type of the `principal_id`, e.g. User, Group, Service Principal, Application, etc. ### Timeouts * `create` - (Defaults to 30 minutes) Used when creating the Role Assignment. * `read` - (Defaults to 5 minutes) Used when retrieving the Role Assignment. * `delete` - (Defaults to 30 minutes) Used when deleting the Role Assignment. ``` -------------------------------- ### Example Usage (using a role definition ID) Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/marketplace_role_assignment This example shows how to assign a role to a principal using the role definition ID. ```APIDOC ## azurerm_marketplace_role_assignment (using role definition ID) ### Description Assigns a given Principal (User or Group) to a given Role in a Private Azure Marketplace using the role definition ID. ### Arguments Reference * `principal_id` - (Required) The ID of the Principal (User, Group or Service Principal) to assign the Role Definition to. Changing this forces a new resource to be created. * `role_definition_id` - (Optional) The Scoped-ID of the Role Definition. Changing this forces a new resource to be created. Conflicts with `role_definition_name`. * `name` - (Optional) A unique UUID/GUID for this Role Assignment - one will be generated if not specified. Changing this forces a new resource to be created. * `condition` - (Optional) The condition that limits the resources that the role can be assigned to. Changing this forces a new resource to be created. * `condition_version` - (Optional) The version of the condition. Possible values are `1.0` or `2.0`. Changing this forces a new resource to be created. * `delegated_managed_identity_resource_id` - (Optional) The delegated Azure Resource ID which contains a Managed Identity. Changing this forces a new resource to be created. * `description` - (Optional) The description for this Role Assignment. Changing this forces a new resource to be created. * `skip_service_principal_aad_check` - (Optional) If the `principal_id` is a newly provisioned `Service Principal` set this value to `true` to skip the `Azure Active Directory` check which may fail due to replication lag. This argument is only valid if the `principal_id` is a `Service Principal` identity. Defaults to `false`. Changing this forces a new resource to be created. ### Attributes Reference * `id` - The Role Assignment ID. * `principal_type` - The type of the `principal_id`, e.g. User, Group, Service Principal, Application, etc. ### Timeouts * `create` - (Defaults to 30 minutes) Used when creating the Role Assignment. * `read` - (Defaults to 5 minutes) Used when retrieving the Role Assignment. * `delete` - (Defaults to 30 minutes) Used when deleting the Role Assignment. ``` -------------------------------- ### azurerm_service_plan Data Source Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/service_plan This example demonstrates how to use the azurerm_service_plan data source to retrieve details of an existing Service Plan and output its ID. ```APIDOC ## Data Source: azurerm_service_plan Use this data source to access information about an existing Service Plan. ### Example Usage ``` data "azurerm_service_plan" "example" { name = "existing" resource_group_name = "existing" } output "id" { value = data.azurerm_service_plan.example.id } ``` ### Arguments Reference The following arguments are supported: * `name` - (Required) The name of this Service Plan. * `resource_group_name` - (Required) The name of the Resource Group where the Service Plan exists. ### Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: * `id` - The ID of the Service Plan. * `app_service_environment_id` - The ID of the App Service Environment this Service Plan is part of. * `kind` - A string representing the Kind of Service Plan. * `location` - The Azure Region where the Service Plan exists. * `maximum_elastic_worker_count` - The maximum number of workers in use in an Elastic SKU Plan. * `worker_count` - The number of Workers (instances) allocated. * `os_type` - The O/S type for the App Services hosted in this plan. * `per_site_scaling_enabled` - Is Per Site Scaling be enabled? * `reserved` - Whether this is a reserved Service Plan Type. `true` if `os_type` is `Linux`, otherwise `false`. * `sku_name` - The SKU for the Service Plan. * `zone_balancing_enabled` - Is the Service Plan balance across Availability Zones in the region? * `tags` - A mapping of tags assigned to the Service Plan. ### Timeouts The `timeouts` block allows you to specify timeouts for certain actions: * `read` - (Defaults to 5 minutes) Used when retrieving the Service Plan. ### API Providers This data source uses the following Azure API Providers: * `Microsoft.Web` - 2023-12-01 ``` -------------------------------- ### Provision an App Service Environment V3 Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_environment_v3 This example provisions an App Service Environment V3, including the necessary network resources and configuration settings. Additional examples are available in the GitHub repository. ```terraform resource "azurerm_resource_group" "example" { name = "exampleRG1" location = "West Europe" } resource "azurerm_virtual_network" "example" { name = "example-vnet" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name address_space = ["10.0.0.0/16"] } resource "azurerm_subnet" "example" { name = "example-subnet" resource_group_name = azurerm_resource_group.example.name virtual_network_name = azurerm_virtual_network.example.name address_prefixes = ["10.0.2.0/24"] delegation { name = "Microsoft.Web.hostingEnvironments" service_delegation { name = "Microsoft.Web/hostingEnvironments" actions = ["Microsoft.Network/virtualNetworks/subnets/action"] } } } resource "azurerm_app_service_environment_v3" "example" { name = "example-asev3" resource_group_name = azurerm_resource_group.example.name subnet_id = azurerm_subnet.example.id internal_load_balancing_mode = "Web, Publishing" cluster_setting { name = "DisableTls1.0" value = "1" } cluster_setting { name = "InternalEncryption" value = "true" } cluster_setting { name = "FrontEndSSLCipherSuiteOrder" value = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" } tags = { env = "production" terraformed = "true" } } resource "azurerm_service_plan" "example" { name = "example" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location os_type = "Linux" sku_name = "I1v2" app_service_environment_id = azurerm_app_service_environment_v3.example.id } ``` -------------------------------- ### azurerm_app_service Data Source Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/app_service This example demonstrates how to use the azurerm_app_service data source to retrieve information about an existing App Service and output its ID. ```APIDOC ## Data Source: azurerm_app_service Use this data source to access information about an existing App Service. __Note: This data source has been deprecated and will be removed in version 5.0 of the AzureRM provider. Please use the `azurerm_linux_web_app` and `azurerm_windows_web_app` data sources instead. ## Example Usage ``` data "azurerm_app_service" "example" { name = "search-app-service" resource_group_name = "search-service" } output "app_service_id" { value = data.azurerm_app_service.example.id } ``` ## Arguments Reference * `name` - The name of the App Service. * `resource_group_name` - The Name of the Resource Group where the App Service exists. ## Attributes Reference * `id` - The ID of the App Service. * `location` - The Azure location where the App Service exists. * `app_service_plan_id` - The ID of the App Service Plan within which the App Service exists. * `app_settings` - A key-value pair of App Settings for the App Service. * `connection_string` - An `connection_string` block as defined below. * `client_affinity_enabled` - Does the App Service send session affinity cookies, which route client requests in the same session to the same instance? * `custom_domain_verification_id` - An identifier used by App Service to perform domain ownership verification via DNS TXT record. * `enabled` - Is the App Service Enabled? * `https_only` - Can the App Service only be accessed via HTTPS? * `client_cert_enabled` - Does the App Service require client certificates for incoming requests? * `site_config` - A `site_config` block as defined below. * `tags` - A mapping of tags to assign to the resource. * `default_site_hostname` - The Default Hostname associated with the App Service - such as `mysite.azurewebsites.net` * `outbound_ip_addresses` - A comma separated list of outbound IP addresses - such as `52.23.25.3,52.143.43.12` * `outbound_ip_address_list` - A list of outbound IP addresses - such as `["52.23.25.3", "52.143.43.12"]` * `possible_outbound_ip_addresses` - A comma separated list of outbound IP addresses - such as `52.23.25.3,52.143.43.12,52.143.43.17` - not all of which are necessarily in use. Superset of `outbound_ip_addresses`. * `possible_outbound_ip_address_list` - A list of outbound IP addresses - such as `["52.23.25.3", "52.143.43.12", "52.143.43.17"]` - not all of which are necessarily in use. Superset of `outbound_ip_address_list`. * `source_control` - A `source_control` block as defined below. * * * A `connection_string` block exports the following: * `name` - The name of the Connection String. * `type` - The type of the Connection String. * `value` - The value for the Connection String. * * * A `cors` block exports the following: * `allowed_origins` - A list of origins which are able to make cross-origin calls. * `support_credentials` - Are credentials supported? * * * An `ip_restriction` block exports the following: * `ip_address` - The IP Address used for this IP Restriction. * `service_tag` - The Service Tag used for this IP Restriction. * `subnet_mask` - The Subnet mask used for this IP Restriction. * `name` - The name for this IP Restriction. * `priority` - The priority for this IP Restriction. * `action` - Does this restriction `Allow` or `Deny` access for this IP range? * * * An `scm_ip_restriction` block exports the following: * `ip_address` - The IP Address used for this IP Restriction in CIDR notation. * `service_tag` - The Service Tag used for this IP Restriction. * `virtual_network_subnet_id` - The Virtual Network Subnet ID used for this IP Restriction. * `name` - The name for this IP Restriction. * `priority` - The priority for this IP Restriction. * `action` - Allow or Deny access for this IP range. Defaults to Allow. ``` -------------------------------- ### Example Usage of azurerm_source_control_token Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/source_control_token This example demonstrates how to use the azurerm_source_control_token data source to retrieve a GitHub token. Note that this token can only be queried for the executing user or service principal. ```hcl data "azurerm_source_control_token" "example" { type = "GitHub" } output "id" { value = data.azurerm_app_service_github_token.example.id } ``` -------------------------------- ### Example Usage of App Service Managed Certificate Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_managed_certificate This example demonstrates how to configure an App Service, its custom hostname binding, and a managed certificate for securing custom domains. It includes DNS record creation for verification. ```terraform data "azurerm_dns_zone" "example" { name = "mydomain.com" resource_group_name = azurerm_resource_group.example.name } resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_app_service_plan" "example" { name = "example-plan" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name kind = "Linux" reserved = true sku { tier = "Basic" size = "B1" } } resource "azurerm_app_service" "example" { name = "example-app" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name app_service_plan_id = azurerm_app_service_plan.example.id } resource "azurerm_dns_txt_record" "example" { name = "asuid.mycustomhost.contoso.com" zone_name = data.azurerm_dns_zone.example.name resource_group_name = data.azurerm_dns_zone.example.resource_group_name ttl = 300 record { value = azurerm_app_service.example.custom_domain_verification_id } } resource "azurerm_dns_cname_record" "example" { name = "example-adcr" zone_name = data.azurerm_dns_zone.example.name resource_group_name = data.azurerm_dns_zone.example.resource_group_name ttl = 300 record = azurerm_app_service.example.default_site_hostname } resource "azurerm_app_service_custom_hostname_binding" "example" { hostname = join(".", [azurerm_dns_cname_record.example.name, azurerm_dns_cname_record.example.zone_name]) app_service_name = azurerm_app_service.example.name resource_group_name = azurerm_resource_group.example.name } resource "azurerm_app_service_managed_certificate" "example" { custom_hostname_binding_id = azurerm_app_service_custom_hostname_binding.example.id } resource "azurerm_app_service_certificate_binding" "example" { hostname_binding_id = azurerm_app_service_custom_hostname_binding.example.id certificate_id = azurerm_app_service_managed_certificate.example.id ssl_state = "SniEnabled" } ``` -------------------------------- ### Example Usage of azurerm_role_definition Data Source Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/role_definition Demonstrates how to use the azurerm_role_definition data source to retrieve information about custom and built-in role definitions. It shows examples of fetching by ID and name, and outputting the retrieved role definition IDs. ```hcl data "azurerm_subscription" "primary" { } resource "azurerm_role_definition" "custom" { role_definition_id = "00000000-0000-0000-0000-000000000000" name = "CustomRoleDef" scope = data.azurerm_subscription.primary.id #... } data "azurerm_role_definition" "custom" { role_definition_id = azurerm_role_definition.custom.role_definition_id scope = data.azurerm_subscription.primary.id # /subscriptions/00000000-0000-0000-0000-000000000000 } data "azurerm_role_definition" "custom-byname" { name = azurerm_role_definition.custom.name scope = data.azurerm_subscription.primary.id } data "azurerm_role_definition" "builtin" { name = "Contributor" } output "custom_role_definition_id" { value = data.azurerm_role_definition.custom.id } output "contributor_role_definition_id" { value = data.azurerm_role_definition.builtin.id } ``` -------------------------------- ### Example Usage Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_source_control_slot Creates an App Service Source Control Slot linked to a specific slot ID and a GitHub repository. ```terraform resource "azurerm_app_service_source_control_slot" "example" { slot_id = azurerm_linux_web_app_slot.example.id repo_url = "https://github.com/Azure-Samples/python-docs-hello-world" branch = "master" } ``` -------------------------------- ### Example Usage of azurerm_monitor_scheduled_query_rules_alert Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert This snippet demonstrates the basic setup for creating an alert rule. It requires a resource group and an Application Insights instance. ```terraform resource "azurerm_resource_group" "example" { name = "monitoring-resources" location = "West Europe" } resource "azurerm_application_insights" "example" { name = "appinsights" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name application_type = "web" } resource "azurerm_application_insights" "example2" { name = "appinsights2" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name application_type = "web" } ``` -------------------------------- ### App Service Hybrid Connection Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_hybrid_connection Provisions an App Service, a Relay Hybrid Connection, and a Service Bus, then uses their outputs to create the App Service Hybrid Connection. This example demonstrates the setup required for connecting an App Service to a hybrid connection. ```terraform resource "azurerm_resource_group" "example" { name = "exampleResourceGroup1" location = "West Europe" } resource "azurerm_app_service_plan" "example" { name = "exampleAppServicePlan1" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name sku { tier = "Standard" size = "S1" } } resource "azurerm_app_service" "example" { name = "exampleAppService1" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name app_service_plan_id = azurerm_app_service_plan.example.id } resource "azurerm_relay_namespace" "example" { name = "exampleRN1" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name sku_name = "Standard" } resource "azurerm_relay_hybrid_connection" "example" { name = "exampleRHC1" resource_group_name = azurerm_resource_group.example.name relay_namespace_name = azurerm_relay_namespace.example.name user_metadata = "examplemetadata" } resource "azurerm_app_service_hybrid_connection" "example" { app_service_name = azurerm_app_service.example.name resource_group_name = azurerm_resource_group.example.name relay_id = azurerm_relay_hybrid_connection.example.id hostname = "testhostname.example" port = 8080 send_key_name = "exampleSharedAccessKey" } ``` -------------------------------- ### Example Usage of azurerm_windows_function_app Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_function_app This snippet demonstrates how to provision a Windows Function App. It requires setting up a resource group, a storage account for app content, and a service plan for hosting. Ensure the provider and necessary resources are configured before applying. ```terraform provider "azurerm" { features {} } resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_storage_account" "example" { name = "windowsfunctionappsa" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_service_plan" "example" { name = "example-app-service-plan" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location os_type = "Windows" sku_name = "Y1" } resource "azurerm_windows_function_app" "example" { name = "example-windows-function-app" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location storage_account_name = azurerm_storage_account.example.name storage_account_access_key = azurerm_storage_account.example.primary_access_key service_plan_id = azurerm_service_plan.example.id site_config {} } ``` -------------------------------- ### Example Usage (with App Service) Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_virtual_network_swift_connection Creates an App Service Virtual Network Swift Connection for an existing App Service. ```terraform resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_virtual_network" "example" { name = "example-vnet" address_space = ["10.0.0.0/16"] location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name } resource "azurerm_subnet" "example" { name = "example-subnet" resource_group_name = azurerm_resource_group.example.name virtual_network_name = azurerm_virtual_network.example.name address_prefixes = ["10.0.1.0/24"] delegations { name = "serverFarms" service_delegation { name = "Microsoft.Web/serverFarms" actions = [ "Microsoft.Network/virtualNetworks/subnets/join/action" ] } } } resource "azurerm_app_service_plan" "example" { name = "example-plan" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name sku { tier = "Standard" size = "S1" } } 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 } resource "azurerm_app_service_virtual_network_swift_connection" "example" { name = "example-vnet-connection" app_service_id = azurerm_app_service.example.id subnet_id = azurerm_subnet.example.id resource_group_name = azurerm_resource_group.example.name } ``` -------------------------------- ### List all Service Plans in the subscription Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/list-resources/service_plan This example demonstrates how to list all Service Plans within your Azure subscription using the azurerm_service_plan resource. ```APIDOC ## List Service Plans ### Description Lists Service Plan resources. ### Method list ### Endpoint N/A (Terraform resource) ### Parameters #### Configuration Block - `resource_group_name` (Optional) - The name of the resource group to query. - `subscription_id` (Optional) - The Subscription ID to query. Defaults to the value specified in the Provider Configuration. ### Request Example ```terraform list "azurerm_service_plan" "example" { provider = azurerm config {} } ``` ### Response #### Success Response - `list` of service plan objects (details not specified in source). ``` -------------------------------- ### Example Usage (using a role definition name) Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/marketplace_role_assignment Assigns a role to a principal using the role definition name. Ensure the `azurerm_client_config` data source is configured to get the principal's object ID. ```terraform data "azurerm_client_config" "example" { } resource "azurerm_marketplace_role_assignment" "example" { role_definition_name = "Marketplace Admin" principal_id = data.azurerm_client_config.example.object_id lifecycle { ignore_changes = [ name, role_definition_id, ] } } ``` -------------------------------- ### Linux Web App Active Slot Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/web_app_active_slot Example of creating an active slot for a Linux Web App. This involves similar setup steps as for Windows, including resource group, service plan, and the Linux Web App, before defining and activating the slot. ```terraform provider "azurerm" { features {} } resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_service_plan" "example" { name = "example-plan" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location os_type = "Linux" sku_name = "P1v2" } resource "azurerm_linux_web_app" "example" { name = "example-linux-web-app" resource_group_name = azurerm_resource_group.example.name location = azurerm_service_plan.example.location service_plan_id = azurerm_service_plan.example.id site_config {} } resource "azurerm_linux_web_app_slot" "example" { name = "example-linux-web-app-slot" app_service_name = azurerm_linux_web_app.example.name location = azurerm_service_plan.example.location service_plan_id = azurerm_service_plan.example.id site_config {} } resource "azurerm_web_app_active_slot" "example" { slot_id = azurerm_linux_web_app_slot.example.id } ``` -------------------------------- ### Example Usage of azurerm_static_web_app_function_app_registration Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/static_web_app_function_app_registration This example demonstrates how to create a Static Web App, a Linux Function App, and then register the Function App to the Static Web App. Ensure that the `auth_settings_v2` configuration on the Function App is handled, potentially using `ignore_changes`. ```terraform resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_static_web_app" "example" { name = "example" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location } resource "azurerm_storage_account" "example" { name = "examplesstorageacc" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_service_plan" "example" { name = "example-service-plan" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name os_type = "Linux" sku_name = "S1" } resource "azurerm_linux_function_app" "example" { name = "example-function-app" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name service_plan_id = azurerm_service_plan.example.id storage_account_name = azurerm_storage_account.example.name storage_account_access_key = azurerm_storage_account.example.primary_access_key site_config {} lifecycle { ignore_changes = [auth_settings_v2] } } resource "azurerm_static_web_app_function_app_registration" "example" { static_web_app_id = azurerm_static_web_app.example.id function_app_id = azurerm_linux_function_app.example.id } ``` -------------------------------- ### azurerm_monitor_scheduled_query_rules_alert_v2 Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_scheduled_query_rules_alert_v2 This snippet shows how to configure an alert rule that triggers when the number of requests by country/region falls below a threshold. It includes setup for necessary resources like resource groups, application insights, action groups, and user-assigned identities, along with role assignments for permissions. The alert is configured to trigger if the condition is met for at least one evaluation period and uses a user-assigned identity for actions. ```terraform resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_application_insights" "example" { name = "example-ai" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name application_type = "web" } resource "azurerm_monitor_action_group" "example" { name = "example-mag" resource_group_name = azurerm_resource_group.example.name short_name = "test mag" } resource "azurerm_user_assigned_identity" "example" { name = "example-uai" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name } resource "azurerm_role_assignment" "example" { scope = azurerm_application_insights.example.id role_definition_name = "Reader" principal_id = azurerm_user_assigned_identity.example.principal_id } resource "azurerm_monitor_scheduled_query_rules_alert_v2" "example" { name = "example-msqrv2" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location evaluation_frequency = "PT10M" window_duration = "PT10M" scopes = [azurerm_application_insights.example.id] severity = 4 criteria { query = <<-QUERY requests | summarize CountByCountry=count() by client_CountryOrRegion QUERY time_aggregation_method = "Maximum" threshold = 17.5 operator = "LessThan" resource_id_column = "client_CountryOrRegion" metric_measure_column = "CountByCountry" dimension { name = "client_CountryOrRegion" operator = "Exclude" values = ["123"] } failing_periods { minimum_failing_periods_to_trigger_alert = 1 number_of_evaluation_periods = 1 } } auto_mitigation_enabled = true workspace_alerts_storage_enabled = false description = "example sqr" display_name = "example-sqr" enabled = true query_time_range_override = "PT1H" skip_query_validation = true action { action_groups = [azurerm_monitor_action_group.example.id] custom_properties = { key = "value" key2 = "value2" } email_subject = "Email Header" } identity { type = "UserAssigned" identity_ids = [ azurerm_user_assigned_identity.example.id, ] } tags = { key = "value" key2 = "value2" } depends_on = [azurerm_role_assignment.example] } ``` -------------------------------- ### azurerm_windows_function_app Data Source Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/windows_function_app Example usage of the azurerm_windows_function_app data source to retrieve information about a Windows Function App. ```APIDOC ## Data Source: azurerm_windows_function_app Use this data source to access information about an existing Windows Function App. ### Example Usage ``` data "azurerm_windows_function_app" "example" { name = "existing" resource_group_name = "existing" } output "id" { value = data.azurerm_windows_function_app.example.id } ``` ## Arguments Reference The following arguments are supported: * `name` - (Required) The name of this Windows Function App. * `resource_group_name` - (Required) The name of the Resource Group where the Windows Function App exists. ``` -------------------------------- ### Example Usage (with Function App) Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/app_service_virtual_network_swift_connection Creates an App Service Virtual Network Swift Connection for an existing Function App. ```terraform resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_virtual_network" "example" { name = "example-vnet" address_space = ["10.0.0.0/16"] location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name } resource "azurerm_subnet" "example" { name = "example-subnet" resource_group_name = azurerm_resource_group.example.name virtual_network_name = azurerm_virtual_network.example.name address_prefixes = ["10.0.1.0/24"] delegations { name = "serverFarms" service_delegation { name = "Microsoft.Web/serverFarms" actions = [ "Microsoft.Network/virtualNetworks/subnets/join/action" ] } } } resource "azurerm_function_app" "example" { name = "example-function-app" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name enable_builtin_logging = true storage_account_name = azurerm_storage_account.example.name storage_connection_string = azurerm_storage_account.example.primary_connection_string identity { type = "SystemAssigned" } } resource "azurerm_storage_account" "example" { name = "examplesa" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location account_tier = "Standard" account_replication_type = "LRS" } resource "azurerm_app_service_virtual_network_swift_connection" "example" { name = "example-vnet-connection" app_service_id = azurerm_function_app.example.id subnet_id = azurerm_subnet.example.id resource_group_name = azurerm_resource_group.example.name } ``` -------------------------------- ### azurerm_monitor_action_group Data Source Example Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/monitor_action_group Example of how to use the azurerm_monitor_action_group data source to retrieve an Action Group and output its ID. ```APIDOC ## Data Source: azurerm_monitor_action_group Use this data source to access the properties of an Action Group. ### Example Usage ```terraform data "azurerm_monitor_action_group" "example" { resource_group_name = "terraform-example-rg" name = "tfex-actiongroup" } output "action_group_id" { value = data.azurerm_monitor_action_group.example.id } ``` ## Arguments Reference * `name` - Specifies the name of the Action Group. * `resource_group_name` - Specifies the name of the resource group the Action Group is located in. ## Attributes Reference * `id` - The ID of the Action Group. * `short_name` - The short name of the action group. * `enabled` - Whether this action group is enabled. * `arm_role_receiver` - One or more `arm_role_receiver` blocks as defined below. * `automation_runbook_receiver` - One or more `automation_runbook_receiver` blocks as defined below. * `azure_app_push_receiver` - One or more `azure_app_push_receiver` blocks as defined below. * `azure_function_receiver` - One or more `azure_function_receiver` blocks as defined below. * `email_receiver` - One or more `email_receiver` blocks as defined below. * `event_hub_receiver` - One or more `event_hub_receiver` blocks as defined below. * `itsm_receiver` - One or more `itsm_receiver` blocks as defined below. * `logic_app_receiver` - One or more `logic_app_receiver` blocks as defined below. * `sms_receiver` - One or more `sms_receiver` blocks as defined below. * `webhook_receiver` - One or more `webhook_receiver` blocks as defined below. * `voice_receiver` - One or more `voice_receiver` blocks as defined below. * * * `arm_role_receiver` supports the following: * `name` - The name of the ARM role receiver. * `role_id` - The arm role id. * `use_common_alert_schema` - Indicates whether to use common alert schema. * * * `automation_runbook_receiver` supports the following: * `name` - The name of the automation runbook receiver. * `automation_account_id` - The automation account ID which holds this runbook and authenticates to Azure resources. * `runbook_name` - The name for this runbook. * `webhook_resource_id` - The resource id for webhook linked to this runbook. * `is_global_runbook` - Indicates whether this instance is global runbook. * `service_uri` - The URI where webhooks should be sent. * `use_common_alert_schema` - Indicates whether to use common alert schema. * * * `azure_app_push_receiver` supports the following: * `name` - The name of the Azure app push receiver. * `email_address` - The email address of the user signed into the mobile app who will receive push notifications from this receiver. * * * `azure_function_receiver` supports the following: * `name` - The name of the Azure Function receiver. * `function_app_resource_id` - The Azure resource ID of the function app. * `function_name` - The function name in the function app. * `http_trigger_url` - The HTTP trigger url where HTTP request sent to. * `use_common_alert_schema` - Indicates whether to use common alert schema. * * * `email_receiver` supports the following: * `name` - The name of the email receiver. * `email_address` - The email address of this receiver. * `use_common_alert_schema` - Indicates whether to use common alert schema. * * * `event_hub_receiver` supports the following: * `name` - The name of the EventHub Receiver, must be unique within action group. * `event_hub_name` - The name of the specific Event Hub queue. * `event_hub_namespace` - The namespace name of the Event Hub. * `subscription_id` - The ID for the subscription containing this Event Hub. Default to the subscription ID of the Action Group. __Note: `event_hub_id` is deprecated in version 3.0 and will be removed in version 4.0 of the AzureRM Provider. Please use `event_hub_name`, `event_hub_name`,and `subscription_id` instead. * `tenant_id` - The Tenant ID for the subscription containing this Event Hub. * `use_common_alert_schema` - Indicates whether to use common alert schema. ``` -------------------------------- ### Basic azurerm_static_site Resource Source: https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/static_site This example shows how to provision a basic Azure Static Site. Ensure the resource group is defined first. This resource is superseded by `azurerm_static_web_app`. ```terraform resource "azurerm_resource_group" "example" { name = "example-resources" location = "West Europe" } resource "azurerm_static_site" "example" { name = "example" resource_group_name = azurerm_resource_group.example.name location = azurerm_resource_group.example.location } ```