-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3249fa3
commit af81bf5
Showing
4 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
terraform { | ||
required_providers { | ||
enos = { | ||
source = "app.terraform.io/hashicorp-qti/enos" | ||
} | ||
} | ||
} | ||
|
||
variable "vault_instance_count" { | ||
type = number | ||
description = "How many vault instances are in the cluster" | ||
} | ||
|
||
variable "vault_instances" { | ||
type = map(object({ | ||
private_ip = string | ||
public_ip = string | ||
})) | ||
description = "The vault cluster instances that were created" | ||
} | ||
|
||
variable "vault_root_token" { | ||
type = string | ||
description = "The vault root token" | ||
} | ||
|
||
variable "vault_autopilot_default_max_leases" { | ||
type = string | ||
description = "The autopilot upgrade expected max_leases" | ||
} | ||
|
||
variable "timeout" { | ||
type = number | ||
description = "The max number of seconds to wait before timing out" | ||
default = 60 | ||
} | ||
|
||
variable "retry_interval" { | ||
type = number | ||
description = "How many seconds to wait between each retry" | ||
default = 2 | ||
} | ||
|
||
locals { | ||
public_ips = { | ||
for idx in range(var.vault_instance_count) : idx => { | ||
public_ip = values(var.vault_instances)[idx].public_ip | ||
private_ip = values(var.vault_instances)[idx].private_ip | ||
} | ||
} | ||
} | ||
|
||
resource "enos_remote_exec" "smoke_verify_default_lcq" { | ||
for_each = local.public_ips | ||
|
||
environment = { | ||
RETRY_INTERVAL = var.retry_interval | ||
TIMEOUT_SECONDS = var.timeout | ||
VAULT_ADDR = "http://localhost:8200" | ||
VAULT_TOKEN = var.vault_root_token | ||
DEFAULT_LCQ = var.vault_autopilot_default_max_leases | ||
} | ||
|
||
scripts = [abspath("${path.module}/scripts/smoke-verify-default-lcq.sh")] | ||
|
||
transport = { | ||
ssh = { | ||
host = each.value.public_ip | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
enos/modules/vault_verify_default_lcq/scripts/smoke-verify-default-lcq.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: BUSL-1.1 | ||
|
||
function fail() { | ||
echo "$1" 1>&2 | ||
exit 1 | ||
} | ||
|
||
[[ -z "$RETRY_INTERVAL" ]] && fail "RETRY_INTERVAL env variable has not been set" | ||
[[ -z "$TIMEOUT_SECONDS" ]] && fail "TIMEOUT_SECONDS env variable has not been set" | ||
[[ -z "$VAULT_ADDR" ]] && fail "VAULT_ADDR env variable has not been set" | ||
[[ -z "$VAULT_TOKEN" ]] && fail "VAULT_TOKEN env variable has not been set" | ||
|
||
getMaxLeases() { | ||
curl --request GET --header "X-Vault-Token: $VAULT_TOKEN" \ | ||
"$VAULT_ADDR/v1/sys/quotas/lease-count/default" | jq '.data.max_leases // empty' | ||
} | ||
|
||
waitForMaxLeases() { | ||
local max_leases | ||
if ! max_leases=$(getMaxLeases); then | ||
echo "failed getting /v1/sys/quotas/lease-count/default data" 1>&2 | ||
return 1 | ||
fi | ||
|
||
if [[ "$max_leases" == "$DEFAULT_LCQ" ]]; then | ||
echo "$max_leases" | ||
return 0 | ||
else | ||
echo "Expected Default LCQ $DEFAULT_LCQ but got $max_leases" | ||
return 1 | ||
fi | ||
} | ||
|
||
begin_time=$(date +%s) | ||
end_time=$((begin_time + TIMEOUT_SECONDS)) | ||
while [ "$(date +%s)" -lt "$end_time" ]; do | ||
if waitForMaxLeases; then | ||
exit 0 | ||
fi | ||
|
||
sleep "$RETRY_INTERVAL" | ||
done | ||
|
||
fail "Timed out waiting for Default LCQ verification to complete. Data:\n\t$(getMaxLeases)" |