diff --git a/oci.compute.tf b/oci.compute.tf index e69de29..b9b7918 100644 --- a/oci.compute.tf +++ b/oci.compute.tf @@ -0,0 +1,5 @@ +resource "tls_private_key" "ssh_key" { + count = var.compute_ssh_key == null ? 1 : 0 + + algorithm = var.created_ssh_key_algorithm +} diff --git a/oci.locals.tf b/oci.locals.tf index 8bf9966..bd437fb 100644 --- a/oci.locals.tf +++ b/oci.locals.tf @@ -7,4 +7,5 @@ locals { } # 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) + compute_ssh_key = coalesce(var.compute_ssh_key, trimspace(tls_private_key.ssh_key[0].public_key_openssh)) } diff --git a/terraform.outputs.tf b/terraform.outputs.tf index 373656a..5ab2ef1 100644 --- a/terraform.outputs.tf +++ b/terraform.outputs.tf @@ -71,3 +71,14 @@ output "vcn_ipv6_cidr_private_blocks" { description = "The IPv6 CIDR block for the VCN" 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 +} diff --git a/terraform.variables.tf b/terraform.variables.tf index 4d1fe21..01df8b0 100644 --- a/terraform.variables.tf +++ b/terraform.variables.tf @@ -60,3 +60,15 @@ variable "enable_ipv6" { type = bool 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" +}