I was looking at the pre-defined LAMP stack for Amazon ec2 instance template on Bluemix and found the following piece of code:
"awsPHPInstance": {
"source": "git::https://github.com/camc-experimental/terraform-modules.git?ref=master//aws/ami_instance",
"aws_ami": "${module.find_ami.aws_ami}",
"aws_instance_type": "t2.micro",
"aws_subnet_id": "${module.awsNetwork.subnet_id}",
"aws_security_group_id": "${module.awsNetwork.application_security_group_id}",
"aws_cam_public_key_id": "${aws_key_pair.cam_lamp_public_key.id}",
"hostname": "${var.php_instance_name}",
"module_script": "files/createCAMUser.sh",
"module_script_name": "createCAMUser.sh",
"module_script_variable_1": "${var.cam_user}",
"module_script_variable_2": "${var.cam_pwd}"
}
I am not very clear about "module_script": "files/createCAMUser.sh"
. Where is this file's folder which has the shell script in it exactly? From what I understand, we can only have single page standalone terraform template.
For your first question, the script is actually located within the module structure in the git repo. When terraform is run from CAM, it does a "terraform get" which pulls in everything from "source": "git::https://github.com/camc-experimental/terraform-modules.git?ref=master//aws/ami_instance"
The script file is actually packaged within the module in a folder named "files"
The module uses the following syntax to reference the file:
data "template_file" "default" { template = "${file("${path.module}/${var.module_script}")}"
For your second question, one possible solution is to base64 encode the contents of the pem file and pass it into your template as an input string versus trying to read it from a file