Skip to content

Commit bad56bc

Browse files
Password and SSH bug fixes (#110)
1 parent 54b05c4 commit bad56bc

23 files changed

Lines changed: 624 additions & 30 deletions

.terraform-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
formatter: "markdown document" # this is required
66

7-
version: "~> 0.17.0"
7+
version: "~> 0.18.0"
88

99
header-from: "_header.md"
1010
footer-from: "_footer.md"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ Default: `{}`
660660

661661
### <a name="input_disable_password_authentication"></a> [disable\_password\_authentication](#input\_disable\_password\_authentication)
662662

663-
Description: If true this value will disallow password authentication on linux vm's. This will require at least one public key to be configured.
663+
Description: If true this value will disallow password authentication on linux vm's. This will require at least one public key to be configured. If using the option to auto generate passwords and keys, setting this value to `false` will cause a password to be generated an stored instead of an SSH key.
664664

665665
Type: `bool`
666666

@@ -849,7 +849,7 @@ Default: `{}`
849849

850850
### <a name="input_generate_admin_password_or_ssh_key"></a> [generate\_admin\_password\_or\_ssh\_key](#input\_generate\_admin\_password\_or\_ssh\_key)
851851

852-
Description: Set this value to true if the deployment should create a strong password for the admin user.
852+
Description: Set this value to true if the deployment should create a strong password for the admin user. If `os_type` is Linux, this will generate and store an SSH key as the default. However, setting `disable_password_authentication` to `false` will generate and store a password value instead of an ssh key.
853853

854854
Type: `bool`
855855

examples/.terraform-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
formatter: "markdown document" # this is required
66

7-
version: "~> 0.17.0"
7+
version: "~> 0.18.0"
88

99
header-from: "_header.md"
1010
footer-from: "_footer.md"

examples/basic_windows_w_encryption_at_host/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ module "avm_res_keyvault_vault" {
177177
}
178178
179179
resource "azurerm_disk_encryption_set" "this" {
180-
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
181180
location = azurerm_resource_group.this_rg.location
182181
name = module.naming.disk_encryption_set.name_unique
183182
resource_group_name = azurerm_resource_group.this_rg.name
183+
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
184184
tags = local.tags
185185
186186
identity {

examples/basic_windows_w_encryption_at_host/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ module "avm_res_keyvault_vault" {
155155
}
156156

157157
resource "azurerm_disk_encryption_set" "this" {
158-
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
159158
location = azurerm_resource_group.this_rg.location
160159
name = module.naming.disk_encryption_set.name_unique
161160
resource_group_name = azurerm_resource_group.this_rg.name
161+
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
162162
tags = local.tags
163163

164164
identity {

examples/common_ubuntu_w_ssh_auth/README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,34 +86,34 @@ resource "azurerm_subnet" "this_subnet_2" {
8686
virtual_network_name = azurerm_virtual_network.this_vnet.name
8787
}
8888
89-
/* Uncomment this section if you would like to include a bastion resource with this example.
89+
#Uncomment this section if you would like to include a bastion resource with this example.
9090
resource "azurerm_subnet" "bastion_subnet" {
91+
address_prefixes = ["10.0.3.0/24"]
9192
name = "AzureBastionSubnet"
9293
resource_group_name = azurerm_resource_group.this_rg.name
9394
virtual_network_name = azurerm_virtual_network.this_vnet.name
94-
address_prefixes = ["10.0.3.0/24"]
9595
}
9696
9797
resource "azurerm_public_ip" "bastionpip" {
98-
name = module.naming.public_ip.name_unique
98+
allocation_method = "Static"
9999
location = azurerm_resource_group.this_rg.location
100+
name = module.naming.public_ip.name_unique
100101
resource_group_name = azurerm_resource_group.this_rg.name
101-
allocation_method = "Static"
102102
sku = "Standard"
103103
}
104104
105105
resource "azurerm_bastion_host" "bastion" {
106-
name = module.naming.bastion_host.name_unique
107106
location = azurerm_resource_group.this_rg.location
107+
name = module.naming.bastion_host.name_unique
108108
resource_group_name = azurerm_resource_group.this_rg.name
109109
110110
ip_configuration {
111111
name = "${module.naming.bastion_host.name_unique}-ipconf"
112-
subnet_id = azurerm_subnet.bastion_subnet.id
113112
public_ip_address_id = azurerm_public_ip.bastionpip.id
113+
subnet_id = azurerm_subnet.bastion_subnet.id
114114
}
115115
}
116-
*/
116+
117117
118118
119119
data "azurerm_client_config" "current" {}
@@ -197,11 +197,26 @@ resource "azurerm_key_vault_secret" "admin_ssh_key" {
197197
]
198198
}
199199
200+
resource "tls_private_key" "this_2" {
201+
algorithm = "RSA"
202+
rsa_bits = 4096
203+
}
204+
205+
resource "azurerm_key_vault_secret" "admin_ssh_key_2" {
206+
key_vault_id = module.avm_res_keyvault_vault.resource_id
207+
name = "azureuser-ssh-private-key-2"
208+
value = tls_private_key.this_2.private_key_pem
209+
210+
depends_on = [
211+
module.avm_res_keyvault_vault
212+
]
213+
}
214+
200215
resource "azurerm_disk_encryption_set" "this" {
201-
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
202216
location = azurerm_resource_group.this_rg.location
203217
name = module.naming.disk_encryption_set.name_unique
204218
resource_group_name = azurerm_resource_group.this_rg.name
219+
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
205220
tags = local.tags
206221
207222
identity {
@@ -230,6 +245,10 @@ module "testvm" {
230245
{
231246
public_key = tls_private_key.this.public_key_openssh
232247
username = "azureuser" #the username must match the admin_username currently.
248+
},
249+
{
250+
public_key = tls_private_key.this_2.public_key_openssh
251+
username = "azureuser" #the username must match the admin_username currently.
233252
}
234253
]
235254
@@ -339,17 +358,22 @@ The following requirements are needed by this module:
339358

340359
The following resources are used by this module:
341360

361+
- [azurerm_bastion_host.bastion](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/bastion_host) (resource)
342362
- [azurerm_disk_encryption_set.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/disk_encryption_set) (resource)
343363
- [azurerm_key_vault_secret.admin_ssh_key](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) (resource)
364+
- [azurerm_key_vault_secret.admin_ssh_key_2](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/key_vault_secret) (resource)
365+
- [azurerm_public_ip.bastionpip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) (resource)
344366
- [azurerm_resource_group.this_rg](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
345367
- [azurerm_resource_group.this_rg_secondary](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) (resource)
368+
- [azurerm_subnet.bastion_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) (resource)
346369
- [azurerm_subnet.this_subnet_1](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) (resource)
347370
- [azurerm_subnet.this_subnet_2](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) (resource)
348371
- [azurerm_user_assigned_identity.example_identity](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/user_assigned_identity) (resource)
349372
- [azurerm_virtual_network.this_vnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) (resource)
350373
- [random_integer.region_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource)
351374
- [random_integer.zone_index](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) (resource)
352375
- [tls_private_key.this](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) (resource)
376+
- [tls_private_key.this_2](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) (resource)
353377
- [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/client_config) (data source)
354378

355379
<!-- markdownlint-disable MD013 -->

examples/common_ubuntu_w_ssh_auth/main.tf

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,34 @@ resource "azurerm_subnet" "this_subnet_2" {
6464
virtual_network_name = azurerm_virtual_network.this_vnet.name
6565
}
6666

67-
/* Uncomment this section if you would like to include a bastion resource with this example.
67+
#Uncomment this section if you would like to include a bastion resource with this example.
6868
resource "azurerm_subnet" "bastion_subnet" {
69+
address_prefixes = ["10.0.3.0/24"]
6970
name = "AzureBastionSubnet"
7071
resource_group_name = azurerm_resource_group.this_rg.name
7172
virtual_network_name = azurerm_virtual_network.this_vnet.name
72-
address_prefixes = ["10.0.3.0/24"]
7373
}
7474

7575
resource "azurerm_public_ip" "bastionpip" {
76-
name = module.naming.public_ip.name_unique
76+
allocation_method = "Static"
7777
location = azurerm_resource_group.this_rg.location
78+
name = module.naming.public_ip.name_unique
7879
resource_group_name = azurerm_resource_group.this_rg.name
79-
allocation_method = "Static"
8080
sku = "Standard"
8181
}
8282

8383
resource "azurerm_bastion_host" "bastion" {
84-
name = module.naming.bastion_host.name_unique
8584
location = azurerm_resource_group.this_rg.location
85+
name = module.naming.bastion_host.name_unique
8686
resource_group_name = azurerm_resource_group.this_rg.name
8787

8888
ip_configuration {
8989
name = "${module.naming.bastion_host.name_unique}-ipconf"
90-
subnet_id = azurerm_subnet.bastion_subnet.id
9190
public_ip_address_id = azurerm_public_ip.bastionpip.id
91+
subnet_id = azurerm_subnet.bastion_subnet.id
9292
}
9393
}
94-
*/
94+
9595

9696

9797
data "azurerm_client_config" "current" {}
@@ -175,11 +175,26 @@ resource "azurerm_key_vault_secret" "admin_ssh_key" {
175175
]
176176
}
177177

178+
resource "tls_private_key" "this_2" {
179+
algorithm = "RSA"
180+
rsa_bits = 4096
181+
}
182+
183+
resource "azurerm_key_vault_secret" "admin_ssh_key_2" {
184+
key_vault_id = module.avm_res_keyvault_vault.resource_id
185+
name = "azureuser-ssh-private-key-2"
186+
value = tls_private_key.this_2.private_key_pem
187+
188+
depends_on = [
189+
module.avm_res_keyvault_vault
190+
]
191+
}
192+
178193
resource "azurerm_disk_encryption_set" "this" {
179-
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
180194
location = azurerm_resource_group.this_rg.location
181195
name = module.naming.disk_encryption_set.name_unique
182196
resource_group_name = azurerm_resource_group.this_rg.name
197+
key_vault_key_id = module.avm_res_keyvault_vault.keys_resource_ids.des_key.id
183198
tags = local.tags
184199

185200
identity {
@@ -208,6 +223,10 @@ module "testvm" {
208223
{
209224
public_key = tls_private_key.this.public_key_openssh
210225
username = "azureuser" #the username must match the admin_username currently.
226+
},
227+
{
228+
public_key = tls_private_key.this_2.public_key_openssh
229+
username = "azureuser" #the username must match the admin_username currently.
211230
}
212231
]
213232

0 commit comments

Comments
 (0)