Created
November 26, 2018 09:22
-
-
Save jungopro/bf450f48742ef0f23d6ab750c49efab2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provide "azurerm" {} | |
## Declare Variables | |
variable "resource_group_name" { | |
default = "my-resource-group" | |
} | |
variable "location" { | |
default = "West Europe" | |
} | |
variable "vault_uri" { | |
default = "https://jungo-test-keyvault.vault.azure.net/" | |
} | |
## Generate Random String | |
resource "random_string" "vm_password" { | |
length = 14 | |
min_upper = 2 | |
min_lower = 2 | |
min_numeric = 2 | |
min_special = 2 | |
} | |
## Create the secret | |
resource "azurerm_key_vault_secret" "vm_secret" { | |
name = "vm-secret" | |
value = "${random_string.vm_password.result}" | |
vault_uri = "${var.vault_uri}" | |
tags { | |
environment = "${var.resource_group_name}" | |
} | |
} | |
## Print secret data to console | |
output "vm_password_result" { | |
value = "${azurerm_key_vault_secret.vm_secret.value}" | |
} | |
## Create the VM | |
## The below is not a complete code and only used to demonstrate the password consumption concept | |
resource "azurerm_virtual_machine" "vm" { | |
name = "${var.resource_group_name}-myvm" | |
location = "${var.location}" | |
resource_group_name = "${var.resource_group_name}" | |
## Removed additional config for readability | |
os_profile { | |
computer_name = "${var.resource_group_name}-myvm" | |
admin_username = "admin" | |
admin_password = "${azurerm_key_vault_secret.vm_secret.value}" # Use the secret created earlier | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment