You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add esc env settings command with get and set subcommands (#595)
* Add `esc env settings` command with `get` and `set` subcommands
Fixespulumi/pulumi-service#33364
Adds `esc env settings get` and `esc env settings set` commands to manage environment settings.
Currently supports the `deletion-protected` setting, which prevents environments from being deleted when set to `true`. The default remains `false` for new environments.
### Usage
```bash
# Get all settings
$ esc env settings get myorg/myproject/prod
deletion-protected true
# Get a specific setting
$ esc env settings get myorg/myproject/prod deletion-protected
true
# Set deletion protection
$ esc env settings set myorg/myproject/prod deletion-protected true
true
```
The `get` command returns all settings in space-separated format when no setting name is provided, or just the value when a specific setting is requested. The `set` command works with single key-value pairs.
### Implementation
The implementation uses Go generics to keep setting implementations fully typed—each setting implements `Setting[T]` with its concrete type (e.g., `bool`). Settings are wrapped with `settingBox[T]` at registration time to convert them to `UntypedSetting` for homogeneous storage in the registry map.
### Test Script
The following script tests the deletion protection functionality end-to-end:
```bash
#!/usr/bin/env bash
set -ex
# Test script for environment settings (deletion protection)
#
# Required environment variables:
# PULUMI_ACCESS_TOKEN - Access token for the review stack
# PULUMI_API - Backend API URL (e.g., https://api-fnune-review.review-stacks.pulumi-dev.io)
#
# Usage:
# export PULUMI_ACCESS_TOKEN="your-token-here"
# export PULUMI_API="https://api-fnune-review.review-stacks.pulumi-dev.io"
# ./esc login $PULUMI_API
# ./test.sh
#
# You can test with any of these environments from the review stack:
# pulumi_local/2025-08-18-test-nocode1/dev
# pulumi_local/csharp-documented-test-no-code/dev
# pulumi_local/fearless-copper-fossa-nocode4/dev
# pulumi_local/innovative-rhenium-pangolin/dev
# pulumi_local/inspiring-ruby-quokka-nocode3/dev
if [ -z "$PULUMI_ACCESS_TOKEN" ]; then
echo "Error: PULUMI_ACCESS_TOKEN is not set"
exit 1
fi
if [ -z "$PULUMI_API" ]; then
echo "Error: PULUMI_API is not set"
exit 1
fi
ENV_NAME="${1:-pulumi_local/2025-08-18-test-nocode1/dev}"
echo "Building esc CLI..."
go build -o ./esc ./cmd/esc
echo ""
echo "Testing environment settings commands with: $ENV_NAME"
echo "Backend: $PULUMI_API"
echo ""
echo "=== Test 1: Get all settings ==="
./esc env settings get "$ENV_NAME"
echo ""
echo "=== Test 2: Get deletion-protected setting ==="
./esc env settings get "$ENV_NAME" deletion-protected
echo ""
echo "=== Test 3: Enable deletion protection ==="
./esc env settings set "$ENV_NAME" deletion-protected true
echo ""
echo "=== Test 4: Verify deletion protection is enabled ==="
./esc env settings get "$ENV_NAME" deletion-protected
echo ""
echo "=== Test 5: Attempt to delete protected environment (should fail) ==="
if ./esc env rm "$ENV_NAME" --yes 2>&1 | tee /dev/stderr | grep -q "deletion protection is enabled"; then
echo "✓ Deletion correctly blocked"
else
echo "✗ Deletion should have been blocked"
exit 1
fi
echo ""
echo "=== Test 6: Disable deletion protection ==="
./esc env settings set "$ENV_NAME" deletion-protected false
echo ""
echo "=== Test 7: Verify deletion protection is disabled ==="
./esc env settings get "$ENV_NAME" deletion-protected
echo ""
echo "=== Test 8: Test invalid value (should fail) ==="
if ./esc env settings set "$ENV_NAME" deletion-protected invalid 2>&1 | tee /dev/stderr | grep -q "expected true or false"; then
echo "✓ Invalid value correctly rejected"
else
echo "✗ Invalid value should have been rejected"
exit 1
fi
echo ""
echo "=== Test 9: Test unknown setting (should fail) ==="
if ./esc env settings get "$ENV_NAME" unknown-setting 2>&1 | tee /dev/stderr | grep -q "unknown setting name"; then
echo "✓ Unknown setting correctly rejected"
else
echo "✗ Unknown setting should have been rejected"
exit 1
fi
echo ""
echo "All tests passed! ✓"
```
* Add minimal enforcement of interface compatibility with env set/get
* Stop masking 409s unrelated to del protection, add comment about parsing
0 commit comments