Hello guys, i have a weird problem with my terraform template_file.
i am trying to automate a mongo replicaset, and i have a bash command script to execute this automation during the aws spin up instance, but for some weird reason, it appears that my bash file does not execute, and if i ssh inside my mongo instance, and input manually the code, it runs just fine.
this is the structure of my folder:
.
├── dev.terraform
├── dev.tf
├── output.tf
├── provider.tf
├── scripts
│ ├── init.cfg
│ └── volumes.sh
├── ssh
│ ├── aws
│ ├── aws.pub
│ ├── awssingle
│ ├── awssingle.pub
│ ├── hamza-elaouane-elkkey.pem
│ └── winetricks
├── template
│ ├── db
│ │ ├── init1.sh.tpl
│ │ └── init2.sh.tpl
│ ├── init1.sh.tpl
│ ├── init2.sh.tpl
│ └── init.sh.tpl
├── terraform.tfstate
├── terraform.tfstate.backup
├── variable.tf
└── versions.tf
4 directories, 21 files
and my bash command looks like this:
#!/bin/bash
exec &> /var/mylog
sleep 120;
sudo systemctl enable mongod
sudo systemctl start mongod
mongo --host mongodb://ip-10-0-1-100 --port 27017 --eval 'rs.initiate({_id: "rs0", members: [{_id: 0, host: "ip-10-0-1-100:27017", priority: 2}, {_id: 1, host: "ip-10-0-2-100:27017"}, {_id: 2, host: "ip-10-0-3-100:27017"}]})'
mongo --host mongodb://ip-10-0-1-100 --port 27017 --eval "db.isMaster().primary"
mongo --host mongodb://ip-10-0-1-100 --port 27017 --eval "rs.slaveOk()"
sleep 60; sudo systemctl restart metricbeat
sudo systemctl restart filebeat
sleep 180; sudo filebeat setup -e \
-E output.logstash.enabled=false \
-E output.elasticsearch.hosts=['10.0.105.100:9200'] \
-E setup.kibana.host=10.0.105.101:5601 && sudo metricbeat setup
from my dev.tf in a template_file data i am calling the bash script:
data "template_file" "initdb1" {
template = "./template/db/init1.sh.tpl"
}
data "template_file" "initdb2" {
template = "./template/db/init2.sh.tpl"
}
in bash command i tried to exec the output to a mylog file so to try if its working, but nothing has been created and my code is not running.
I dont undersrtand what i am doing wrong as i dont have any error logs to troubleshoot. Any suggestin please?
If you need more info just please let me know, thank you very much