Reputation: 2975
I want to save the private_key_pem
generated by the tls_private_key
resource to a file on disk locally using local_file
resource.
resource "tls_private_key" "example" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "generated_key" {
key_name = "cloudtls"
public_key = tls_private_key.example.public_key_openssh
}
resource "aws_instance" "automation" {
instance_type = var.instance_type
ami = var.image_id
iam_instance_profile = aws_iam_instance_profile.ec2_profile.name
key_name = aws_key_pair.generated_key.key_name
}
resource "local_file" "pem_file" {
filename = "pemfile.pem"
#
}
Upvotes: 3
Views: 3407
Reputation: 2975
The below code saves the private key (.pem file) to the specified path.
resource "local_file" "cloud_pem" {
filename = "${path.module}/cloudtls.pem"
content = tls_private_key.example.private_key_pem
}
Upvotes: 7