Skip to content

Commit 8579486

Browse files
committed
fix: refactored variables; updated description
1 parent ba62086 commit 8579486

File tree

3 files changed

+32
-37
lines changed

3 files changed

+32
-37
lines changed

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ locals {
66
}
77

88
resource "azurerm_public_ip" "this" {
9-
count = var.network_interface.public_ip_enabled ? 1 : 0
9+
count = var.public_ip_enabled ? 1 : 0
1010

1111
name = local.public_ip
1212
resource_group_name = var.resource_group
@@ -23,8 +23,8 @@ resource "azurerm_network_interface" "this" {
2323
ip_configuration {
2424
name = "ip-config-${var.project}-${var.env}-${var.location}"
2525
subnet_id = var.subnet_id
26-
private_ip_address_allocation = var.network_interface.private_ip_address_allocation
27-
public_ip_address_id = var.network_interface.public_ip_enabled ? azurerm_public_ip.this[0].id : null
26+
private_ip_address_allocation = var.network_interface_private_ip_address_allocation
27+
public_ip_address_id = try(azurerm_public_ip.this[0].id, null)
2828
}
2929
}
3030

@@ -35,7 +35,7 @@ resource "azurerm_linux_virtual_machine" "this" {
3535
size = var.vm_size
3636
admin_username = var.vm_admin_username
3737
tags = var.tags
38-
network_interface_ids = [azurerm_network_interface.this.id, ]
38+
network_interface_ids = [azurerm_network_interface.this.id]
3939
admin_password = var.vm_admin_password
4040
disable_password_authentication = var.password_access_enabled ? false : true
4141

outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ output "id" {
44
}
55

66
output "identity" {
7-
value = try(azurerm_linux_virtual_machine.this.identity[0].principal_id, null)
7+
value = var.identity_enabled ? azurerm_linux_virtual_machine.this.identity : [] #[0].principal_id : ""
88
description = "linux virtual machine Identities list"
99
}
10+
11+
output "public_ip" {
12+
value = azurerm_public_ip.this[0].ip_address
13+
description = "Linux Virtual Machine public IP address"
14+
}

variables.tf

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,27 @@ variable "tags" {
4848
default = {}
4949
}
5050

51+
variable "subnet_id" {
52+
type = string
53+
description = "The ID of the Subnet where this Network Interface should be located in."
54+
}
55+
56+
variable "public_ip_enabled" {
57+
type = bool
58+
description = "Boolean flag to enable Public Ip address creation and assignment to Virtual Machine"
59+
default = true
60+
}
61+
5162
variable "public_ip_allocation_method" {
5263
type = string
5364
description = "Defines the allocation method for this IP address. Possible values are Static or Dynamic"
5465
default = "Dynamic"
5566
}
5667

57-
variable "subnet_id" {
68+
variable "network_interface_private_ip_address_allocation" {
5869
type = string
59-
description = "The ID of the Subnet where this Network Interface should be located in."
60-
}
61-
62-
variable "network_interface" {
63-
type = object({
64-
private_ip_address_allocation = string
65-
public_ip_enabled = bool
66-
})
67-
description = "Objects to configure network interface"
68-
default = {
69-
private_ip_address_allocation = "Dynamic"
70-
public_ip_enabled = true
71-
}
70+
description = "The allocation method used for the Private IP Address."
71+
default = "Dynamic"
7272
}
7373

7474
variable "vm_size" {
@@ -99,40 +99,30 @@ variable "admin_ssh_key" {
9999

100100
variable "os_disk" {
101101
type = object({
102-
caching = string
103-
storage_account_type = string
102+
caching = optional(string, "ReadWrite")
103+
storage_account_type = optional(string, "Standard_LRS")
104104
})
105105
description = "Objects to configure os disk reference for virtual machine"
106-
default = {
107-
caching = "ReadWrite"
108-
storage_account_type = "Standard_LRS"
109-
}
110106
}
111107

112108
variable "source_image_reference" {
113109
type = object({
114-
publisher = string
115-
offer = string
116-
sku = string
117-
version = string
110+
publisher = optional(string, "Canonical")
111+
offer = optional(string, "0001-com-ubuntu-server-focal")
112+
sku = optional(string, "20_04-lts")
113+
version = optional(string, "latest")
118114
})
119115
description = "Objects to configure source image reference for virtual machine"
120-
default = {
121-
publisher = "Canonical"
122-
offer = "0001-com-ubuntu-server-focal"
123-
sku = "20_04-lts"
124-
version = "latest"
125-
}
126116
}
127117

128118
variable "identity_enabled" {
129119
type = bool
130-
description = "identity enabled"
120+
description = "Boolean flag than enables creation of System Assigned identity to VM"
131121
default = false
132122
}
133123

134124
variable "password_access_enabled" {
135125
type = bool
136-
description = "Vm password access enabled"
126+
description = "Boolean flag that enables access using password"
137127
default = false
138128
}

0 commit comments

Comments
 (0)