Skip to content

Commit f8086c3

Browse files
author
dmytro_velychko3
committed
fix: fix variables
1 parent 3dcc320 commit f8086c3

File tree

4 files changed

+55
-47
lines changed

4 files changed

+55
-47
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,23 @@ module "linux_virtual_machine" {
5959
| <a name="input_project"></a> [project](#input\_project)| Project name | `string` | n/a | yes |
6060
| <a name="input_env"></a> [env](#input\_env)| Environment name | `string` | n/a | yes |
6161
| <a name="input_resource_group"></a> [resource\_group](#input\_resource\_group)| The name of the resource group | `string` | n/a | yes |
62-
| <a name="input_location"></a> [location](#input\_location)| Azure location | `string` | n/a | yes |
6362
| <a name="input_suffix"></a> [suffix](#input\_suffix)| Optional suffix that would be added to the end of resources names. It is recommended to use dash at the beginning of variable (e.x., '-example') | `string` | "" | no |
63+
| <a name="input_location"></a> [location](#input\_location)| Azure location | `string` | n/a | yes |
6464
| <a name="input_custom_virtual_machine_name"></a> [custom\_virtual\_machine\_name](#input\_custom\_virtual\_machine\_name)| Specifies the name of the virtual machine name resource | `string` | null | no |
6565
| <a name="input_custom_network_interface_name"></a> [custom\_network\_interface\_name](#input\_custom\_network\_interface\_name)| Specifies the name of the virtual machine interface name resource | `string` | null | no |
6666
| <a name="input_custom_public_ip_name"></a> [custom\_public\_ip\_name](#input\_custom\_public\_ip\_name)| Specifies the name of the public ip name name resource | `string` | null | no |
6767
| <a name="input_tags"></a> [tags](#input\_tags)| Resource tags | map(any) | {} | no |
6868
| <a name="input_public_ip_allocation_method"></a> [public\_ip\_allocation\_method](#input\_public\_ip\_allocation_method)| Defines the allocation method for this IP address. Possible values are Static or Dynamic | map(any) | Dynamic | no |
6969
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id)| The ID of the Subnet where this Network Interface should be located in. | `string` | n/a | yes |
7070
| <a name="input_network_interface"></a> [network\_interface](#input\_network\_interface)| Objects to configure network interface | <pre>object({<br> private_ip_address_allocation = string<br> public_ip_enabled = bool<br>})</pre> | <pre>{<br> private_ip_address_allocation = "Dynamic"<br> public_ip_enabled = true<br>}</pre> | no |
71-
| <a name="input_virtual_machine"></a> [virtual\_machine](#input\_virtual\_machine)| Objects to configure virtual_machine | <pre>object({<br> size = string<br> admin_username = string<br>})</pre> | <pre>{<br> size = "Standard_F2"<br> admin_username = "adminuser"<br>}</pre> | no |
71+
| <a name="input_vm_size"></a> [vm\_size](#input\_vm\_size)| The SKU which should be used for this Virtual Machine. | `string` | Standard_F2 | no |
72+
| <a name="input_vm_admin_username"></a> [vm\_admin\_username](#input\_vm\_admin\_username)| The username of the local administrator used for the Virtual Machine. | `string` | adminuser | no |
73+
| <a name="input_vm_admin_password"></a> [vm\_admin\_password](#input\_vm\_admin\_password)| The password of the local administrator used for the Virtual Machine. | `string` | null | no |
7274
| <a name="input_admin_ssh_key"></a> [admin\_ssh\_key](#input\_admin\_ssh\_key)| Objects to configure ssh key reference for virtual machine | <pre>object({<br> username = string<br> public_key = string<br>})</pre> | n/a | yes |
7375
| <a name="input_os_disk"></a> [os\_disk](#input\_os\_disk)| Objects to configure os disk reference for virtual machine | <pre>object({<br> caching = string<br> storage_account_type = string<br>})</pre> | <pre>{<br> caching = "ReadWrite"<br> storage_account_type = "Standard_LRS"<br>}</pre> | no |
7476
| <a name="input_source_image_reference"></a> [source\_image\_reference](#input\_source\_image\_reference)| Objects to configure source image reference for virtual machine | <pre>object({<br> publisher = string<br> offer = string<br> sku = string<br> version = string<br>})</pre> | <pre>{<br> publisher = "Canonical"<br> offer = "0001-com-ubuntu-server-focal"<br> sku = "20_04-lts"<br> version = "latest"<br>}</pre> | no |
75-
| <a name="input_password_access_enable"></a> [password\_access\_enable](#input\_password\_access\_enable)| Password access enable | `bool` | true | no |
77+
| <a name="input_identity_enabled"></a> [identity\_enabled](#input\_identity\_enabled)| identity enabled | `bool` | false | no |
78+
| <a name="input_password_access_enabled"></a> [password\_access\_enabled](#input\_password\_access\_enabled)| Vm password access enabled | `bool` | false | no |
7679
7780
## Modules
7881

@@ -92,8 +95,7 @@ No modules.
9295
| Name | Description |
9396
| ----------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
9497
| <a name="output_id"></a> [id](#output\_id) | The ID of the Linux Virtual Machine |
95-
| <a name="output_identity"></a> [identity](#output\_identity) | linux virtual machine identity |
96-
| <a name="output_password"></a> [password](#output\_password) | The password of the Linux Virtual Machine |
98+
| <a name="output_access_connector_identity"></a> [access\_connector\_identity](#output\_access\_connector\_identity) | linux virtual machine identity |
9799
<!-- END_TF_DOCS -->
98100

99101
## License

main.tf

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
locals {
22
suffix = length(var.suffix) == 0 ? "" : "-${var.suffix}"
3-
virtual_machine_name = var.custom_virtual_machine_name == null ? "wm-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_virtual_machine_name}${local.suffix}"
3+
virtual_machine_name = var.custom_virtual_machine_name == null ? "vm-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_virtual_machine_name}${local.suffix}"
44
network_interface_name = var.custom_network_interface_name == null ? "nic-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_network_interface_name}${local.suffix}"
55
public_ip = var.custom_public_ip_name == null ? "ip-${var.project}-${var.env}-${var.location}${local.suffix}" : "${var.custom_public_ip_name}${local.suffix}"
66
}
77

8-
resource "random_string" "this" {
9-
count = var.password_access_enable ? 1 : 0
10-
11-
length = 16
12-
special = true
13-
override_special = "/@£I"
14-
}
15-
168
resource "azurerm_public_ip" "this" {
179
count = var.network_interface.public_ip_enabled ? 1 : 0
1810

1911
name = local.public_ip
2012
resource_group_name = var.resource_group
2113
location = var.location
22-
allocation_method = var.allocation_method
14+
allocation_method = var.public_ip_allocation_method
2315
}
2416

2517
resource "azurerm_network_interface" "this" {
@@ -40,22 +32,29 @@ resource "azurerm_linux_virtual_machine" "this" {
4032
name = local.virtual_machine_name
4133
resource_group_name = var.resource_group
4234
location = var.location
43-
size = var.virtual_machine.size
44-
admin_username = var.virtual_machine.admin_username
35+
size = var.vm_size
36+
admin_username = var.vm_admin_username
4537
tags = var.tags
4638
network_interface_ids = [azurerm_network_interface.this.id, ]
47-
disable_password_authentication = var.password_access_enable ? false : true
48-
admin_password = var.password_access_enable ? random_string.this[0].result : null
39+
admin_password = var.vm_admin_password
40+
disable_password_authentication = var.password_access_enabled ? false : true
4941

50-
identity {
51-
type = "SystemAssigned"
52-
}
42+
dynamic "identity" {
43+
for_each = var.identity_enabled ? [1] : []
5344

54-
admin_ssh_key {
55-
username = var.password_access_enable ? null : var.admin_ssh_key.username
56-
public_key = var.password_access_enable ? null : var.admin_ssh_key.public_key
45+
content {
46+
type = "SystemAssigned"
47+
}
5748
}
5849

50+
dynamic "admin_ssh_key" {
51+
for_each = var.password_access_enabled ? [] : [1]
52+
53+
content {
54+
username = var.admin_ssh_key.username
55+
public_key = var.admin_ssh_key.public_key
56+
}
57+
}
5958

6059
os_disk {
6160
caching = var.os_disk.caching

outputs.tf

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

66
output "access_connector_identity" {
7-
value = azurerm_linux_virtual_machine.this.identity[0].principal_id
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 "password" {
12-
value = var.password_access_enable ? random_string.this[0].result : ""
13-
description = "The password of the Linux Virtual Machine"
14-
}

variables.tf

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

51-
variable "allocation_method" {
51+
variable "public_ip_allocation_method" {
5252
type = string
5353
description = "Defines the allocation method for this IP address. Possible values are Static or Dynamic"
5454
default = "Dynamic"
@@ -71,22 +71,28 @@ variable "network_interface" {
7171
}
7272
}
7373

74-
variable "virtual_machine" {
75-
type = object({
76-
size = string
77-
admin_username = string
78-
})
79-
description = "Objects to configure virtual_machine"
80-
default = {
81-
size = "Standard_F2"
82-
admin_username = "adminuser"
83-
}
74+
variable "vm_size" {
75+
type = string
76+
description = "The SKU which should be used for this Virtual Machine."
77+
default = "Standard_F2"
78+
}
79+
80+
variable "vm_admin_username" {
81+
type = string
82+
description = "The username of the local administrator used for the Virtual Machine."
83+
default = "adminuser"
84+
}
85+
86+
variable "vm_admin_password" {
87+
type = string
88+
description = "The username of the local administrator used for the Virtual Machine."
89+
default = null
8490
}
8591

8692
variable "admin_ssh_key" {
8793
type = object({
88-
username = string
89-
public_key = string
94+
username = optional(string, "adminuser")
95+
public_key = optional(string)
9096
})
9197
description = "Objects to configure ssh key reference for virtual machine"
9298
}
@@ -119,8 +125,14 @@ variable "source_image_reference" {
119125
}
120126
}
121127

122-
variable "password_access_enable" {
128+
variable "identity_enabled" {
129+
type = bool
130+
description = "identity enabled"
131+
default = false
132+
}
133+
134+
variable "password_access_enabled" {
123135
type = bool
124-
description = "Password access enable"
125-
default = true
136+
description = "Vm password access enabled"
137+
default = false
126138
}

0 commit comments

Comments
 (0)