i lanched an ec2 instance (ubuntu), and i have a script which looks like :
#!/bin/bash
# works fine (even directly in terminal or via user_data)
hostnamectl set-hostname ${hostname}
# works fine as well (even directly in terminal or via user_data)
echo "127.0.0.1 ${hostname}" >> /etc/hosts
# it works in terminal BUT NOT via user_data, why ?
curl -LsSf https://astral.sh/uv/install.sh | sh
i want to install uv (python package) with last code in my script above BUT it does not works using user_data, why ?
Update :
This script named and located at remote-servers-script/installer.sh, and referenced in a terraform module which looks like :
module "virtual_machine" {
source = "./virtual_machine"
ami_id = var.ec2_ami_id
instance_type = "c7i-flex.large"
for_each = toset(var.vms_names)
public_key = var.public_key
tag_name = each.key
enable_public_ip_address = each.key == "jump-server" ? true : false
sg_for_jump_server = each.key == "jump-server" ? [module.security_group.sg_ec2_jump_server] : [module.security_group.sg_ec2_clickhouse_instances]
subnet_id = each.key == "jump-server" ? tolist(module.networking.free_iliad_public_subnets)[0] : tolist(module.networking.free_iliad_private_subnets)[0]
user_data_install_jump_server = templatefile("./remote-servers-script/hostname.sh", { hostname = each.key }) # <== referenced here
}
user_data(which I assume is a bash variable but idk). and show how you're trying to use it in your script. Also, copy/paste your script into shellcheck.net and fix the issues it tells you about.