Created
June 16, 2020 09:29
-
-
Save iamtheindian/bd06120badd8d971460fa04f966e054c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#generate private key | |
resource "tls_private_key" "tkey" { | |
algorithm = "RSA" | |
} | |
#assigne public openssh to the aws key pair | |
resource "aws_key_pair" "deployer" { | |
key_name = "deployer-key" | |
public_key = tls_private_key.tkey.public_key_openssh | |
depends_on=[tls_private_key.tkey] | |
} | |
#use key_name variable in the field of aws_instance's key_name | |
#if you want to save this key then use this | |
resource "local_file" "lf" { | |
content = tls_private_key.tkey.private_key_pem | |
filename= "awskey.pem" | |
} | |
#now this will save in you local system | |
#if you want to remote-exec the just use this << tls_private_key.tkey.private_key_pem >> in private_key argument of connection | |
#or you can use variables | |
variable "aws_key_pair_name" { | |
default = aws_key_pair.deployer.key_name | |
} | |
variable "login_private_key" { | |
defautl = tls_private_key.tkey.private_key_pem | |
} | |
#now use this variables in your terraform file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment