diff --git a/infra/modules/providers/azure/app-service/README.md b/infra/modules/providers/azure/app-service/README.md new file mode 100644 index 00000000..dd7d1a0c --- /dev/null +++ b/infra/modules/providers/azure/app-service/README.md @@ -0,0 +1,69 @@ +## Azure App Service + +Build, deploy, and scale enterprise-grade web, mobile, and API apps running on any platform. Meet rigorous performance, scalability, security and compliance requirements while using a fully managed platform to perform infrastructure maintenance. + +More information for Azure App Services can be found [here](https://azure.microsoft.com/en-us/services/app-service/) + +Cobalt gives ability to specify following settings for App Service based on the requirements: +- name : The name of the App Services to be created. This is a map of app service name and the linux_fx_version/container image to be loaded for that app service. DOCKER| +- service_plan_resource_group_name : The Name of the Resource Group where the Service Plan exists. +- app_service_plan_id : The ID of the App Service Plan within which the App Service exists is populated automatically based on service plan. +- tags : A mapping of tags to assign to the resource. +- app_settings : A key-value pair of App Settings. Settings for private Container Registries + - DOCKER_REGISTRY_SERVER_URL : The docker registry server URL for app service to be created + - DOCKER_REGISTRY_SERVER_USERNAME : The docker registry server usernames for app services to be created + - DOCKER_REGISTRY_SERVER_PASSWORD : The docker registry server passwords for app services to be created +- site_config : + - always_on : Should the app be loaded at all times? Defaults to false. + - virtual_network_name : The name of the Virtual Network which this App Service should be attached to. + +Please click the [link](https://www.terraform.io/docs/providers/azurerm/d/app_service.html) to get additional details on settings in Terraform for Azure App Service. + +## Usage + +### Module Definitions + +The App Service is dependent on deployment of Service Plan. Make sure to deploy Service Plan before starting to deploy App Services. + +- Service Plan Module : infra/modules/providers/azure/service-plan +- App Service Module : infra/modules/providers/azure/app-service + +``` +variable "resource_group_name" { + value = "test-rg" +} + +variable "service_plan_name" { + value = "test-svcplan" +} + +variable "app_service_name" { + value = { + appservice1="DOCKER|" + appservice2="DOCKER|" + } +} + +module "service_plan" { + resource_group_name = "${var.resource_group_name}" + resource_group_location = "${var.resource_group_location}" + service_plan_name = "${var.service_plan_name}" +} + +module "app_service" { + service_plan_resource_group_name = "${var.resource_group_name}" + service_plan_name = "${var.service_plan_name}" +``` + +## Outputs + +Once the deployments are completed successfully, the output for the current module will be in the format mentioned below: + +``` +Outputs: + +app_service_uri = [ + appservice1.azurewebsites.net, + appservice2.azurewebsites.net +] +``` diff --git a/infra/modules/providers/azure/app-service/main.tf b/infra/modules/providers/azure/app-service/main.tf new file mode 100644 index 00000000..bd7ae5e9 --- /dev/null +++ b/infra/modules/providers/azure/app-service/main.tf @@ -0,0 +1,29 @@ +data "azurerm_resource_group" "appsvc" { + name = "${var.service_plan_resource_group_name}" +} + +data "azurerm_app_service_plan" "appsvc" { + name = "${var.service_plan_name}" + resource_group_name = "${data.azurerm_resource_group.appsvc.name}" +} + +resource "azurerm_app_service" "appsvc" { + name = "${element(keys(var.app_service_name), count.index)}" + resource_group_name = "${data.azurerm_resource_group.appsvc.name}" + location = "${data.azurerm_resource_group.appsvc.location}" + app_service_plan_id = "${data.azurerm_app_service_plan.appsvc.id}" + tags = "${var.resource_tags}" + count = "${length(keys(var.app_service_name))}" + + app_settings { + DOCKER_REGISTRY_SERVER_URL = "${var.docker_registry_server_url}" + DOCKER_REGISTRY_SERVER_USERNAME = "${var.docker_registry_server_username}" + DOCKER_REGISTRY_SERVER_PASSWORD = "${var.docker_registry_server_password}" + } + + site_config { + linux_fx_version = "${element(values(var.app_service_name), count.index)}" + always_on = "${var.site_config_always_on}" + virtual_network_name = "${var.site_config_vnet_name}" + } +} diff --git a/infra/modules/providers/azure/app-service/output.tf b/infra/modules/providers/azure/app-service/output.tf new file mode 100644 index 00000000..489ace70 --- /dev/null +++ b/infra/modules/providers/azure/app-service/output.tf @@ -0,0 +1,5 @@ +output "app_service_uri" { + description = "The URL of the app service created" + value = "${azurerm_app_service.appsvc.*.default_site_hostname}" +} + diff --git a/infra/modules/providers/azure/app-service/variables.tf b/infra/modules/providers/azure/app-service/variables.tf new file mode 100644 index 00000000..26a9c458 --- /dev/null +++ b/infra/modules/providers/azure/app-service/variables.tf @@ -0,0 +1,51 @@ +variable "service_plan_resource_group_name" { + description = "The name of the resource group in which the service plan was created." + type = "string" +} + +variable "service_plan_name" { + description = "The name of the service plan" + type = "string" +} + +variable "resource_tags" { +description = "Map of tags to apply to taggable resources in this module. By default the taggable resources are tagged with the name defined above and this map is merged in" +type = "map" +default = {} +} + +variable "app_service_name" { + description = "The name of the app service to be created" + type = "map" + default = {} +} + +variable "docker_registry_server_url" { + description = "The docker registry server URL for app service to be created" + type = "string" + default = "index.docker.io" +} + +variable "docker_registry_server_username" { + description = "The docker registry server username for app service to be created" + type = "string" + default = "" +} + +variable "docker_registry_server_password" { + description = "The docker registry server password for app service to be created" + type = "string" + default = "" +} + +variable "site_config_always_on" { + description = "Should the app be loaded at all times? Defaults to false." + type = "string" + default = "false" +} + +variable "site_config_vnet_name" { + description = "Should the app be loaded at all times? Defaults to false." + type = "string" + default = "" +} diff --git a/infra/modules/providers/azure/provider/README.md b/infra/modules/providers/azure/provider/README.md index e82b41c8..ee8bf9b4 100644 --- a/infra/modules/providers/azure/provider/README.md +++ b/infra/modules/providers/azure/provider/README.md @@ -65,4 +65,4 @@ resource "null_resource" "example" { command = "execute shell script" } } -``` +``` \ No newline at end of file diff --git a/infra/modules/providers/azure/provider/main.tf b/infra/modules/providers/azure/provider/main.tf index fd3bbd4c..97f26c9b 100644 --- a/infra/modules/providers/azure/provider/main.tf +++ b/infra/modules/providers/azure/provider/main.tf @@ -12,4 +12,4 @@ provider "null" { provider "azuread" { version = "~>0.1" -} +} \ No newline at end of file diff --git a/infra/modules/providers/azure/service-plan/variables.tf b/infra/modules/providers/azure/service-plan/variables.tf index e4192b82..a133374b 100644 --- a/infra/modules/providers/azure/service-plan/variables.tf +++ b/infra/modules/providers/azure/service-plan/variables.tf @@ -5,6 +5,7 @@ variable "resource_group_name" { variable "resource_group_location" { description = "Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. The full list of Azure regions can be found at https://azure.microsoft.com/regions" + type = "string" } variable "resource_tags" { @@ -19,26 +20,31 @@ variable "service_plan_name" { } variable "service_plan_tier" { - description = "The tier under which the service plan is created. Details can be found at https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans" - default = "Isolated" + description = "The tier under which the service plan is created. Details can be found at https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans" + type = "string" + default = "Standard" } variable "service_plan_size" { - description = "The compute and storage needed for the service plan to be deployed. Details can be found at https://azure.microsoft.com/en-us/pricing/details/app-service/windows/" - default = "S1" + description = "The compute and storage needed for the service plan to be deployed. Details can be found at https://azure.microsoft.com/en-us/pricing/details/app-service/windows/" + type = "string" + default = "S1" } variable "service_plan_kind" { - description = "The kind of Service Plan to be created. Possible values are Windows/Linux/FunctionApp/App" - default = "Linux" + description = "The kind of Service Plan to be created. Possible values are Windows/Linux/FunctionApp/App" + type = "string" + default = "Linux" } variable "service_plan_capacity" { description = "The capacity of Service Plan to be created." + type = "number" default = "1" } variable "service_plan_reserved" { description = "Is the Service Plan to be created reserved. Possible values are true/false" + type = "bool" default = true }