Add e2e test using opentofu cli
This commit is contained in:
parent
bd06c2e4b3
commit
6b623eb3a3
8 changed files with 180 additions and 5 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -39,3 +39,5 @@ CLAUDE.md
|
|||
extra
|
||||
.direnv
|
||||
.claude
|
||||
e2e-test/*tfstate*
|
||||
e2e-test/.terraformrc
|
||||
|
|
13
GNUmakefile
13
GNUmakefile
|
@ -21,4 +21,15 @@ test:
|
|||
testacc:
|
||||
TF_ACC=1 go test -v -cover -timeout 120m ./...
|
||||
|
||||
.PHONY: fmt lint test testacc build install generate
|
||||
e2e:
|
||||
@echo "Running end-to-end test..."
|
||||
cd e2e-test && \
|
||||
rm -rf .terraform/ .terraform.lock.hcl terraform.tfstate* && \
|
||||
./setup-dev.sh && \
|
||||
TF_CLI_CONFIG_FILE=.terraformrc terraform plan && \
|
||||
TF_CLI_CONFIG_FILE=.terraformrc terraform apply -auto-approve && \
|
||||
echo "✓ E2E test passed! Cleaning up..." && \
|
||||
TF_CLI_CONFIG_FILE=.terraformrc terraform destroy -auto-approve && \
|
||||
echo "✓ E2E test completed successfully"
|
||||
|
||||
.PHONY: fmt lint test testacc build install generate e2e
|
||||
|
|
|
@ -37,10 +37,6 @@ output "public_key_pem" {
|
|||
value = tor_relay_identity_ed25519.example.public_key_pem
|
||||
}
|
||||
|
||||
output "public_key_fingerprint_sha1" {
|
||||
description = "SHA1 fingerprint of the Ed25519 public key"
|
||||
value = tor_relay_identity_ed25519.example.public_key_fingerprint_sha1
|
||||
}
|
||||
|
||||
output "public_key_fingerprint_sha256" {
|
||||
description = "SHA256 fingerprint of the Ed25519 public key"
|
||||
|
|
49
e2e-test/README.md
Normal file
49
e2e-test/README.md
Normal file
|
@ -0,0 +1,49 @@
|
|||
# End-to-End Testing
|
||||
|
||||
This directory contains a complete end-to-end test setup for the terraform-provider-tor.
|
||||
|
||||
## Quick Start
|
||||
|
||||
1. **Setup development environment:**
|
||||
```bash
|
||||
./setup-dev.sh
|
||||
```
|
||||
This script will:
|
||||
- Create local `.terraformrc` with dev overrides (no global config changes)
|
||||
- Build and install the provider locally
|
||||
|
||||
2. **Run the test:**
|
||||
```bash
|
||||
./tf plan
|
||||
./tf apply
|
||||
```
|
||||
|
||||
Or using the full command:
|
||||
```bash
|
||||
TF_CLI_CONFIG_FILE=.terraformrc terraform plan
|
||||
TF_CLI_CONFIG_FILE=.terraformrc terraform apply
|
||||
```
|
||||
|
||||
Note: Skip `terraform init` when using dev overrides - it's not needed and may cause errors.
|
||||
|
||||
3. **Clean up:**
|
||||
```bash
|
||||
./tf destroy
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
If you encounter issues:
|
||||
|
||||
1. **Provider not found**: Run `./setup-dev.sh` again
|
||||
2. **Build errors**: Check that Go >= 1.23 is installed
|
||||
3. **Permission errors**: Ensure the setup script is executable
|
||||
|
||||
## Resetting
|
||||
|
||||
To reset your Terraform configuration:
|
||||
```bash
|
||||
rm -rf .terraform/ .terraform.lock.hcl terraform.tfstate*
|
||||
```
|
||||
|
||||
Then run the setup and init process again.
|
62
e2e-test/main.tf
Normal file
62
e2e-test/main.tf
Normal file
|
@ -0,0 +1,62 @@
|
|||
terraform {
|
||||
required_providers {
|
||||
tor = {
|
||||
source = "guardianproject/tor"
|
||||
version = "99.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "tor" {}
|
||||
|
||||
# Generate RSA identity key for the bridge
|
||||
resource "tor_relay_identity_rsa" "bridge" {}
|
||||
|
||||
# Generate Ed25519 identity key for the bridge
|
||||
resource "tor_relay_identity_ed25519" "bridge" {}
|
||||
|
||||
# Generate obfs4 state using the identity keys
|
||||
resource "tor_obfs4_state" "bridge" {
|
||||
rsa_identity_private_key = tor_relay_identity_rsa.bridge.private_key_pem
|
||||
ed25519_identity_private_key = tor_relay_identity_ed25519.bridge.private_key_pem
|
||||
}
|
||||
|
||||
# Generate bridge line for client distribution
|
||||
data "tor_obfs4_bridge_line" "bridge" {
|
||||
ip_address = "203.0.113.1"
|
||||
port = 9001
|
||||
identity_fingerprint_sha1 = tor_relay_identity_rsa.bridge.public_key_fingerprint_sha1
|
||||
obfs4_state_certificate = tor_obfs4_state.bridge.certificate
|
||||
obfs4_state_iat_mode = tor_obfs4_state.bridge.iat_mode
|
||||
}
|
||||
|
||||
# Outputs for verification
|
||||
output "rsa_fingerprint_sha1" {
|
||||
description = "RSA identity fingerprint (SHA1)"
|
||||
value = tor_relay_identity_rsa.bridge.public_key_fingerprint_sha1
|
||||
}
|
||||
|
||||
output "rsa_fingerprint_sha256" {
|
||||
description = "RSA identity fingerprint (SHA256)"
|
||||
value = tor_relay_identity_rsa.bridge.public_key_fingerprint_sha256
|
||||
}
|
||||
|
||||
output "ed25519_fingerprint_sha256" {
|
||||
description = "Ed25519 identity fingerprint (SHA256)"
|
||||
value = tor_relay_identity_ed25519.bridge.public_key_fingerprint_sha256
|
||||
}
|
||||
|
||||
output "obfs4_certificate" {
|
||||
description = "obfs4 certificate for bridge line"
|
||||
value = tor_obfs4_state.bridge.certificate
|
||||
}
|
||||
|
||||
output "obfs4_iat_mode" {
|
||||
description = "obfs4 IAT mode"
|
||||
value = tor_obfs4_state.bridge.iat_mode
|
||||
}
|
||||
|
||||
output "bridge_line" {
|
||||
description = "Complete bridge line for clients"
|
||||
value = data.tor_obfs4_bridge_line.bridge.bridge_line
|
||||
}
|
48
e2e-test/setup-dev.sh
Executable file
48
e2e-test/setup-dev.sh
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo "Setting up development environment for terraform-provider-tor..."
|
||||
|
||||
# Get the Go bin path
|
||||
GOBIN=$(go env GOPATH)/bin
|
||||
if [ -z "$GOBIN" ]; then
|
||||
GOBIN=$(go env GOROOT)/bin
|
||||
fi
|
||||
|
||||
echo "Go bin path: $GOBIN"
|
||||
|
||||
# Create local .terraformrc with dev overrides
|
||||
TERRAFORMRC="$(pwd)/.terraformrc"
|
||||
echo "Creating $TERRAFORMRC..."
|
||||
|
||||
# Create local .terraformrc with dev overrides
|
||||
cat > "$TERRAFORMRC" << EOF
|
||||
provider_installation {
|
||||
dev_overrides {
|
||||
"guardianproject/tor" = "$GOBIN"
|
||||
}
|
||||
direct {}
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "✓ Created local $TERRAFORMRC with dev overrides"
|
||||
|
||||
# Build and install the provider
|
||||
echo "Building and installing provider..."
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
# Build with proper naming for dev overrides
|
||||
go build -o "$GOBIN/terraform-provider-tor_v99.0.0"
|
||||
|
||||
echo "✓ Provider built and installed to $GOBIN/terraform-provider-tor_v99.0.0"
|
||||
|
||||
echo ""
|
||||
echo "Setup complete! You can now run:"
|
||||
echo " cd e2e-test"
|
||||
echo " ./tf plan"
|
||||
echo " ./tf apply"
|
||||
echo ""
|
||||
echo "Or use the full command:"
|
||||
echo " TF_CLI_CONFIG_FILE=.terraformrc terraform plan"
|
||||
echo ""
|
||||
echo "Note: Using local .terraformrc to avoid modifying your global configuration."
|
5
e2e-test/tf
Executable file
5
e2e-test/tf
Executable file
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
# Wrapper script to run terraform with local config
|
||||
|
||||
export TF_CLI_CONFIG_FILE=.terraformrc
|
||||
exec tofu "$@"
|
|
@ -47,6 +47,8 @@
|
|||
pkgs.go
|
||||
pkgs.golangci-lint
|
||||
pkgs.obfs4
|
||||
pkgs.gnumake
|
||||
pkgs.opentofu
|
||||
];
|
||||
buildInputs = libraries;
|
||||
inputsFrom = libraries;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue