Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b22d911
add optional key vault id
lyudmililchev92 Jul 28, 2025
188a48d
fix private key
lyudmililchev92 Jul 28, 2025
bc543ef
fix keys
lyudmililchev92 Jul 28, 2025
b46eb1b
fix virtual machine plan settings
lyudmililchev92 Jul 28, 2025
be88c16
add sku and sku tier to public ip
lyudmililchev92 Jul 28, 2025
a8b0d4a
add domain name label to public ip
lyudmililchev92 Jul 28, 2025
456128d
add availability set id
lyudmililchev92 Jul 28, 2025
94cb27c
fix availabiolity set
lyudmililchev92 Jul 28, 2025
7833df0
add platform fault domain count
lyudmililchev92 Jul 28, 2025
2497535
add minor change in network interface inside vms
lyudmililchev92 Jul 28, 2025
a9a3a38
add admin password to linux machines
lyudmililchev92 Jul 28, 2025
6ce1280
add admin password to linux vm
lyudmililchev92 Jul 28, 2025
92b1fb7
fix secret
lyudmililchev92 Jul 28, 2025
2ebb9ef
add versioning enabled for storage account
lyudmililchev92 Jul 30, 2025
bc2ebd3
add az api resource
lyudmililchev92 Jul 30, 2025
391863a
add azapi
lyudmililchev92 Jul 30, 2025
ef4742d
add version 2.5.0
lyudmililchev92 Jul 30, 2025
4fea05c
azapi
lyudmililchev92 Jul 30, 2025
2280567
fix
lyudmililchev92 Jul 30, 2025
cff971b
add azapi
lyudmililchev92 Jul 30, 2025
2f52558
fix azapi
lyudmililchev92 Jul 30, 2025
cde3df2
add providers
lyudmililchev92 Jul 30, 2025
8640623
fix pre commit
lyudmililchev92 Jul 30, 2025
03d27d0
remove unused file
lyudmililchev92 Jul 30, 2025
b8b6eee
add agreement
lyudmililchev92 Aug 1, 2025
2bfcc17
add one more source for vnet peerings
lyudmililchev92 Aug 4, 2025
7e63dcb
add custom to the validation
lyudmililchev92 Aug 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/_provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ terraform {
source = "hashicorp/azurerm"
version = "4.33.0"
}
azapi = {
source = "Azure/azapi"
version = "2.5.0" // version
}
}
}

Expand All @@ -15,3 +19,7 @@ provider "azurerm" {
tenant_id = var.tenant_id
subscription_id = var.subscription_id
}

