Created
August 24, 2017 13:13
-
-
Save bizmate/d5d38dad31c64593cc41edc5dec5d793 to your computer and use it in GitHub Desktop.
Getting terraform to ssh and run remote commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
access_key = "${var.aws_access_key}" | |
secret_key = "${var.aws_secret}" | |
region = "${var.region}" | |
} | |
resource "aws_key_pair" "auth" { | |
key_name = "${var.key_name}" | |
public_key = "${file(var.public_key_path)}" | |
} | |
resource "aws_instance" "pivot_gocd_agent" { | |
ami = "ami-cb4b94dd" | |
instance_type = "t2.medium" | |
# The name of our SSH keypair we created above. | |
key_name = "${aws_key_pair.auth.id}" | |
connection { | |
# The default username for our AMI | |
user = "root" | |
# The connection will use the local SSH agent for authentication. | |
} | |
provisioner "remote-exec" { | |
scripts = [ | |
"./bin/provision.sh", | |
"./bin/start.sh" | |
] | |
} | |
} | |
### | |
# the above yelds a ssh timeout | |
# aws_instance.pivot_gocd_agent (remote-exec): Connecting to remote host via SSH... | |
# aws_instance.pivot_gocd_agent (remote-exec): Host: 54.159.165.163 | |
# aws_instance.pivot_gocd_agent (remote-exec): User: root | |
# aws_instance.pivot_gocd_agent (remote-exec): Password: false | |
# aws_instance.pivot_gocd_agent (remote-exec): Private key: false | |
# aws_instance.pivot_gocd_agent (remote-exec): SSH Agent: true | |
# aws_instance.pivot_gocd_agent: Still creating... (5m10s elapsed) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment