2025-10-21 17:20:20 -04:00
|
|
|
# Copyright IBM Corp. 2016, 2025
|
2023-12-08 16:00:45 -05:00
|
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
terraform {
|
|
|
|
|
required_providers {
|
|
|
|
|
enos = {
|
2024-04-22 14:34:47 -04:00
|
|
|
source = "registry.terraform.io/hashicorp-forge/enos"
|
2023-12-08 16:00:45 -05:00
|
|
|
version = ">= 0.4.9"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "hosts" {
|
|
|
|
|
type = map(object({
|
2024-07-30 13:00:27 -04:00
|
|
|
ipv6 = string
|
2023-12-08 16:00:45 -05:00
|
|
|
private_ip = string
|
|
|
|
|
public_ip = string
|
|
|
|
|
}))
|
|
|
|
|
description = "The hosts for whom default softhsm configuration will be applied"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
variable "skip" {
|
|
|
|
|
type = bool
|
|
|
|
|
default = false
|
|
|
|
|
description = "Whether or not to skip initializing softhsm"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locals {
|
|
|
|
|
// The location on disk to write the softhsm tokens to
|
|
|
|
|
token_dir = "/var/lib/softhsm/tokens"
|
|
|
|
|
|
|
|
|
|
// Where the default configuration is
|
|
|
|
|
config_paths = {
|
2024-08-09 15:43:28 -04:00
|
|
|
"amzn" = "/etc/softhsm2.conf"
|
2023-12-08 16:00:45 -05:00
|
|
|
"rhel" = "/etc/softhsm2.conf"
|
|
|
|
|
"ubuntu" = "/etc/softhsm/softhsm2.conf"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
host_key = element(keys(enos_host_info.hosts), 0)
|
|
|
|
|
config_path = local.config_paths[enos_host_info.hosts[local.host_key].distro]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "enos_host_info" "hosts" {
|
|
|
|
|
for_each = var.hosts
|
|
|
|
|
|
|
|
|
|
transport = {
|
|
|
|
|
ssh = {
|
|
|
|
|
host = each.value.public_ip
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "enos_remote_exec" "init_softhsm" {
|
|
|
|
|
for_each = var.hosts
|
|
|
|
|
depends_on = [enos_host_info.hosts]
|
|
|
|
|
|
|
|
|
|
environment = {
|
|
|
|
|
CONFIG_PATH = local.config_paths[enos_host_info.hosts[each.key].distro]
|
|
|
|
|
TOKEN_DIR = local.token_dir
|
|
|
|
|
SKIP = var.skip ? "true" : "false"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scripts = [abspath("${path.module}/scripts/init-softhsm.sh")]
|
|
|
|
|
|
|
|
|
|
transport = {
|
|
|
|
|
ssh = {
|
|
|
|
|
host = each.value.public_ip
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "config_path" {
|
|
|
|
|
// Technically this is actually just the first config path of our hosts.
|
|
|
|
|
value = local.config_path
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "token_dir" {
|
|
|
|
|
value = local.token_dir
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output "skipped" {
|
|
|
|
|
value = var.skip
|
|
|
|
|
}
|