Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Terraforming Azure PaaS
# functionapp.tf
#
# Configure the Azure Provider
provider "azurerm" {
version = "=1.20.0"
}
locals {
name = "${var.name}"
location = "${var.location}"
resource_group = "${var.resource_group}"
tags = "${var.tags}"
consumption_plan_id = "${var.consumption_plan_id}"
web_config = "${var.web_config}"
app_settings = "${var.app_settings}"
}
resource "azurerm_function_app" "fncapp" {
# Function app name
name = "${local.name}"
# Function app location
location = "${local.location}"
# Resource group name that Function app belongs
resource_group_name = "${local.resource_group}"
# Resource tags
tags = "${local.tags}"
# Consumption plan ID
app_service_plan_id = "${local.consumption_plan_id}"
# Web config
https_only = "${local.web_config["https_only"]}"
site_config {
use_32_bit_worker_process = "${local.web_config["use_32_bit_worker_process"]}"
}
# App settings
storage_connection_string = "${local.app_settings["storage_connection_string"]}"
version = "${local.app_settings["functions_extension_version"]}"
app_settings {
AzureWebJobsSecretStorageType = "${local.app_settings["secret_storage_type"]}"
FUNCTION_APP_EDIT_MODE = "${local.app_settings["functions_edit_mode"]}"
FUNCTIONS_WORKER_RUNTIME = "${local.app_settings["functions_worker_runtime"]}"
}
}
resource "azurerm_logic_app_trigger_custom" "test" {
name = "example-trigger"
logic_app_id = "${azurerm_logic_app_workflow.test.id}"
# JSON hard-coding required
body = <<BODY
{
"recurrence": {
"frequency": "Day",
"interval": 1
},
"type": "Recurrence"
}
BODY
}
# logicapp.tf
#
# Configure the Azure Provider
provider "azurerm" {
version = "=1.20.0"
}
locals {
name = "${var.name}"
location = "${var.location}"
resource_group = "${var.resource_group}"
tags = "${var.tags}"
}
resource "azurerm_logic_app_workflow" "logapp" {
# Logic App name
name = "${local.name}"
# Logic App location
location = "${local.location}"
# Resource group name that Logic App belongs
resource_group_name = "${local.resource_group}"
# Resouce tags
tags = "${local.tags}"
}
# orchestrator.tf
#
# Configure the Azure Provider
provider "azurerm" {
version = "=1.20.0"
}
# Initialise external variables
variable "resource_name" {
type = "string"
description = "Resource name"
}
variable "resource_environment" {
type = "string"
description = "Resource environment"
default = "Development"
}
variable "resource_environment_code" {
type = "string"
description = "Resource environment code"
default = "dev"
}
variable "resource_location" {
type = "string"
description = "Resource location"
default = "Australia Southeast"
}
variable "resource_location_code" {
type = "string"
description = "Resource location code"
default = "ase"
}
# Initialise local variables
locals {
resource_long_name = "{0}-${var.resource_name}-${var.resource_environment_code}-${var.resource_location_code}"
resource_short_name = "${replace(local.resource_long_name, "-", "")}"
location = "${var.resource_location}"
tags = {
environment = "${var.resource_environment}"
}
}
# Create Resource Group
module "resgrp" {
source = "./modules/resourcegroup"
name = "${replace(local.resource_long_name, "{0}", "resgrp")}"
location = "${local.location}"
tags = "${local.tags}"
}
# Create Storage Account
module "st" {
source = "./modules/storageaccount"
name = "${replace(local.resource_short_name, "{0}", "st")}"
location = "${local.location}"
resource_group = "${module.resgrp.name}"
tags = "${local.tags}"
}
# Create Consumption Plan
module "csplan" {
source = "./modules/consumptionplan"
name = "${replace(local.resource_long_name, "{0}", "csplan")}"
location = "${local.location}"
resource_group = "${module.resgrp.name}"
tags = "${local.tags}"
}
# Create Function App
module "fncapp" {
source = "./modules/functionapp"
name = "${replace(local.resource_long_name, "{0}", "fncapp")}"
location = "${local.location}"
resource_group = "${module.resgrp.name}"
tags = "${local.tags}"
consumption_plan_id = "${module.csplan.id}"
web_config = {
https_only = "true"
use_32_bit_worker_process = "false"
}
app_settings = {
storage_connection_string = "${module.st.connection_string}"
secret_storage_type = "Files"
functions_extension_version = "~2"
functions_edit_mode = "ReadOnly"
functions_worker_runtime = "dotnet"
}
}
# Create Logic App
module "logapp" {
source = "./modules/logicapp"
name = "${replace(local.resource_long_name, "{0}", "logapp")}"
location = "${local.location}"
resource_group = "${module.resgrp.name}"
tags = "${local.tags}"
}
# outputs.tf
#
# Resource group ID
output "id" {
value = "${azurerm_resource_group.resgrp.id}"
}
# Resource Group name
output "name" {
value = "${azurerm_resource_group.resgrp.name}"
}
# Resource Group location
output "location" {
value = "${azurerm_resource_group.resgrp.location}"
}
# resourcegroup.tf
#
# Configure the Azure Provider
provider "azurerm" {
version = "=1.20.0"
}
locals {
name = "${var.name}"
location = "${var.location}"
tags = "${var.tags}"
}
resource "azurerm_resource_group" "resgrp" {
# Resource group name
name = "${local.name}"
# Resource group location
location = "${local.location}"
# Resource group tag
tags = "${local.tags}"
}
# variables.tf
#
variable "name" {
type = "string"
description = "Resource group name"
}
variable "location" {
type = "string"
description = "Resource group location"
default = "Australia Southeast"
}
variable "tags" {
type = "map"
description = "Tags for resource group"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.