I recently encountered some problems when writing a script for Terrafrom automation.
In my case VM is using proxmox platform, not cloud platform So I use Telmate/proxmox as my mod for creating VMs(CentOS7)
The VM builds smoothly, but when I want to customize the VM(CentOS7), there are some problems
There is an inline usage in terraform’s remote exec Provisioner. According to the official documentation, this usage applies to line-by-line instructions
I followed this step and used it on my Provision script, the script did execute normally, and it also spawned the VM and executed the installation script.
The content of the install script is
yum -y install <something package>
install web service
copy web.conf, web program to /path/to/dir
restart web service
But the most important service is not up, but when I start the command in the script via SSH to the VM, the service is normal. That is, this cannot be achieved through terraform’s remote exec
So I want to ask if terraform is not suitable for customizing some services, such as web server, etc.? Only suitable for generating some resources such as VM?
And another custom script needs to be done using such as ansbile?
here is sample code
provisioner "remote-exec" {
inline = [
"yum -y install tar",
"tar -C / -xvf /tmp/product.tar",
"sh install.sh",
]
}
I found a way to understand this matter later, I am not sure if there is a problem with the program written by the developer or other reasons. Anyway, I can't enable the service (process) via script. But it is possible to enable the service by rebooting and using the built-in system service (systemctl).