Skip to content

Commit 3a3e2c5

Browse files
Add module for user assigned managed identity and update the tags based on new policies (#12)
* DEVOPS-289 added tags to API management module and did terraform fmt * DEVOPS-289 added tags tologanalytics ws module and did terraform fmt * DEVOPS-289 terraform fmt * DEVOPS-289 updated provider version to v4.0 azurerm * DEVOPS-289 added tags to storage accnt module and added temporarry and did terraform fmt * DEVOPS-289 did terraform fmt * DEVOPS-289 created user assigned man * terraform fmt and temporary tag DEVOPS-291
1 parent b4bd588 commit 3a3e2c5

File tree

18 files changed

+281
-72
lines changed

18 files changed

+281
-72
lines changed

api-management/apim.tf

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
resource "azurerm_resource_group" "rg" {
22
name = var.resource_group_name
33
location = var.location
4+
tags = {
5+
Environment = upper(var.environment)
6+
Orchestrator = "Terraform"
7+
DisplayName = upper(var.resource_group_name)
8+
ApplicationName = lower(var.application_name)
9+
Temporary = upper(var.temporary)
10+
}
411
}
512

613
resource "azurerm_api_management" "apim" {
@@ -9,6 +16,12 @@ resource "azurerm_api_management" "apim" {
916
resource_group_name = azurerm_resource_group.rg.name
1017
publisher_name = tostring(var.publisher_name)
1118
publisher_email = tostring(var.publisher_email)
12-
1319
sku_name = "${var.sku_name_part1}_${var.sku_name_part2}"
20+
tags = {
21+
Environment = upper(var.environment)
22+
Orchestrator = "Terraform"
23+
DisplayName = upper(var.resource_group_name)
24+
ApplicationName = lower(var.application_name)
25+
Temporary = upper(var.temporary)
26+
}
1427
}

api-management/output.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
output "azure_resource_group_name" {
22
description = "Azure resource group name"
3-
value = azurerm_resource_group.rg.name
3+
value = azurerm_resource_group.rg.name
44
}
55

66
output "azure_api_management_name" {
77
description = "Azure API management name"
8-
value = azurerm_api_management.apim.name
8+
value = azurerm_api_management.apim.name
99
}
1010

1111
output "azure_api_management_location" {
1212
description = "Azure API management location"
13-
value = azurerm_api_management.apim.location
13+
value = azurerm_api_management.apim.location
1414
}
1515

1616
output "azure_api_management_publisher_name" {
1717
description = "Azure API management"
18-
value = azurerm_api_management.apim.publisher_name
18+
value = azurerm_api_management.apim.publisher_name
1919
}
2020

2121
output "azure_api_management_publisher_emailids" {
2222
description = "Azure API management publisher emails"
23-
value = azurerm_api_management.apim.publisher_email
23+
value = azurerm_api_management.apim.publisher_email
2424
}
2525

2626
output "azure_api_management_sku" {
2727
description = "Azure API management SKU"
28-
value = azurerm_api_management.apim.sku_name
28+
value = azurerm_api_management.apim.sku_name
2929
}

api-management/variables.tf

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,74 @@
11
variable "resource_group_name" {
2-
type = string
2+
type = string
33
description = "Azure Storage Account Rg"
44
}
55

66
variable "location" {
7-
type = string
7+
type = string
88
description = "Azure storage account location"
99
}
1010

1111
variable "api_management_name" {
1212
description = "Azure api management name"
13-
type = string
13+
type = string
1414
}
1515

1616
variable "publisher_name" {
1717
description = "Publisher of API"
18-
type = list(string)
18+
type = list(string)
1919
validation {
20-
condition = can(index(var.publisher_name, 0))
20+
condition = can(index(var.publisher_name, 0))
2121
error_message = "A value is required for Publisher name."
2222
}
2323
}
2424

2525
variable "publisher_email" {
2626
description = "Email ID of API publishers"
27-
type = list(string)
27+
type = list(string)
2828
validation {
2929
condition = can(index(var.publisher_email, 0))
30-
error_message = "At least one Publisher email is required."
30+
error_message = "At least one Publisher email is required."
3131
}
3232
}
3333

3434
variable "sku_name_part1" {
3535
description = "SKU name of API management "
36-
type = string
36+
type = string
3737
validation {
38-
condition = contains(["Consumption","Developer","Basic","Standard", "Premium"], var.sku_name_part1)
38+
condition = contains(["Consumption", "Developer", "Basic", "Standard", "Premium"], var.sku_name_part1)
3939
error_message = "SKU name should be one among Consumption, Developer,Basic,Standard,Premium."
40-
}
40+
}
4141
}
4242

4343
variable "sku_name_part2" {
4444
description = "Sku capacity part"
45-
type = string
45+
type = string
46+
}
47+
48+
49+
variable "temporary" {
50+
default = "TRUE"
51+
description = "Temporary tag value in Azure"
52+
type = string
53+
validation {
54+
condition = contains(["TRUE", "FALSE"], upper(var.temporary))
55+
error_message = "The temporary tag value must be either 'TRUE' or 'FALSE'."
56+
}
57+
58+
}
59+
60+
variable "application_name" {
61+
default = ""
62+
description = "Azure application name tag"
63+
type = string
64+
}
65+
66+
variable "environment" {
67+
default = ""
68+
description = "Environment tag value in Azure"
69+
type = string
70+
validation {
71+
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment)
72+
error_message = "Environment value should be one among DEV or QA or UAT or PROD."
73+
}
4674
}

log-analytics-workspace/loganalytics.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@ resource "azurerm_resource_group" "rg" {
66
Orchestrator = "Terraform"
77
DisplayName = upper(var.resource_group_name)
88
ApplicationName = lower(var.application_name)
9+
Temporary = upper(var.temporary)
910
}
1011
}
1112

1213
resource "azurerm_log_analytics_workspace" "loganalytics_ws" {
13-
name = upper(var.loganalytics_workspace_name)
14-
sku = var.loganalytics_sku
14+
name = upper(var.loganalytics_workspace_name)
15+
sku = var.loganalytics_sku
1516
resource_group_name = azurerm_resource_group.rg.name
16-
location = var.location
17-
retention_in_days = var.loganalytics_retention_period
17+
location = var.location
18+
retention_in_days = var.loganalytics_retention_period
19+
tags = {
20+
Environment = upper(var.environment)
21+
Orchestrator = "Terraform"
22+
DisplayName = upper(var.resource_group_name)
23+
ApplicationName = lower(var.application_name)
24+
Temporary = upper(var.temporary)
25+
}
1826
}

log-analytics-workspace/output.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
output "loganalytics_workspace_name" {
2-
value = azurerm_log_analytics_workspace.loganalytics_ws.name
2+
value = azurerm_log_analytics_workspace.loganalytics_ws.name
33
description = "Azure Log analytics workspace name"
44
}
55

66
output "loganalytics_workspace_resource_group" {
7-
value = azurerm_log_analytics_workspace.loganalytics_ws.resource_group_name
8-
description = "Azure Log analytics workspace resource group name"
7+
value = azurerm_log_analytics_workspace.loganalytics_ws.resource_group_name
8+
description = "Azure Log analytics workspace resource group name"
99
}
1010

1111
output "loganalytics_retention_period" {
12-
value = azurerm_log_analytics_workspace.loganalytics_ws.retention_in_days
12+
value = azurerm_log_analytics_workspace.loganalytics_ws.retention_in_days
1313
description = "Azure loganalytics data retention in days"
1414
}
1515

1616
output "loganalytics_sku" {
17-
value = azurerm_log_analytics_workspace.loganalytics_ws.sku
17+
value = azurerm_log_analytics_workspace.loganalytics_ws.sku
1818
description = "Azure loganalytics SKU"
1919
}

log-analytics-workspace/variables.tf

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
variable "resource_group_name" {
2-
default = ""
2+
default = ""
33
description = "Azure resource group name to create log analytics workspace"
4-
type = string
4+
type = string
55
}
66

77
variable "location" {
8-
default = ""
8+
default = ""
99
description = "Azure location"
10-
type = string
10+
type = string
1111
}
1212

1313
variable "loganalytics_workspace_name" {
14-
default = ""
15-
type = string
14+
default = ""
15+
type = string
1616
description = "Loganalytics workspace name"
1717
}
1818

