Skip to content

Commit

Permalink
feat:add user data attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupalgw committed Feb 27, 2024
1 parent 16679c0 commit 10dd303
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
13 changes: 8 additions & 5 deletions _example/linux-vm/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module "security_group" {
module "key_vault" {
source = "clouddrove/key-vault/azure"
version = "1.1.0"
name = "app399433"
name = "hello55"
environment = "test"
label_order = ["name", "environment", ]
resource_group_name = module.resource_group.resource_group_name
Expand Down Expand Up @@ -148,10 +148,10 @@ module "virtual-machine" {
network_interface_sg_enabled = true
network_security_group_id = module.security_group.id
## Public IP
public_ip_enabled = false
public_ip_enabled = true
## Virtual Machine
vm_size = "Standard_B1s"
public_key = "ssh-rsa AAAA"
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC/e5bluEqTbb3qtuoKh1qEXMP4bk6QtqPrbhg7bMYQjJChmzvuA/aqA8gkQ48lweoFZMd7yr/ylhBPXvpYQ450INW6CNksatr4+z+EXHzyJ3MBTLSWlFc+ut6ji6Fglgkk3fe4sJw2fPZlf3FWFkomLJ3dIOIHyHQO6IaL9ZP22TRSPegSceNC30XF4xz1nHYiqNlZVq/COMHDtammwq8VnitkP6lRbokeJ1HlNBaJygUHlzYKrg8nguxGph3rlG9g+2+xAYf/qHQ/8k14xUMac7JBORnv+HAI+YHYCRYlQVXg635Bnj83jWmDK5Wed98O9ORARv70UN8Bj46247cdkeXXOAslUW19RQj0BA+QYRRvsXfLqlNX/Wq9V5yp66wO4QZV/2wvmoUwSELz6fn+qQvdBbs8IN9K7oJz2nl43Dth0vLnn8IrG7V2PfgW1g4WHjK5/GJXfyZXEYiM5Aye4W8V24g0AnunjIldBTnpofT6q4ki9bXx6en9EeBYB6E="
admin_username = "ubuntu"
caching = "ReadWrite"
disk_size_gb = 30
Expand Down Expand Up @@ -180,6 +180,9 @@ module "virtual-machine" {
}]

#### enable diagnostic setting
diagnostic_setting_enable = true
diagnostic_setting_enable = false
log_analytics_workspace_id = module.log-analytics.workspace_id ## when diagnostic_setting_enable enable, add log analytics workspace id
}

#vm With User Data
user_data = file("user-data.sh")
}
8 changes: 8 additions & 0 deletions _example/linux-vm/user-data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
sudo apt-get update
sudo apt-get install -y apache2
sudo systemctl start apache2
sudo systemctl enable apache2
echo "<h1>Deployed via Terraform</h1>" | sudo tee /var/www/html/index.html
sudo systemctl restart apache2

2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ resource "azurerm_linux_virtual_machine" "default" {
name = var.vm_addon_name == null ? format("%s-virtual-machine-%s", module.labels.id, count.index + 1) : format("%s-virtual-machine-%s", module.labels.id, var.vm_addon_name)
resource_group_name = var.resource_group_name
location = var.location
custom_data = base64encode(file("user-data.sh"))
size = var.vm_size
admin_username = var.admin_username
admin_password = var.disable_password_authentication == true ? null : var.admin_password
Expand Down Expand Up @@ -178,6 +179,7 @@ resource "azurerm_linux_virtual_machine" "default" {
}
}


timeouts {
create = var.create
update = var.update
Expand Down
5 changes: 5 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,8 @@ variable "user_object_id" {
default = {}
description = "The ID of the Principal (User, Group or Service Principal) to assign the Role Definition to. Changing this forces a new resource to be created."
}
variable "user_data" {
type = string
default = ""
description = "(Optional) A string of the desired User Data for the vm."
}

0 comments on commit 10dd303

Please sign in to comment.