create ssh key for compute instances

This commit is contained in:
bdeshi 2024-05-24 16:18:39 +06:00
parent e80919d3be
commit be39b066c5
Signed by: bdeshi
GPG Key ID: 410D03DA9A3468E0
4 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,5 @@
resource "tls_private_key" "ssh_key" {
count = var.compute_ssh_key == null ? 1 : 0
algorithm = var.created_ssh_key_algorithm
}

View File

@ -7,4 +7,5 @@ locals {
} }
# vcn dns label must be only alphanumeric and max 15 chars # vcn dns label must be only alphanumeric and max 15 chars
vcn_dns_label = substr(replace(join("", [var.prefix, "vcn"]), "/(?i)[^0-9a-z]/", ""), 0, 15) vcn_dns_label = substr(replace(join("", [var.prefix, "vcn"]), "/(?i)[^0-9a-z]/", ""), 0, 15)
compute_ssh_key = coalesce(var.compute_ssh_key, trimspace(tls_private_key.ssh_key[0].public_key_openssh))
} }

View File

@ -71,3 +71,14 @@ output "vcn_ipv6_cidr_private_blocks" {
description = "The IPv6 CIDR block for the VCN" description = "The IPv6 CIDR block for the VCN"
value = oci_core_vcn.vcn.ipv6private_cidr_blocks value = oci_core_vcn.vcn.ipv6private_cidr_blocks
} }
output "ssh_key_public" {
description = "The public SSH key for the compute instances"
value = local.compute_ssh_key
}
output "ssh_key_private" {
description = "The created SSH private key for the compute instances"
value = try(tls_private_key.ssh_key[0].private_key_pem, null)
sensitive = true
}

View File

@ -60,3 +60,15 @@ variable "enable_ipv6" {
type = bool type = bool
default = true default = true
} }
variable "compute_ssh_key" {
description = "The public SSH key for the compute instances"
type = string
default = null
}
variable "created_ssh_key_algorithm" {
description = "The algorithm for the created SSH key"
type = string
default = "ED25519"
}