Skip to content

Commit 37adee6

Browse files
DEVOPS-304 azure container registry terraform module (#18)
1 parent fbde51e commit 37adee6

File tree

4 files changed

+191
-0
lines changed

4 files changed

+191
-0
lines changed

container-registry/acr.tf

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
resource "azurerm_resource_group" "acr_rg" {
2+
name = var.resource_group_name
3+
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+
}
11+
}
12+
13+
14+
resource "azurerm_container_registry" "acr" {
15+
name = var.container_registry_name
16+
resource_group_name = azurerm_resource_group.acr_rg.name
17+
location = azurerm_resource_group.acr_rg.location
18+
sku = var.sku_name
19+
20+
dynamic "georeplications" {
21+
for_each = var.georeplications
22+
content {
23+
location = georeplications.value.location
24+
zone_redundancy_enabled = var.sku_name == "Premium" ? georeplications.value.zone_redundancy_enabled : false
25+
tags = {
26+
Environment = upper(var.environment)
27+
Orchestrator = "Terraform"
28+
DisplayName = "replication-${upper(var.container_registry_name)}"
29+
ApplicationName = lower(var.application_name)
30+
Temporary = upper(var.temporary)
31+
}
32+
}
33+
}
34+
35+
retention_policy_in_days = var.sku_name == "Premium" ? var.container_registry_config.retention_policy_in_days : null
36+
public_network_access_enabled = var.container_registry_config.public_network_access_enabled
37+
quarantine_policy_enabled = var.sku_name == "Premium" ? var.container_registry_config.quarantine_policy_enabled : false
38+
zone_redundancy_enabled = var.sku_name == "Premium" ? var.container_registry_config.zone_redundancy_enabled : false
39+
admin_enabled = var.container_registry_config.admin_enabled
40+
anonymous_pull_enabled = var.sku_name != "Basic" ? var.container_registry_config.anonymous_pull_enabled : false
41+
data_endpoint_enabled = var.sku_name == "Premium" ? var.container_registry_config.data_endpoint_enabled : false
42+
trust_policy_enabled = var.sku_name == "Premium" ? var.container_registry_config.trust_policy_enabled : false
43+
44+
network_rule_bypass_option = var.azure_services_bypass
45+
tags = {
46+
Environment = upper(var.environment)
47+
Orchestrator = "Terraform"
48+
DisplayName = upper(var.container_registry_name)
49+
ApplicationName = lower(var.application_name)
50+
Temporary = upper(var.temporary)
51+
}
52+
}

container-registry/outputs.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
output "container_registry_name" {
2+
description = "Azure container registry name"
3+
value = azurerm_container_registry.acr.name
4+
}
5+
6+
output "acr_rg" {
7+
description = "Azure container registry RG"
8+
value = azurerm_resource_group.acr_rg.name
9+
}
10+
11+
output "acr_login_server" {
12+
description = "The URL that can be used to log into the container registry"
13+
value = azurerm_container_registry.acr.login_server
14+
}
15+
16+
output "acr_admin_enabled" {
17+
description = "Admin user is enabled for acr or not"
18+
value = azurerm_container_registry.acr.admin_enabled
19+
}
20+
21+
output "acr_admin_username" {
22+
description = "Username associated with the Container Registry Admin account - if the admin account is enabled"
23+
value = azurerm_container_registry.acr.admin_username
24+
depends_on = [azurerm_container_registry.acr]
25+
}
26+
27+
output "acr_admin_password" {
28+
description = " Password associated with the Container Registry Admin account - if the admin account is enabled"
29+
value = nonsensitive(azurerm_container_registry.acr.admin_password)
30+
depends_on = [azurerm_container_registry.acr]
31+
sensitive = false
32+
}
33+
34+
output "acr_anonymous_pull_enabled" {
35+
description = "Anonymous pull is enabled on ACR or not"
36+
value = azurerm_container_registry.acr.anonymous_pull_enabled
37+
}

container-registry/providers.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
terraform {
2+
required_version = "~> 1.3"
3+
required_providers {
4+
azurerm = {
5+
source = "hashicorp/azurerm"
6+
version = "<= 4.0"
7+
}
8+
}
9+
}
10+
provider "azurerm" {
11+
features {}
12+
}

container-registry/variables.tf

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
variable "resource_group_name" {
2+
type = string
3+
description = "Azure container registry Rg"
4+
default = ""
5+
}
6+
7+
variable "location" {
8+
type = string
9+
description = "Azure container registry location"
10+
default = ""
11+
}
12+
13+
variable "container_registry_name" {
14+
description = "Azure container registry name"
15+
type = string
16+
default = ""
17+
18+
}
19+
20+
variable "sku_name" {
21+
default = "Basic"
22+
description = "Container registry SKUs available in Azure. Valid options are Basic, Standard or Premium"
23+
validation {
24+
condition = contains(["Basic", "Standard", "Premium"], var.sku_name)
25+
error_message = "Container registry SKU should be one among Basic, Standard or Premium"
26+
}
27+
}
28+
29+
variable "environment" {
30+
default = "DEV"
31+
description = "Environment tag value in Azure"
32+
type = string
33+
validation {
34+
condition = contains(["DEV", "QA", "UAT", "PROD"], var.environment)
35+
error_message = "Environment value should be one among DEV or QA or UAT or PROD."
36+
}
37+
}
38+
39+
variable "application_name" {
40+
default = "devwithkrishna"
41+
description = "Azure application name tag"
42+
}
43+
44+
variable "temporary" {
45+
default = "TRUE"
46+
description = "Temporary tag value in Azure"
47+
type = string
48+
validation {
49+
condition = contains(["TRUE", "FALSE"], upper(var.temporary))
50+
error_message = "The temporary tag value must be either 'TRUE' or 'FALSE'."
51+
}
52+
53+
}
54+
55+
# Container registry extra config
56+
variable "container_registry_config" {
57+
type = object({
58+
admin_enabled = optional(bool)
59+
quarantine_policy_enabled = optional(bool)
60+
zone_redundancy_enabled = optional(bool)
61+
public_network_access_enabled = optional(bool)
62+
retention_policy_in_days = optional(number)
63+
trust_policy_enabled = optional(bool)
64+
anonymous_pull_enabled = optional(bool)
65+
data_endpoint_enabled = optional(bool)
66+
})
67+
description = "Manages an Azure Container Registry"
68+
}
69+
70+
#azure_service_bypass
71+
variable "azure_services_bypass" {
72+
type = string
73+
default = "AzureServices"
74+
description = "Whether to allow trusted Azure services to access a network restricted Container Registry? Possible values are None and AzureServices. Defaults to AzureServices"
75+
validation {
76+
condition = contains(["None", "AzureServices"], var.azure_services_bypass)
77+
error_message = "Possible values are None or AzureServices"
78+
}
79+
}
80+
81+
# Acr geo replication config
82+
variable "georeplications" {
83+
description = "A list of Azure locations where the container registry should be geo-replicated"
84+
type = list(object({
85+
location = string
86+
zone_redundancy_enabled = optional(bool)
87+
}))
88+
default = []
89+
90+
}

0 commit comments

Comments
 (0)