vault/enos/modules/database_container/main.tf
Vault Automation ad9a5b1e0a
[VAULT-34888] enos: backport changes for Fyre scenarios for testing on linux/s390x
Add support for running enos on Fyre with support for linux/s390x,
linux/amd64, and linux/ppc64le. The enterprise version of this PR
has enterprise only scenarios. The changes reflected here are on
shared modules.

We now have three new fyre modules that are can swap in-place of
create_vpc, ec2_info, and target_ec2_instances:
create_vpc_fyre_shim, fyre_os_info and target_fyre_vms. This pass
doesn't make them adhered 1:1 as module interfaces but that can come
later when the base scenarios are merged.

The only major change we had to make to long existing modules was
supporting leader_api_addr for discovery. Historically we've always used
cloud based node discovery but that's obviously not available in Fyre.
Nowyou can set the retry_join variable to either local_api_addr or
aws.

We also modify our integration containers to use those available from
the HashiCorp docker mirror. We do this because we pull those images
unauthenticated and thus share the same external address as the larger
network, which makes the likelihood of throttling very high.

To maintain the goal of the Fyre scenarios not requiring AWS credentials, I
had to move the AWS secrets verification into it's own module. That allows
us now to simply not include it, but later if/when we include it we can have
scenarios with the Fyre backend compile them out by skipping.

This PR is massive and covers the following tickets:

    VAULT-40635
    VAULT-40636
    VAULT-44591
    VAULT-34888
    VAULT-34887
    VAULT-34886
    VAULT-34885
    VAULT-34884

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2026-06-22 10:21:47 -06:00

83 lines
2.2 KiB
HCL

# Copyright IBM Corp. 2016, 2026
# SPDX-License-Identifier: BUSL-1.1
terraform {
required_providers {
enos = {
source = "registry.terraform.io/hashicorp-forge/enos"
}
}
}
locals {
# Database-specific configurations
database_configs = {
postgres = {
image_template = "docker.mirror.hashicorp.services/library/postgres:${var.db_version}"
env_vars = {
POSTGRES_USER = var.username
POSTGRES_PASSWORD = var.password
POSTGRES_DB = var.database
}
}
mongodb = {
image_template = "docker.mirror.hashicorp.services/library/mongo:${var.db_version}"
env_vars = {
MONGO_INITDB_ROOT_USERNAME = var.username
MONGO_INITDB_ROOT_PASSWORD = var.password
MONGO_INITDB_DATABASE = var.database
}
args = "--bind_ip_all"
}
mysql = {
image_template = "docker.mirror.hashicorp.services/library/mysql:${var.db_version}"
env_vars = {
MYSQL_ROOT_PASSWORD = var.password
MYSQL_USER = var.username
MYSQL_PASSWORD = var.password
MYSQL_DATABASE = var.database
}
}
}
config = local.database_configs[var.database_type]
image = local.config.image_template
env_vars_map = local.config.env_vars
env_vars = join(",", [for k, v in local.env_vars_map : "${k}=${v}"])
args = try(local.config.args, "")
}
# Creating Database Server using generic container script
resource "enos_remote_exec" "create_database" {
depends_on = [var.depends_on_modules]
scripts = [abspath("${path.module}/../../modules/set_up_external_integration_target/scripts/start-container.sh")]
environment = {
CONTAINER_IMAGE = local.image
CONTAINER_NAME = "${var.database_type}-${var.instance_name}"
CONTAINER_PORTS = var.port
CONTAINER_ENVS = local.env_vars
CONTAINER_ARGS = local.args
}
transport = {
ssh = {
host = var.host.public_ip
}
}
}
# Outputs
output "config" {
description = "Database configuration details"
value = {
type = var.database_type
username = var.username
password = var.password
database = var.database
version = var.db_version
port = var.port
host = var.host
}
}