diff --git a/.gitignore b/.gitignore index 126777e..23b12a9 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ CLAUDE.md extra .direnv .claude +e2e-test/*tfstate* +e2e-test/.terraformrc diff --git a/GNUmakefile b/GNUmakefile index e339a0a..df4f989 100644 --- a/GNUmakefile +++ b/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 diff --git a/docs/resources/relay_identity_ed25519.md b/docs/resources/relay_identity_ed25519.md index 96a446f..b1662d9 100644 --- a/docs/resources/relay_identity_ed25519.md +++ b/docs/resources/relay_identity_ed25519.md @@ -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" diff --git a/e2e-test/README.md b/e2e-test/README.md new file mode 100644 index 0000000..01c17d1 --- /dev/null +++ b/e2e-test/README.md @@ -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. diff --git a/e2e-test/main.tf b/e2e-test/main.tf new file mode 100644 index 0000000..8c3ecea --- /dev/null +++ b/e2e-test/main.tf @@ -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 +} diff --git a/e2e-test/setup-dev.sh b/e2e-test/setup-dev.sh new file mode 100755 index 0000000..1899c53 --- /dev/null +++ b/e2e-test/setup-dev.sh @@ -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." diff --git a/e2e-test/tf b/e2e-test/tf new file mode 100755 index 0000000..2df7ce0 --- /dev/null +++ b/e2e-test/tf @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +# Wrapper script to run terraform with local config + +export TF_CLI_CONFIG_FILE=.terraformrc +exec tofu "$@" diff --git a/flake.nix b/flake.nix index 8b5a7d7..edead20 100644 --- a/flake.nix +++ b/flake.nix @@ -47,6 +47,8 @@ pkgs.go pkgs.golangci-lint pkgs.obfs4 + pkgs.gnumake + pkgs.opentofu ]; buildInputs = libraries; inputsFrom = libraries;