Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/userdata #55

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions _example/linux-vm/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ 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"
Expand Down Expand Up @@ -182,4 +182,7 @@ module "virtual-machine" {
#### enable diagnostic setting
diagnostic_setting_enable = true
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
user_data = base64encode(var.user_data)
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 = "path/to/user-data.sh" // Adjust this path accordingly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep this null and pass this path/to/user-data file in comments.

description = "(Optional) A string of the desired User Data for the vm."
}
Loading