provider "azapi" {
# Configuration options
}
3 changes: 3 additions & 0 deletions src/modules/_networking/public_ip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ resource "azurerm_public_ip" "main" {
allocation_method = try(var.settings.allocation_method, "Static")
tags = local.tags
zones = try(var.settings.zones, null)
sku = try(var.settings.sku, null)
sku_tier = try(var.settings.sku_tier, null)
domain_name_label = try(var.settings.domain_name_label, null)
}
1 change: 1 addition & 0 deletions src/modules/_networking/vnet_peering/_locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ locals {
direction = try(var.settings.direction, "<->")
target = local.direction == "target"
source = local.direction == "source"
custom = local.direction == "custom"
Comment on lines 18 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какво е direction source, target, custom?


# These use regex to simulate startswith/endswith
peer_left_to_right = can(regex("->$", local.direction))
Expand Down
4 changes: 2 additions & 2 deletions src/modules/_networking/vnet_peering/_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ variable "settings" {
description = "All the configuration for this resource"

validation {
condition = contains(["<-", "->", "<->", "target", "source"], try(var.settings.direction, "<->"))
error_message = "Allowed values for 'direction' are '<-', '->', '<->', 'target', or 'source'. Defaults to '<->' if not set."
condition = contains(["<-", "->", "<->", "target", "source", "custom"], try(var.settings.direction, "<->"))
error_message = "Allowed values for 'direction' are '<-', '->', '<->', 'target', 'source' or 'custom' . Defaults to '<->' if not set."
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/modules/_networking/vnet_peering/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ resource "azurerm_virtual_network_peering" "target" {
use_remote_gateways = true
}

resource "azurerm_virtual_network_peering" "custom" {
count = local.custom ? 1 : 0

name = try(var.settings.custom_name, "peering-${local.vnet_right.name}")
resource_group_name = local.vnet_right.resource_group_name
virtual_network_name = local.vnet_right.name
remote_virtual_network_id = try(var.settings.remote_vnet_id, local.vnet_left.id)
allow_virtual_network_access = try(var.settings.allow_virtual_network_access, false)
allow_forwarded_traffic = try(var.settings.allow_forwarded_traffic, false)
use_remote_gateways = try(var.settings.use_remote_gateways, false)
allow_gateway_transit = try(var.settings.allow_gateway_transit, false)
}

resource "azurerm_virtual_network_peering" "source" {
count = local.source ? 1 : 0

Expand Down
1 change: 1 addition & 0 deletions src/modules/storage_account/storage_account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ resource "azurerm_storage_account" "main" {
for_each = can(var.settings.blob_properties) ? [1] : []

content {
versioning_enabled = try(var.settings.blob_properties.versioning_enabled, false)
dynamic "cors_rule" {
for_each = can(var.settings.blob_properties.cors_rule) ? [1] : []

Expand Down
28 changes: 28 additions & 0 deletions src/modules/storage_account/storage_container.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,31 @@ resource "azurerm_storage_container" "main" {

container_access_type = try(each.value.access_type, null)
}


resource "azapi_resource" "main" {
for_each = try(var.settings.api_containers, {})

type = "Microsoft.Storage/storageAccounts/blobServices/containers@2023-05-01"
name = each.value.name
parent_id = "${azurerm_storage_account.main.id}/blobServices/default"
body = {
properties = {
defaultEncryptionScope = try(each.value.default_encryption_scope, "$account-encryption-key")
denyEncryptionScopeOverride = try(each.value.deny_encryption_scope_override, false)
immutableStorageWithVersioning = {
enabled = try(each.value.enable_versioning, true)
}
publicAccess = try(each.value.public_access, "None")
}
}
}


terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}
Comment on lines +30 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define required providers in root module or where the rest of the providers have been defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not work when I define them in the root module

Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ locals {

network_interface_ids = module.network_interface.ids

key_vault_id = var.resources[
key_vault_id = try(var.resources[
try(var.settings.keyvault_lz_key, var.client_config.landingzone_key)
].keyvaults[
var.settings.keyvault_ref
].id
].id, null)

vm_keys = { for key, ssh_key in var.settings.admin_ssh_key :
vm_keys = {
for key, ssh_key in try(var.settings.admin_ssh_key, {}) :
key => tls_private_key.main[ssh_key.public_key_ref]
}

private_keys_pem = { for key, value in local.vm_keys : key => value.private_key_pem }
public_keys_openssh = { for key, value in local.vm_keys : key => value.public_key_openssh }


tags = merge(
var.global_settings.tags,
var.global_settings.inherit_resource_group_tags ? local.resource_group.tags : {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "azurerm_marketplace_agreement" "main" {
count = try(var.settings.marketplace_agreement, null) == null ? 0 : 1
publisher = var.settings.marketplace_agreement.publisher
offer = var.settings.marketplace_agreement.offer
plan = var.settings.marketplace_agreement.plan
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "azurerm_availability_set" "main" {
count = try(var.settings.availability_set, null) == null ? 0 : 1
name = try(var.settings.availability_set.name)
location = local.location
resource_group_name = local.resource_group_name
platform_fault_domain_count = try(var.settings.availability_set.platform_fault_domain_count, null)
platform_update_domain_count = try(var.settings.availability_set.platform_update_domain_count, null)
tags = local.tags
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
resource "azurerm_linux_virtual_machine" "main" {
name = var.settings.name
resource_group_name = local.resource_group_name
location = local.location
admin_username = var.settings.admin_username
size = var.settings.size
network_interface_ids = local.network_interface_ids
name = var.settings.name
resource_group_name = local.resource_group_name
location = local.location
admin_username = var.settings.admin_username
admin_password = try(random_password.admin[0].result, null)
size = var.settings.size
network_interface_ids = local.network_interface_ids
encryption_at_host_enabled = try(var.settings.encryption_at_host_enabled, null)
disable_password_authentication = try(var.settings.disable_password_authentication, null)
availability_set_id = try(one(azurerm_availability_set.main[*].id), null)


tags = local.tags

Expand All @@ -15,6 +20,14 @@ resource "azurerm_linux_virtual_machine" "main" {
public_key = tls_private_key.main[admin_ssh_key.value.public_key_ref].public_key_openssh
}
}
dynamic "plan" {
for_each = can(var.settings.plan) ? [1] : []
content {
name = var.settings.plan.name
product = var.settings.plan.product
publisher = var.settings.plan.publisher
}
}

os_disk {
caching = var.settings.os_disk.caching
Expand Down
20 changes: 20 additions & 0 deletions src/modules/virtual_machines/linux_virtual_machine/secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,23 @@ resource "azurerm_key_vault_secret" "public_keys" {
value = each.value
key_vault_id = local.key_vault_id
}


resource "random_password" "admin" {
count = try(var.settings.disable_password_authentication, false) ? 0 : 1
length = 18
min_upper = 2
min_lower = 2
min_special = 2
numeric = true
special = true
override_special = "!@#$%&"
}


resource "azurerm_key_vault_secret" "admin_password" {
count = try(var.settings.disable_password_authentication, false) ? 0 : 1
name = "${var.settings.name}-${var.settings.admin_username}"
value = random_password.admin[0].result
key_vault_id = local.key_vault_id
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "tls_private_key" "main" {
for_each = var.settings.public_key_openssh
for_each = try(var.settings.public_key_openssh, {})

algorithm = each.value.algorithm
rsa_bits = each.value.rsa_bits
Expand Down
10 changes: 6 additions & 4 deletions src/modules/virtual_machines/network_interface/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
resource "azurerm_network_interface" "main" {
for_each = var.settings.network_interfaces
name = each.value.name
resource_group_name = local.resource_group_name
location = local.location
for_each = var.settings.network_interfaces
name = each.value.name
resource_group_name = local.resource_group_name
location = local.location
accelerated_networking_enabled = try(each.value.accelerated_networking_enabled, false)
ip_forwarding_enabled = try(each.value.ip_forwarding_enabled, false)

tags = local.tags

Expand Down
Loading