Skip to content

Instantly share code, notes, and snippets.

@Structed
Last active June 25, 2021 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Structed/f3fa38a41b10acefbac38ebc0a1c524f to your computer and use it in GitHub Desktop.
Save Structed/f3fa38a41b10acefbac38ebc0a1c524f to your computer and use it in GitHub Desktop.
TerraformExample
variable "location" {
type = string
description = "The location in which to create all resources"
default = "westeurope"
}
variable "prefix" {
type = string
description = "Resource Name prefix (will be applied to all resource names except the resource group"
default = "gamezure"
}
variable "tags" {
type = map(string)
default = {}
}
variable "sp_client_id" {
type = string
description = "Service Principal ID which is used to run the Gamezure API"
}
variable "use_cosmosdb_free_tier" {
type = bool
description = "Whether to use the CosmosDB free tier. You may only have one CosmosDB account per Azure subscription. For details, see https://docs.microsoft.com/en-us/azure/cosmos-db/how-pricing-works#try-azure-cosmos-db-for-free"
default = false
}
# Configure the Azure provider
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.48"
}
}
backend "azurerm" {}
}
provider "azurerm" {
features {}
}
locals {
management_prefix = "${var.prefix}-management"
vmpool_prefix = "${var.prefix}-vmpool"
}
resource "azurerm_resource_group" "rg_management" {
name = "${local.management_prefix}-rg"
location = var.location
}
resource "azurerm_resource_group" "rg_vmpool" {
name = "${local.vmpool_prefix}-rg"
location = var.location
}
resource "azurerm_role_assignment" "contributor_role_assignment" {
scope = azurerm_resource_group.rg_vmpool.id
role_definition_name = "Contributor"
principal_id = var.sp_client_id
}
resource "azurerm_virtual_network" "network_vmpool" {
name = "${local.vmpool_prefix}-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.rg_vmpool.location
resource_group_name = azurerm_resource_group.rg_vmpool.name
}
resource "azurerm_subnet" "subnet_vmpool" {
name = "${local.vmpool_prefix}-subnet"
resource_group_name = azurerm_resource_group.rg_vmpool.name
virtual_network_name = azurerm_virtual_network.network_vmpool.name
address_prefixes = ["10.0.2.0/24"]
}
resource "azurerm_storage_account" "storage" {
name = replace("${var.prefix}storage", "-", "")
resource_group_name = azurerm_resource_group.rg_management.name
location = azurerm_resource_group.rg_management.location
account_kind = "StorageV2"
account_tier = "Standard"
account_replication_type = "LRS"
access_tier = "Hot"
}
module "cosmosdb" {
source = "./cosmosdb"
resource_group = azurerm_resource_group.rg_management
tags = var.tags
}
resource "azurerm_app_service_plan" "app_service_plan" {
name = "${var.prefix}-app-service-plan"
location = azurerm_resource_group.rg_management.location
resource_group_name = azurerm_resource_group.rg_management.name
kind = "FunctionApp"
sku {
tier = "Dynamic"
size = "Y1"
}
}
resource "azurerm_function_app" "function" {
name = "${var.prefix}-function"
location = azurerm_resource_group.rg_management.location
resource_group_name = azurerm_resource_group.rg_management.name
app_service_plan_id = azurerm_app_service_plan.app_service_plan.id
storage_account_name = azurerm_storage_account.storage.name
storage_account_access_key = azurerm_storage_account.storage.primary_access_key
enabled = true
enable_builtin_logging = true
https_only = true
version = "~3"
// identity {
// type = ""
// }
connection_string {
name = "CosmosDb"
type = "Custom"
value = module.cosmosdb.connection_strings[0]
}
site_config {
ftps_state = "Disabled"
// ip_restriction = []
min_tls_version = "1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment