diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl new file mode 100755 index 0000000..60e0af1 --- /dev/null +++ b/.terraform.lock.hcl @@ -0,0 +1,19 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/azurerm" { + version = "2.45.1" + hashes = [ + "h1:fHWHWrf6l5P2IAYGPyt1trkeEwpSLwwK1+30EHNQplQ=", + "zh:257cc6e06e7b4f5eb7b8e5999ed59a984a16d2c7582da01c4318be4270d3274f", + "zh:49dffa76925d3db2634668630d5cdc33d80b7ffbdc39787b180ed41ee657a4fa", + "zh:6d1c28e9e35e7a6ff6a7ce57a5ffe34213c263ff135f2aa2900474f51568037b", + "zh:80c0f6c5e83ce57a08a8552b4b9b8b1f4d42a7bc3b050a408e003cbe20e55272", + "zh:9a30b2821d5ee4a7aa2145f6467639f414a5851e7c658346d57b94bde56c7ec4", + "zh:a6ba84564b768b821726fe2fc34763bece99e2ef190420a49e6c94e7a86d279e", + "zh:c32d250618b841aac2ef5c1af40d9f4d551162957d5f9c2106851e9363b37b4d", + "zh:cc4af260a0d017a6fcda436c8ddb9e5d049ec9a38d51d141498ebaeeadd1fa22", + "zh:e0cfe4d5a9a19d02ab19123ad9bccde8e0f87f130bd3d93760e651968f6da637", + "zh:e65803c7d2625ad2217543f177494b4fcb737c391e21649cfb167541aa9a9d64", + ] +} diff --git a/README.md b/README.md index 1f0be52..4edd1e0 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,25 @@ # Azure App Service + Terraform module to create Azure App Service -# Usage +## Usage ``` data "azurerm_resource_group" "rg" { name = "RG_Apps" } +module "appservice_plan" { + source = "github.com/iquzart/terraform-azurerm-appservice-plan" + + resource_group_name = data.azurerm_resource_group.rg.name + location = data.azurerm_resource_group.rg.location + name = var.appservice_plan_name + kind = var.kind + tier = var.tier + size = var.size + tags = var.tags +} module "appservice" { source = "github.com/iquzart/terraform-azurerm-appservice" @@ -20,61 +32,48 @@ module "appservice" { container_image = var.container_image container_image_tag = var.container_image_tag container_image_registry = var.container_image_registry -} - -``` - -# Variables -``` -variable "resource_group_name" { - description = "App service resource group name" - type = string - default = "" -} - -variable "location" { - description = "App service location" - type = string - default = "" -} -variable "app_name" { - description = "App service name" - type = string - default = "" + site_config = { + linux_fx_version = "docker|diquzart/go-app:latest" + always_on = true + http2_enabled = true + min_tls_version = 1.2 + } + + + app_settings = { + "BANNER" = var.appbanner, + "PORT" = var.app_port + } + + connection_string = [{ + name = "database" + type = "MySQL" + value = "xxxxxxx.xxxxxxxx.xx" + }] + + tags = var.tags } -variable "app_service_plan_id" { - description = "App service plan id" - type = string - default = "" -} -variable "container_type" { - description = "Type of container. The options are: `docker`, `compose` or `kube`." - type = string - default = "" -} - -variable "container_image" { - description = "Container image name. Example: diquzart/flaskapp" - type = string - default = "" -} +``` -variable "container_image_tag" { - description = "Container image tag" - type = string - default = "" -} +## Input Variables +| Name | Description | Type | Default | Required | +|---|---|---|---|---| +| resource_group_name | The name of the resource group in which to create the App Service Plan component. | string | na | yes | +| location | Specifies the supported Azure location where the resource exists. | string | na | yes | +| app_name | (Required) Specifies the name of the App Service | string | na | yes | +| app_service_plan_id | (Required) Specifies the name of the App Service plan | string | na | yes | +| app_settings | (Optional) A key-value pair of App Settings | map(string) | na | no | +| site_config | (Optional) A site_config block. | any | {} | yes | +| connection_string | (Optional) One or more connection_string | list(map(string)) | [] | no | +| tags | (Optional) A mapping of default tags to assign to the resource | map(string) | na | no | -variable "container_image_registry" { - description = "Container image registry" - type = string - default = "https://index.docker.io" -} -``` -# License +## License MIT + +## Author Information +Muhammed Iqbal diff --git a/main.tf b/main.tf index 879cb6c..d1b9a86 100644 --- a/main.tf +++ b/main.tf @@ -1,21 +1,46 @@ -# # Azure App service +# Azure App service + +terraform { + required_version = "> 0.12.0" +} resource "azurerm_app_service" "app" { name = var.app_name location = var.location resource_group_name = var.resource_group_name app_service_plan_id = var.app_service_plan_id - - site_config { - linux_fx_version = "${var.container_type}|${var.container_image}:${var.container_image_tag}" - always_on = true - http2_enabled = true - } + dynamic "site_config" { + for_each = [var.site_config] + + content { + always_on = lookup(site_config.value, "always_on", null) + app_command_line = lookup(site_config.value, "app_command_line", null) + default_documents = lookup(site_config.value, "default_documents", null) + dotnet_framework_version = lookup(site_config.value, "dotnet_framework_version", null) + ftps_state = lookup(site_config.value, "ftps_state", null) + health_check_path = lookup(site_config.value, "health_check_path", null) + http2_enabled = lookup(site_config.value, "http2_enabled", null) + java_container = lookup(site_config.value, "java_container", null) + java_container_version = lookup(site_config.value, "java_container_version", null) + java_version = lookup(site_config.value, "java_version", null) + linux_fx_version = lookup(site_config.value, "linux_fx_version", null) + min_tls_version = lookup(site_config.value, "min_tls_version", null) + php_version = lookup(site_config.value, "php_version", null) + python_version = lookup(site_config.value, "python_version", null) + windows_fx_version = lookup(site_config.value, "windows_fx_version", null) + } + } + + app_settings = var.app_settings - app_settings = { - "DOCKER_REGISTRY_SERVER_URL" = var.container_image_registry - "PORT" = "8080" + dynamic "connection_string" { + for_each = var.connection_string + content { + name = lookup(connection_string.value, "name", null) + type = lookup(connection_string.value, "type", null) + value = lookup(connection_string.value, "value", null) + } } tags = var.tags diff --git a/output.tf b/output.tf index 1492cc3..0f06087 100644 --- a/output.tf +++ b/output.tf @@ -1 +1,13 @@ -# Azure App service Plan \ No newline at end of file +# Azure App service + +output "app_service_name" { + description = "Name of the App Service" + value = azurerm_app_service.app.name +} + +output "app_service_default_site_hostname" { + description = "The Default Hostname associated with the App Service" + value = azurerm_app_service.app.default_site_hostname +} + + diff --git a/variable.tf b/variable.tf index eb5e2c5..f4713a5 100644 --- a/variable.tf +++ b/variable.tf @@ -1,54 +1,48 @@ -# Azure App service Plan +# Azure App service variable "resource_group_name" { - description = "App service resource group name" + description = "(Required) The name of the resource group in which to create the App Service" type = string default = "" } variable "location" { - description = "App service location" + description = "(Required) Specifies the supported Azure location where the resource exists" type = string default = "" } variable "app_name" { - description = "App service name" + description = "(Required) Specifies the name of the App Service" type = string default = "" } variable "app_service_plan_id" { - description = "App service plan id" + description = "(Required) Specifies the name of the App Service plan" type = string default = "" } -variable "container_type" { - description = "Type of container. The options are: `docker`, `compose` or `kube`." - type = string - default = "" -} - -variable "container_image" { - description = "Container image name. Example: diquzart/flaskapp" - type = string - default = "" +variable "tags" { + description = "(Optional) A mapping of default tags to assign to the resource" + type = map(string) } -variable "container_image_tag" { - description = "Container image tag" - type = string - default = "" +variable "app_settings" { + description = "(Optional) A key-value pair of App Settings" + type = map(string) + default = {} } -variable "container_image_registry" { - description = "Container image registry" - type = string - default = "https://index.docker.io" +variable "site_config" { + description = "(Optional) A site_config block." + type = any + default = {} } -variable "tags" { - description = "A mapping of tags to assign to the resource" - type = map(string) +variable "connection_string" { + description = "(Optional) One or more connection_string" + type = list(map(string)) + default = [] } \ No newline at end of file