I have three resources resp. VM types I want to add. For each resource I want to run a remote-exec and place some files using the corresponding provisioner. As I don't want to have the provisioners repeated in each resource, I thought about writing a (resp. another) module. I created a module which looks like that:
variable "cicd-user" {
default = [
"useradd cicd-user",
"echo cicd-user: | /usr/sbin/chpasswd",
"su - cicd-user -c \"mkdir /home/cicd-user/.ssh/\"",
"su - cicd-user -c \"touch /home/cicd-user/.ssh/authorized_keys\"",
"su - cicd-user -c \"chmod 700 /home/cicd-user/.ssh/\"",
"su - cicd-user -c \"chmod 600 /home/cicd-user/.ssh/authorized_keys\"",
]
}
variable "sudoers_content" {
default = "cicd-user ALL=(ALL) NOPASSWD: ALL"
}
variable "sudoers_destination" {
default = "/etc/sudoers.d/cicd"
}
The main.tf has the following:
module "provisioner_info" {
source = "./provisioner_info"
}
...
resource "vsphere_virtual_machine" "web" {
...
provisioner "remote-exec" {
inline = module.provisioner_info.cicd-user
}
provisioner "file" {
content = module.provisioner_info.sudoers_content
destination = module.provisioner_info.sudoers_destination
}
...
That doesn't work as I would have expected that, I get the following error:
terraform plan
Error: Unsupported attribute
on main.tf line 81, in resource "vsphere_virtual_machine" "web":
81: inline = module.provisioner_info.cicd-user
This object does not have an attribute named "cicd-user".
Can someone tell me, what I'm doing wrong? Do I misuse the module functionality?