Kailash G

Kailash G

  • NA
  • 3
  • 459

Terraform code to connect Azure Storage to VM is not working

Feb 27 2019 9:56 PM
Hi , I need support in understanding as to why the storage account is not getting connected to VM . I am not getting any errors & storage is created , but remains unattached to VM . I am sharing the code snippet below . Thank you .
provider "azurerm" {
version = "=1.22.0"
subscription_id = "${var.subscription_id}"
client_id = "${var.client_id}"
client_secret = "${var.client_secret}"
tenant_id = "${var.tenant_id}"
}
....
....
resource "azurerm_storage_account" "st_jh" {
name = "${var.storage_jh}"
location = "westeurope"
resource_group_name = "${azurerm_resource_group.rg_main.name}"
account_tier = "Standard"
account_replication_type = "LRS"
tags {
environment = "Terraform Staging"
}
}
.....
.....
resource "azurerm_virtual_machine" "vm1" {
name = "${var.new_vm1_name}"
location = "${azurerm_resource_group.rg_main.location}"
resource_group_name = "${azurerm_resource_group.rg_main.name}"
vm_size = "${var.vm1_size}"
network_interface_ids = ["${azurerm_network_interface.nic1.id}"]
boot_diagnostics {
enabled = "true"
storage_uri = "${azurerm_storage_account.st_jh.primary_blob_endpoint}"
}
storage_image_reference {
publisher = "${var.image1_publisher}"
offer = "${var.image1_offer}"
sku = "${var.image1_sku}"
version = "${var.image1_version}"
}
storage_os_disk {
name = "${var.new_vm1_name}-osdisk"
managed_disk_type = "Standard_LRS"
caching = "ReadWrite"
create_option = "FromImage"
}
os_profile {
computer_name = "${var.Host1}"
admin_username = "${var.vm1_username}"
}
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/${var.vm1_username}/.ssh/authorized_keys"
key_data = "${var.vm1_password}"
}
}
}