chore(enos): Add scenario that uses docker containers for infrastructure (#3073)

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
Michael LiandJohan Brandhorst-Satzkorn authored and GitHub committed 2023-03-15 10:07:36 -04:00
1 parent bbbd6b1e51
commit acda0c3892
13 files changed
+647 -2

No files matched your search

@@ -0,0 +1,81 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
disable_mlock = true
controller {
name = "docker-controller"
database {
url = "env://BOUNDARY_POSTGRES_URL"
}
}
worker {
name = "boundary-colocated-worker"
description = "A worker that runs alongside the controller in the same process"
address = "boundary:9202"
}
listener "tcp" {
address = "boundary:9200"
purpose = "api"
tls_disable = true
}
listener "tcp" {
address = "boundary:9201"
purpose = "cluster"
tls_disable = true
}
listener "tcp" {
address = "boundary:9202"
purpose = "proxy"
tls_disable = true
}
listener "tcp" {
address = "boundary:9203"
purpose = "ops"
tls_disable = true
}
kms "aead" {
purpose = "root"
aead_type = "aes-gcm"
key = "sP1fnF5Xz85RrXyELHFeZg9Ad2qt4Z4bgNHVGtD6ung="
key_id = "global_root"
}
kms "aead" {
purpose = "worker-auth"
aead_type = "aes-gcm"
key = "8fZBjCUfN0TzjEGLQldGY4+iE9AkOvCfjh7+p0GtRBQ="
key_id = "global_worker-auth"
}
kms "aead" {
purpose = "recovery"
aead_type = "aes-gcm"
key = "8fZBjCUfN0TzjEGLQldGY4+iE9AkOvCfjh7+p0GtRBQ="
key_id = "global_recovery"
}
events {
audit_enabled = true
observations_enabled = true
sysevents_enabled = true
sink "stderr" {
name = "all-events"
description = "All events sent to stderr"
event_types = ["*"]
format = "cloudevents-json"
deny_filters = [
"\"/data/request_info/method\" contains \"Status\"",
"\"/data/request_info/path\" contains \"/health\"",
]
}
}
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
# This script initializes a postgres database to work with Boundary by spinning up a temporary
# Boundary docker container pointed to the specified database and invoking `boundary database init`.
#
# This script must only output the JSON that comes from `boundary database init` as the output is
# consumed by other scripts.
TEST_BOUNDARY_IMAGE=$1
TEST_DATABASE_ADDRESS=$2
TEST_CONTAINER_NAME=boundary-init
SOURCE=$(realpath $(dirname ${BASH_SOURCE[0]})) # get directory of this script
docker run \
--rm \
--name $TEST_CONTAINER_NAME \
-e "BOUNDARY_POSTGRES_URL=$TEST_DATABASE_ADDRESS" \
-e "SKIP_CHOWN=true" \
--cap-add IPC_LOCK \
--mount type=bind,src=$SOURCE,dst=/boundary/ \
--network e2e_network \
$TEST_BOUNDARY_IMAGE \
boundary database init -config /boundary/boundary-config.hcl -format json
+127
View File
@@ -0,0 +1,127 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.1"
}
tls = {
source = "hashicorp/tls"
version = "4.0.4"
}
enos = {
source = "app.terraform.io/hashicorp-qti/enos"
}
}
}
variable "image_name" {
description = "Name of Docker Image"
type = string
}
variable "network_name" {
description = "Name of Docker Network"
type = string
}
variable "container_name" {
description = "Name of Docker Container"
type = string
default = "boundary"
}
variable "postgres_address" {
description = "Address to postgres database"
type = string
}
resource "docker_image" "boundary" {
name = var.image_name
keep_locally = true
}
resource "enos_local_exec" "init_database" {
inline = ["bash ./${path.module}/init.sh \"${var.image_name}\" \"${var.postgres_address}\""]
}
locals {
db_init_info = jsondecode(enos_local_exec.init_database.stdout)
auth_method_id = local.db_init_info["auth_method"]["auth_method_id"]
login_name = local.db_init_info["auth_method"]["login_name"]
password = local.db_init_info["auth_method"]["password"]
}
resource "docker_container" "boundary" {
depends_on = [
enos_local_exec.init_database,
]
image = docker_image.boundary.image_id
name = var.container_name
command = ["boundary", "server", "-config", "/boundary/boundary-config.hcl"]
env = [
"BOUNDARY_POSTGRES_URL=${var.postgres_address}",
"HOSTNAME=boundary",
"SKIP_CHOWN=true",
]
ports {
internal = 9200
external = 9200
}
ports {
internal = 9201
external = 9201
}
ports {
internal = 9202
external = 9202
}
ports {
internal = 9203
external = 9203
}
capabilities {
add = ["IPC_LOCK"]
}
volumes {
host_path = abspath(path.module)
container_path = "/boundary/"
}
healthcheck {
test = ["CMD", "wget", "--quiet", "-O", "/dev/null", "http://boundary:9203/health"]
interval = "3s"
timeout = "5s"
retries = 5
}
wait = true
must_run = true
networks_advanced {
name = var.network_name
}
}
resource "enos_local_exec" "wait" {
depends_on = [
docker_container.boundary
]
inline = ["timeout 10s bash -c 'until curl http://0.0.0.0:9200; do sleep 2; done'"]
}
output "address" {
value = "http://0.0.0.0:9200"
}
output "auth_method_id" {
value = local.auth_method_id
}
output "login_name" {
value = local.login_name
}
output "password" {
value = local.password
}