-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal-test.sh
More file actions
executable file
·200 lines (173 loc) · 4.82 KB
/
local-test.sh
File metadata and controls
executable file
·200 lines (173 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# Copyright (c) Spice AI, Inc. 2025, 2026
# SPDX-License-Identifier: MPL-2.0
# Helper script for local testing of the Spice.ai Terraform provider
#
# Usage:
# ./scripts/local-test.sh [command]
#
# Commands:
# build - Build the provider binary
# setup - Set up ~/.terraformrc with dev_overrides
# plan - Run terraform plan in examples/test
# apply - Run terraform apply in examples/test
# destroy - Run terraform destroy in examples/test
# clean - Clean up terraform state files
# all - Build, setup, and run plan
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
PROVIDER_BINARY="$PROJECT_DIR/terraform-provider-spiceai"
TEST_DIR="$PROJECT_DIR/examples/test"
TERRAFORMRC="$HOME/.terraformrc"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
check_credentials() {
if [ -z "$SPICEAI_CLIENT_ID" ]; then
log_error "SPICEAI_CLIENT_ID environment variable is not set"
echo " export SPICEAI_CLIENT_ID=\"your-client-id\""
return 1
fi
if [ -z "$SPICEAI_CLIENT_SECRET" ]; then
log_error "SPICEAI_CLIENT_SECRET environment variable is not set"
echo " export SPICEAI_CLIENT_SECRET=\"your-client-secret\""
return 1
fi
log_info "Credentials configured"
return 0
}
cmd_build() {
log_info "Building provider..."
cd "$PROJECT_DIR"
go build -o terraform-provider-spiceai .
log_info "Provider built: $PROVIDER_BINARY"
}
cmd_setup() {
log_info "Setting up ~/.terraformrc with dev_overrides..."
if [ -f "$TERRAFORMRC" ]; then
if grep -q "spiceai/spiceai" "$TERRAFORMRC"; then
log_warn "~/.terraformrc already contains spiceai/spiceai override"
log_warn "Please verify the path is correct: $PROJECT_DIR"
return 0
fi
log_warn "~/.terraformrc exists, creating backup..."
cp "$TERRAFORMRC" "$TERRAFORMRC.backup.$(date +%Y%m%d%H%M%S)"
fi
cat > "$TERRAFORMRC" << EOF
# Terraform CLI configuration for local provider development
# Generated by terraform-provider-spiceai/scripts/local-test.sh
provider_installation {
dev_overrides {
"spiceai/spiceai" = "$PROJECT_DIR"
}
direct {}
}
EOF
log_info "Created ~/.terraformrc with dev_overrides"
log_info "Provider path: $PROJECT_DIR"
}
cmd_plan() {
check_credentials || exit 1
if [ ! -f "$PROVIDER_BINARY" ]; then
log_warn "Provider binary not found, building..."
cmd_build
fi
log_info "Running terraform plan..."
cd "$TEST_DIR"
terraform plan
}
cmd_apply() {
check_credentials || exit 1
if [ ! -f "$PROVIDER_BINARY" ]; then
log_warn "Provider binary not found, building..."
cmd_build
fi
log_info "Running terraform apply..."
cd "$TEST_DIR"
terraform apply
}
cmd_destroy() {
check_credentials || exit 1
log_info "Running terraform destroy..."
cd "$TEST_DIR"
terraform destroy
}
cmd_clean() {
log_info "Cleaning up terraform state files..."
cd "$TEST_DIR"
rm -rf .terraform .terraform.lock.hcl terraform.tfstate terraform.tfstate.backup
log_info "Cleaned up state files"
}
cmd_all() {
cmd_build
cmd_setup
cmd_plan
}
cmd_help() {
echo "Spice.ai Terraform Provider - Local Testing Helper"
echo ""
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " build - Build the provider binary"
echo " setup - Set up ~/.terraformrc with dev_overrides"
echo " plan - Run terraform plan in examples/test"
echo " apply - Run terraform apply in examples/test"
echo " destroy - Run terraform destroy in examples/test"
echo " clean - Clean up terraform state files"
echo " all - Build, setup, and run plan"
echo " help - Show this help message"
echo ""
echo "Environment variables required for plan/apply/destroy:"
echo " SPICEAI_CLIENT_ID - OAuth client ID"
echo " SPICEAI_CLIENT_SECRET - OAuth client secret"
echo ""
echo "Example:"
echo " export SPICEAI_CLIENT_ID=\"your-client-id\""
echo " export SPICEAI_CLIENT_SECRET=\"your-client-secret\""
echo " $0 all"
}
# Main
case "${1:-help}" in
build)
cmd_build
;;
setup)
cmd_setup
;;
plan)
cmd_plan
;;
apply)
cmd_apply
;;
destroy)
cmd_destroy
;;
clean)
cmd_clean
;;
all)
cmd_all
;;
help|--help|-h)
cmd_help
;;
*)
log_error "Unknown command: $1"
cmd_help
exit 1
;;
esac