├── .gitignore ├── README.md ├── all_outputs.tf ├── frontend.variables.tf ├── global_variables.tf ├── local.tfvars └── main.tf /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terraform - The definitive guide for Azure enthusiasts 2 | 3 | This sample is part of my article "Terraform - The definitive guide for Azure enthusiasts" 4 | 5 | Read the article [on my blog](https://thns.io/terraform-guide) 6 | 7 | -------------------------------------------------------------------------------- /all_outputs.tf: -------------------------------------------------------------------------------- 1 | data "azurerm_subscription" "current" {} 2 | 3 | output "target_azure_subscription" { 4 | value = "${data.azurerm_subscription.current.display_name}" 5 | } 6 | 7 | output "instrumentation_key" { 8 | value = "${azurerm_application_insights.ai.instrumentation_key}" 9 | } 10 | 11 | output "appservice_dns_name" { 12 | value = "${azurerm_app_service.appsvc.default_site_hostname}" 13 | } 14 | -------------------------------------------------------------------------------- /frontend.variables.tf: -------------------------------------------------------------------------------- 1 | variable "appservice_plan_tier" { 2 | type = "string" 3 | default = "Standard" 4 | description = "Specify the SKU tier for the app service plan" 5 | } 6 | 7 | variable "appservice_plan_size" { 8 | type = "string" 9 | default = "S1" 10 | description = "Specify the SKU size for the app service plan" 11 | } 12 | 13 | variable "appservice_plan_kind" { 14 | type = "string" 15 | default = "Linux" 16 | description = "Specify the kind for the app service plan (Linux, FunctionApp or Windows)" 17 | } 18 | 19 | variable "appservice_always_on" { 20 | type = "string" 21 | default = true 22 | description = "Specify if the app service should be always online" 23 | } 24 | 25 | variable "appservice_docker_image" { 26 | type = "string" 27 | default = "nginx:alpine" 28 | description = "Specify the Docker image that should be deployed to the app service" 29 | } 30 | -------------------------------------------------------------------------------- /global_variables.tf: -------------------------------------------------------------------------------- 1 | #global_variables.tf 2 | variable "location" { 3 | type = "string" 4 | default = "westeurope" 5 | description = "Specify a location see: az account list-locations -o table" 6 | } 7 | 8 | variable "tags" { 9 | type = "map" 10 | description = "A list of tags associated to all resources" 11 | 12 | default = { 13 | maintained_by = "terraform" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /local.tfvars: -------------------------------------------------------------------------------- 1 | tags = { 2 | author = "Thorsten Hans" 3 | } 4 | 5 | appservice_plan_tier = "Standard" 6 | 7 | appservice_plan_size = "S1" 8 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | provider "azurerm" { 2 | version = "=1.22.0" 3 | } 4 | 5 | resource "azurerm_resource_group" "resg" { 6 | name = "terraform-group" 7 | location = "${var.location}" 8 | tags = "${var.tags}" 9 | } 10 | 11 | resource "azurerm_application_insights" "ai" { 12 | name = "terraform-ai" 13 | resource_group_name = "${azurerm_resource_group.resg.name}" 14 | location = "${azurerm_resource_group.resg.location}" 15 | application_type = "Web" 16 | tags = "${var.tags}" 17 | } 18 | 19 | resource "azurerm_app_service_plan" "appsvcplan" { 20 | name = "terraform-app-svc-plan" 21 | resource_group_name = "${azurerm_resource_group.resg.name}" 22 | location = "${azurerm_resource_group.resg.location}" 23 | kind = "${var.appservice_plan_kind}" 24 | reserved = true 25 | tags = "${var.tags}" 26 | 27 | sku { 28 | tier = "${var.appservice_plan_tier}" 29 | size = "${var.appservice_plan_size}" 30 | } 31 | } 32 | 33 | resource "azurerm_app_service" "appsvc" { 34 | name = "terraform-app-linux-app-svc" 35 | resource_group_name = "${azurerm_resource_group.resg.name}" 36 | app_service_plan_id = "${azurerm_app_service_plan.appsvcplan.id}" 37 | location = "${azurerm_resource_group.resg.location}" 38 | tags = "${var.tags}" 39 | 40 | app_settings { 41 | WEBSITES_ENABLE_APP_SERVICE_STORAGE = false 42 | } 43 | 44 | site_config { 45 | always_on = "${var.appservice_always_on}" 46 | linux_fx_version = "DOCKER|${var.appservice_docker_image}" 47 | } 48 | } 49 | --------------------------------------------------------------------------------