我想使用local_file
资源将tls_private_key
资源生成的private_key_pem
保存到本地磁盘上的文件中。
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"
#
}
下面的代码将私钥(.pem 文件(保存到指定的路径。
resource "local_file" "cloud_pem" {
filename = "${path.module}/cloudtls.pem"
content = tls_private_key.example.private_key_pem
}