1919
variable "loganalytics_retention_period" {
20-
default = 7
20+
default = 7
2121
description = "Loganalytics logs retention period"
22-
type = number
22+
type = number
2323
validation {
24-
condition = var.loganalytics_retention_period == 7 || (var.loganalytics_retention_period >= 30 && var.loganalytics_retention_period <= 730)
24+
condition = var.loganalytics_retention_period == 7 || (var.loganalytics_retention_period >= 30 && var.loganalytics_retention_period <= 730)
2525
error_message = "The workspace data retention in days. Possible values are either 7 (Free Tier only) or range between 30 and 730."
2626
}
2727

@@ -44,12 +44,23 @@ variable "environment" {
4444
}
4545

4646
variable "loganalytics_sku" {
47-
default = "PerGB2018"
48-
type = string
47+
default = "PerGB2018"
48+
type = string
4949
description = "Specifies the SKU of the Log Analytics Workspace"
5050
validation {
5151
condition = contains(["PerNode", "Premium", "Standard", "Standalone", "Unlimited", "CapacityReservation", "PerGB2018"], var.loganalytics_sku)
5252
error_message = "Log analytics SKU should be one among PerNode, Premium, Standard, Standalone, Unlimited, CapacityReservation or PerGB2018 ."
5353
}
5454
}
5555

56+
variable "temporary" {
57+
default = "TRUE"
58+
description = "Temporary tag value in Azure"
59+
type = string
60+
validation {
61+
condition = contains(["TRUE", "FALSE"], upper(var.temporary))
62+
error_message = "The temporary tag value must be either 'TRUE' or 'FALSE'."
63+
}
64+
65+
}
66+

storage-account/output.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
output "azurerm_resource_group" {
22
description = "Azure resource group name"
3-
value = azurerm_resource_group.storage_rg.name
3+
value = azurerm_resource_group.storage_rg.name
44
}
55

66
output "storage_account_name" {
77
description = "Azure storage account name"
8-
value = azurerm_storage_account.storage.name
8+
value = azurerm_storage_account.storage.name
99
}
1010

1111
output "storage_account_location" {
1212
description = "Azure storage account location"
13-
value = azurerm_storage_account.storage.location
13+
value = azurerm_storage_account.storage.location
1414
}
1515

1616
output "storage_account_delete_retention_policy" {
1717
description = "Azure blob retention policy"
18-
value = azurerm_storage_account.storage.blob_properties[0].delete_retention_policy
18+
value = azurerm_storage_account.storage.blob_properties[0].delete_retention_policy
1919
}
2020

2121
output "storage_account_tier" {
2222
description = "Azure storage account tier"
23-
value = azurerm_storage_account.storage.access_tier
23+
value = azurerm_storage_account.storage.access_tier
2424
}
2525

2626
output "storage_account_replication_type" {
2727
description = "Azure storage account replication type"
28-
value = azurerm_storage_account.storage.account_replication_type
28+
value = azurerm_storage_account.storage.account_replication_type
2929
}
3030

3131
output "storage_account_tags" {
3232
description = "Azure storage account tags"
33-
value = azurerm_storage_account.storage.tags
33+
value = azurerm_storage_account.storage.tags
3434
}

storage-account/providers.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ terraform {
33
required_providers {
44
azurerm = {
55
source = "hashicorp/azurerm"
6-
version = "~> 3.0"
6+
version = "<= 4.0"
77
}
88
random = {
99
source = "hashicorp/random"
1010
version = ">= 3.1"
1111
}
12-
}
12+
}
1313
}
1414
provider "azurerm" {
1515
features {}

storage-account/storageaccount.tf

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ resource "azurerm_resource_group" "storage_rg" {
22
name = var.resource_group_name
33
location = var.location
44
tags = {
5-
Environment = upper(var.environment)
6-
Orchestrator = "Terraform"
7-
DisplayName = upper(var.resource_group_name)
5+
Environment = upper(var.environment)
6+
Orchestrator = "Terraform"
7+
DisplayName = upper(var.resource_group_name)
88
ApplicationName = lower(var.application_name)
9+
Temporary = upper(var.temporary)
10+
911
}
1012
}
1113

1214
resource "azurerm_storage_account" "storage" {
13-
name = var.storage_account_name
14-
resource_group_name = azurerm_resource_group.storage_rg.name
15-
location = azurerm_resource_group.storage_rg.location
16-
account_tier = var.account_tier
17-
account_replication_type = var.account_replication_type
18-
account_kind = var.account_kind
15+
name = var.storage_account_name
16+
resource_group_name = azurerm_resource_group.storage_rg.name
17+
location = azurerm_resource_group.storage_rg.location
18+
account_tier = var.account_tier
19+
account_replication_type = var.account_replication_type
20+
account_kind = var.account_kind
1921
cross_tenant_replication_enabled = var.cross_tenant_replication_enabled
20-
public_network_access_enabled = var.public_network_access_enabled
22+
public_network_access_enabled = var.public_network_access_enabled
2123

2224
blob_properties {
2325
delete_retention_policy {
@@ -26,9 +28,11 @@ resource "azurerm_storage_account" "storage" {
2628
}
2729

2830
tags = {
29-
Environment = upper(var.environment)
30-
Orchestrator = "Terraform"
31-
DisplayName = upper(var.storage_account_name)
31+
Environment = upper(var.environment)
32+
Orchestrator = "Terraform"
33+
DisplayName = upper(var.storage_account_name)
3234
ApplicationName = lower(var.application_name)
35+
Temporary = upper(var.temporary)
36+
3337
}
3438
}

0 commit comments

Comments
 (0)