Skip to content

Commit 7f0454b

Browse files
authored
Merge pull request #3 from kumarvna/develop
updating the module configuration
2 parents a5b8de6 + 473c087 commit 7f0454b

File tree

9 files changed

+179
-1450
lines changed

9 files changed

+179
-1450
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
Azure App Service is a fully managed web hosting service for building web apps, mobile back ends and RESTful APIs. This terraform module helps you create Azure App Service with optional site_config, backup, connection_string, auth_settings and Storage for mount points.
44

5+
> **[!NOTE]**
6+
> **This module supports the meta arguments including `providers`, `depends_on`, `count`, and `for_each`.**
7+
58
## Module Usage
69

710
```hcl
11+
# Azurerm Provider configuration
12+
provider "azurerm" {
13+
features {}
14+
}
15+
816
module "web-app" {
917
source = "kumarvna/web-app/azurerm"
1018
version = "1.0.0"

appinsights.tf

Lines changed: 0 additions & 16 deletions
This file was deleted.

examples/complete/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Terraform module to create Azure App Service with optional site_config, backup,
55
## Module Usage
66

77
```hcl
8+
# Azurerm Provider configuration
9+
provider "azurerm" {
10+
features {}
11+
}
12+
813
module "web-app" {
914
source = "kumarvna/web-app/azurerm"
1015
version = "1.0.0"

examples/complete/main.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
# Azurerm Provider configuration
2+
provider "azurerm" {
3+
features {}
4+
}
5+
16
module "web-app" {
2-
source = "kumarvna/web-app/azurerm"
3-
version = "1.0.0"
7+
// source = "kumarvna/web-app/azurerm"
8+
// version = "1.0.0"
9+
source = "../../"
410

511
# By default, this module will not create a resource group. Location will be same as existing RG.
612
# proivde a name to use an existing resource group, specify the existing resource group name,

graph.svg

Lines changed: 0 additions & 1295 deletions
This file was deleted.

locals.tf

Lines changed: 0 additions & 85 deletions
This file was deleted.

main.tf

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
1+
#---------------------------------
2+
# Local declarations
3+
#---------------------------------
4+
locals {
5+
resource_group_name = element(coalescelist(data.azurerm_resource_group.rgrp.*.name, azurerm_resource_group.rg.*.name, [""]), 0)
6+
location = element(coalescelist(data.azurerm_resource_group.rgrp.*.location, azurerm_resource_group.rg.*.location, [""]), 0)
7+
8+
# Default configuration for Site config block
9+
default_site_config = {
10+
always_on = "true"
11+
}
12+
13+
# Enabling the App Insights on app service - default configuration for agent
14+
app_insights = try(data.azurerm_application_insights.main.0, try(azurerm_application_insights.main.0, {}))
15+
16+
default_app_settings = var.application_insights_enabled ? {
17+
APPLICATION_INSIGHTS_IKEY = try(local.app_insights.instrumentation_key, "")
18+
APPINSIGHTS_INSTRUMENTATIONKEY = try(local.app_insights.instrumentation_key, "")
19+
APPLICATIONINSIGHTS_CONNECTION_STRING = try(local.app_insights.connection_string, "")
20+
ApplicationInsightsAgent_EXTENSION_VERSION = "~2"
21+
} : {}
22+
23+
# App service IP Address, Subnet_ids and Service_Tag restrictions
24+
ip_address = [for ip_address in var.ips_allowed : {
25+
name = "ip_restriction_cidr_${join("", [1, index(var.ips_allowed, ip_address)])}"
26+
ip_address = ip_address
27+
virtual_network_subnet_id = null
28+
service_tag = null
29+
subnet_id = null
30+
priority = join("", [1, index(var.ips_allowed, ip_address)])
31+
action = "Allow"
32+
}]
33+
34+
subnets = [for subnet in var.subnet_ids_allowed : {
35+
name = "ip_restriction_subnet_${join("", [1, index(var.subnet_ids_allowed, subnet)])}"
36+
ip_address = null
37+
virtual_network_subnet_id = subnet
38+
service_tag = null
39+
subnet_id = subnet
40+
priority = join("", [1, index(var.subnet_ids_allowed, subnet)])
41+
action = "Allow"
42+
}]
43+
44+
service_tags = [for service_tag in var.service_tags_allowed : {
45+
name = "service_tag_restriction_${join("", [1, index(var.service_tags_allowed, service_tag)])}"
46+
ip_address = null
47+
virtual_network_subnet_id = null
48+
service_tag = service_tag
49+
subnet_id = null
50+
priority = join("", [1, index(var.service_tags_allowed, service_tag)])
51+
action = "Allow"
52+
}]
53+
54+
# App service SCM IP Address, SCM Subnet_ids andSCM Service_Tag restrictions
55+
scm_ip_address = [for ip_address in var.scm_ips_allowed : {
56+
name = "scm_ip_restriction_cidr_${join("", [1, index(var.scm_ips_allowed, ip_address)])}"
57+
ip_address = ip_address
58+
virtual_network_subnet_id = null
59+
service_tag = null
60+
subnet_id = null
61+
priority = join("", [1, index(var.scm_ips_allowed, ip_address)])
62+
action = "Allow"
63+
}]
64+
65+
scm_subnets = [for subnet in var.scm_subnet_ids_allowed : {
66+
name = "scm_ip_restriction_subnet_${join("", [1, index(var.scm_subnet_ids_allowed, subnet)])}"
67+
ip_address = null
68+
virtual_network_subnet_id = subnet
69+
service_tag = null
70+
subnet_id = subnet
71+
priority = join("", [1, index(var.scm_subnet_ids_allowed, subnet)])
72+
action = "Allow"
73+
}]
74+
75+
scm_service_tags = [for service_tag in var.scm_service_tags_allowed : {
76+
name = "scm_service_tag_restriction_${join("", [1, index(var.scm_service_tags_allowed, service_tag)])}"
77+
ip_address = null
78+
virtual_network_subnet_id = null
79+
service_tag = service_tag
80+
subnet_id = null
81+
priority = join("", [1, index(var.scm_service_tags_allowed, service_tag)])
82+
action = "Allow"
83+
}]
84+
85+
}
86+
187
#---------------------------------------------------------
288
# Resource Group Creation or selection - Default is "true"
389
#----------------------------------------------------------
@@ -15,6 +101,58 @@ resource "azurerm_resource_group" "rg" {
15101
tags = merge({ "ResourceName" = format("%s", var.resource_group_name) }, var.tags, )
16102
}
17103

104+
#---------------------------------------------------------
105+
# Generating Storage SAS URL - Default is "false"
106+
#----------------------------------------------------------
107+
data "azurerm_storage_account" "storeacc" {
108+
count = var.enable_backup ? 1 : 0
109+
name = var.storage_account_name
110+
resource_group_name = local.resource_group_name
111+
}
112+
113+
resource "azurerm_storage_container" "storcont" {
114+
count = var.enable_backup ? 1 : 0
115+
name = var.storage_container_name == null ? "appservice-backup" : var.storage_container_name
116+
storage_account_name = data.azurerm_storage_account.storeacc.0.name
117+
container_access_type = "private"
118+
}
119+
120+
resource "time_rotating" "main" {
121+
count = var.enable_backup ? 1 : 0
122+
rotation_rfc3339 = var.password_end_date
123+
rotation_years = var.password_rotation_in_years
124+
125+
triggers = {
126+
end_date = var.password_end_date
127+
years = var.password_rotation_in_years
128+
}
129+
}
130+
131+
data "azurerm_storage_account_blob_container_sas" "main" {
132+
count = var.enable_backup ? 1 : 0
133+
connection_string = data.azurerm_storage_account.storeacc.0.primary_connection_string
134+
container_name = azurerm_storage_container.storcont.0.name
135+
https_only = true
136+
137+
start = timestamp()
138+
expiry = time_rotating.main.0.rotation_rfc3339
139+
140+
permissions {
141+
read = true
142+
add = true
143+
create = true
144+
write = true
145+
delete = true
146+
list = true
147+
}
148+
149+
cache_control = "max-age=5"
150+
content_disposition = "inline"
151+
content_encoding = "deflate"
152+
content_language = "en-US"
153+
content_type = "application/json"
154+
}
155+
18156
#---------------------------------------------------------
19157
# App Service Plan definition - Default is "true"
20158
#----------------------------------------------------------
@@ -174,3 +312,23 @@ resource "azurerm_app_service_custom_hostname_binding" "cust-host-bind" {
174312
thumbprint = lookup(azurerm_app_service_certificate.main, each.key, false) != false ? azurerm_app_service_certificate.main[each.key].thumbprint : null
175313
}
176314

315+
316+
#---------------------------------------------------------
317+
# Application Insights resoruces - Default is "false"
318+
#----------------------------------------------------------
319+
data "azurerm_application_insights" "main" {
320+
count = var.application_insights_enabled && var.application_insights_id != null ? 1 : 0
321+
name = split("/", var.application_insights_id)[8]
322+
resource_group_name = split("/", var.application_insights_id)[4]
323+
}
324+
325+
resource "azurerm_application_insights" "main" {
326+
count = var.application_insights_enabled && var.application_insights_id == null ? 1 : 0
327+
name = lower(format("appi-%s", var.app_insights_name))
328+
location = local.location
329+
resource_group_name = local.resource_group_name
330+
application_type = var.application_insights_type
331+
retention_in_days = var.retention_in_days
332+
disable_ip_masking = var.disable_ip_masking
333+
tags = merge({ "ResourceName" = "${var.app_insights_name}" }, var.tags, )
334+
}

storage-sas-url.tf

Lines changed: 0 additions & 48 deletions
This file was deleted.

versions.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@ terraform {
1212
}
1313
required_version = ">= 0.13"
1414
}
15-
16-
provider "azurerm" {
17-
features {}
18-
}

0 commit comments

Comments
 (0)