如何使用local_file资源将pem文件保存到Terraform中由tls_private_key资源创建的磁盘上?

时间:2020-05-26 08:09:48

标签: amazon-web-services terraform terraform-provider-aws

我想使用private_key_pem资源将tls_private_key资源生成的local_file保存到本地磁盘上的文件中。

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"
  #
}

1 个答案:

答案 0 :(得分:0)

以下代码将私钥(。pem文件)保存到指定路径。

resource "local_file" "cloud_pem" { 
  filename = "${path.module}/cloudtls.pem"
  content = tls_private_key.example.private_key_pem
}