Skip to content

Commit 2c9cd7e

Browse files
committed
provider update | jumpbox module
1 parent 31ce642 commit 2c9cd7e

File tree

7 files changed

+192
-20
lines changed

7 files changed

+192
-20
lines changed

modules/jumpbox-vm/main.tf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
resource "azurerm_network_interface" "public" {
2+
name = var.network_interface_name
3+
location = var.resource_group_location
4+
resource_group_name = var.resource_group_name
5+
6+
ip_configuration {
7+
name = var.ip_configuration_name
8+
subnet_id = var.subnet_id
9+
private_ip_address_allocation = "Dynamic"
10+
}
11+
}
12+
13+
data "azurerm_image" "search" {
14+
name = var.custom_image_sku
15+
resource_group_name = var.custom_image_resource_group_name
16+
}
17+
18+
# Assume a Linux VM with a user-assigned managed identity
19+
resource "azurerm_user_assigned_identity" "vm_mi" {
20+
name = "vm-mi-d01"
21+
resource_group_name = var.resource_group_name
22+
location = var.resource_group_location
23+
}
24+
25+
resource "azurerm_virtual_machine" "public" {
26+
name = var.vm_name
27+
location = var.resource_group_location
28+
resource_group_name = var.resource_group_name
29+
network_interface_ids = [azurerm_network_interface.public.id]
30+
vm_size = var.vm_size
31+
32+
delete_os_disk_on_termination = true
33+
34+
storage_image_reference {
35+
id = data.azurerm_image.search.id
36+
}
37+
38+
identity {
39+
type = "UserAssigned"
40+
identity_ids = [azurerm_user_assigned_identity.vm_mi.id]
41+
}
42+
43+
storage_os_disk {
44+
name = var.storage_os_disk_name
45+
caching = var.storage_os_disk_caching
46+
create_option = var.storage_os_disk_create_option
47+
managed_disk_type = var.storage_os_disk_managed_disk_type
48+
}
49+
50+
os_profile_linux_config {
51+
disable_password_authentication = false
52+
}
53+
54+
os_profile {
55+
computer_name = var.os_profile_computer_name
56+
admin_username = var.os_profile_admin_username
57+
admin_password = var.os_profile_admin_password
58+
}
59+
60+
depends_on = [
61+
azurerm_network_interface_security_group_association.nic_association
62+
]
63+
}
64+
65+
resource "azurerm_network_interface_security_group_association" "nic_association" {
66+
network_interface_id = azurerm_network_interface.public.id
67+
network_security_group_id = var.network_security_group_id
68+
}

modules/jumpbox-vm/output.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
output "username" {
2+
value = var.os_profile_admin_username
3+
}
4+
5+
output "password" {
6+
value = var.os_profile_admin_password
7+
sensitive = true
8+
}
9+
10+
output "network_interface_id" {
11+
value = azurerm_network_interface.public.id
12+
}
13+
14+
output "ip_configuration_name" {
15+
value = var.ip_configuration_name
16+
}
17+
18+
output "id" {
19+
value = azurerm_virtual_machine.public.id
20+
}
21+
22+
output "user_assigned_identity_principal_id" {
23+
value = azurerm_user_assigned_identity.vm_mi.principal_id
24+
}

modules/jumpbox-vm/variables.tf

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#################################################################################################################
2+
# REQUIRED VARIABLES
3+
#################################################################################################################
4+
5+
variable "resource_group_name" {
6+
type = string
7+
description = "The name of the Azure resource group in which resources will be deployed."
8+
}
9+
10+
variable "resource_group_location" {
11+
type = string
12+
description = "The Azure region where the resource group will be created."
13+
}
14+
15+
variable "subnet_id" {
16+
type = string
17+
description = "The ID of the subnet where the virtual machine will be deployed."
18+
}
19+
20+
variable "network_interface_name" {
21+
type = string
22+
description = "The name of the network interface to associate with the virtual machine."
23+
}
24+
25+
variable "ip_configuration_name" {
26+
type = string
27+
description = "The name of the IP configuration for the network interface."
28+
}
29+
30+
variable "vm_name" {
31+
type = string
32+
description = "The name of the virtual machine instance."
33+
}
34+
35+
variable "storage_os_disk_name" {
36+
type = string
37+
description = "The name assigned to the OS disk."
38+
}
39+
40+
variable "os_profile_computer_name" {
41+
type = string
42+
description = "The hostname of the virtual machine."
43+
}
44+
45+
variable "os_profile_admin_username" {
46+
type = string
47+
description = "The administrator username for the virtual machine."
48+
}
49+
50+
variable "os_profile_admin_password" {
51+
type = string
52+
description = "The administrator password for the virtual machine. Use environment variables or a secret manager instead."
53+
}
54+
55+
variable "network_security_group_id" {
56+
type = string
57+
description = "ID of network security group"
58+
}
59+
60+
#################################################################################################################
61+
# OPTIONAL VARIABLES (WITH DEFAULT VALUES)
62+
#################################################################################################################
63+
64+
variable "vm_size" {
65+
type = string
66+
description = "Specifies the size of the virtual machine."
67+
default = "Standard_B4ms"
68+
}
69+
70+
variable "storage_os_disk_caching" {
71+
type = string
72+
description = "Defines the caching policy for the OS disk (e.g., ReadOnly, ReadWrite)."
73+
default = "ReadWrite"
74+
}
75+
76+
variable "storage_os_disk_create_option" {
77+
type = string
78+
description = "Determines how the OS disk should be created (e.g., FromImage, Attach, Empty)."
79+
default = "FromImage"
80+
}
81+
82+
variable "storage_os_disk_managed_disk_type" {
83+
type = string
84+
description = "Defines the type of managed disk for the OS disk (e.g., Premium_LRS, Standard_LRS)."
85+
default = "Premium_LRS"
86+
}
87+
88+
variable "custom_image_sku" {
89+
type = string
90+
description = "The custom image SKU (name)."
91+
}
92+
93+
variable "custom_image_resource_group_name" {
94+
type = string
95+
description = "The custom image resource group."
96+
}

modules/module/main.tf

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

modules/module/output.tf

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

modules/module/variables.tf

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

provider.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ provider "azurerm" {
33
resource_group {
44
prevent_deletion_if_contains_resources = false
55
}
6+
key_vault {
7+
purge_soft_delete_on_destroy = true
8+
recover_soft_deleted_key_vaults = true
9+
}
610
}
711
subscription_id = var.subscription_id
812
}

0 commit comments

Comments
 (0)