New to Terraform and I am trying to bootstrap a node to chef after the instance is created.
Here is the file:
resource "aws_instance" "jenkinsNode" {
provisioner "remote-exec" {
connection {
user = "ubuntu"
private_key = "${file("~/key/mykey.pem")}"
host = "${aws_instance.jenkinsNode.public_ip}"
}
inline = [
"sudo mkdir -p /etc/chef/trusted_certs",
"sudo curl --silent --show-error --retry 3 --location --output
\"/etc/chef/trusted_certs/opsworks-cm-ca-2016-root.pem\"
\"https://opsworks-cm-us-assets.s3.amazonaws.com/misc/opsworks-cm-ca-2016-root.pem\""
]
}
provisioner "chef" {
environment = "_default"
run_list = ["android-aws-nodes::updateAndroidSdk"]
node_name = "jenkinsNodeOnDemandUpdate"
secret_key = "${file("~/chef/mobile-chef-aws/.chef/private.pem")}"
server_url = "https://my-opsworks-server.io/organizations/default"
recreate_client = true
user_name = "delivery"
user_key = "${file("~/chef/mobile-chef-aws/.chef/private.pem")}"
version = "12.8.1"
}
connection {
user = "ubuntu"
private_key = "${file("~/key/jenkins-main.pem")}"
}
count = 1
instance_type = "c4.8xlarge"
ami = "ami-0000000"
key_name = "mykey"
subnet_id = "subnet-00000000"
vpc_security_group_ids = ["sg-00000000"]
}
I am receiving the following error when I run when I try to apply the above code. I connected and starts the bootstrap process but it keeps complaining that it can't find the private (Which I believe is created when run the "client create". I ssh'd into the instance and I do not see the ubuntu.pem in the /etc/chef/ directory:
UPDATED aws_instance.jenkinsNode (chef): ERROR: Failed to authenticate to https://mobile-b9oer25dyrts1qor.us-east-1.opsworks-cm.io/organizations/default/ as delivery with key /etc/chef/delivery.pem aws_instance.jenkinsNode (chef): Response: Invalid signature for user or client 'delivery' aws_instance.jenkinsNode (chef): Cleanup user key...
Error applying plan:
1 error(s) occurred:
* aws_instance.jenkinsNode: 1 error(s) occurred:
* Command "sudo knife client create jenkinsNodeOnDemandUpdate -d -f /etc/chef/client.pem -c /etc/chef/client.rb -u ubuntu --key /etc/chef/ubuntu.pem" exited with non-zero exit status: 100
There is no key when you log in, because it is removed right after failed bootstrap
aws_instance.jenkinsNode (chef): Cleanup user key...
Double check if key ( ~/key/mykey.pem
) on machine which runs Terraform is in proper format. Also it should be loaded with $file
or put as String:
user_key = "${file("~/key/mykey.pem")}"
Just double check if Terraform supports ~
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.