Skip to content

Commit

Permalink
REDSTACK-3829: refactor the key creation - var.vpc_skip_ssh_key_create
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Bastide <[email protected]>
  • Loading branch information
prb112 committed Nov 18, 2023
1 parent 6c300cd commit 405b538
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions modules/1_vpc_prepare/keys/create_new/keys.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ locals {

resource "ibm_is_ssh_key" "vpc_support_ssh_key_cond_create" {
depends_on = [data.ibm_is_ssh_keys.keys]
count = length(data.ibm_is_ssh_keys.keys) == 0 ? 1 : 0
count = !var.vpc_skip_ssh_key_create ? 1 : 0
name = "${var.vpc_name}-${var.name_prefix}-keypair"
public_key = local.public_key
resource_group = var.vpc_resource_group
}

locals {
key_id = local.keys == [] ? ibm_is_ssh_key.vpc_support_ssh_key_cond_create[0].id : local.keys[0].id
key_id = !var.vpc_skip_ssh_key_create ? ibm_is_ssh_key.vpc_support_ssh_key_cond_create[0].id : local.keys[0].id
}
3 changes: 2 additions & 1 deletion modules/1_vpc_prepare/keys/create_new/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ variable "public_key_file" {}
variable "public_key" {}
variable "vpc_name" {}
variable "vpc_resource_group" {}
variable "name_prefix" {}
variable "name_prefix" {}
variable "vpc_skip_ssh_key_create" {}
1 change: 1 addition & 0 deletions modules/1_vpc_prepare/keys/keys.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ module "create_new" {
vpc_name = var.vpc_name
vpc_resource_group = var.vpc_resource_group
name_prefix = var.name_prefix
vpc_skip_ssh_key_create =var.vpc_skip_ssh_key_create
}
4 changes: 2 additions & 2 deletions modules/1_vpc_prepare/keys/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
################################################################

output "vpc_check_key" {
value = var.vpc_create || var.create_custom_subnet ? module.create_new.vpc_check_key : module.check.check_key
value = var.vpc_create || var.create_custom_subnet || !var.vpc_skip_ssh_key_create ? module.create_new.vpc_check_key : module.check.check_key
}

output "vpc_key_id" {
value = var.vpc_create || var.create_custom_subnet ? module.create_new.vpc_key_id : module.check.keys
value = var.vpc_create || var.create_custom_subnet || !var.vpc_skip_ssh_key_create ? module.create_new.vpc_key_id : module.check.keys
}

0 comments on commit 405b538

Please sign in to comment.