Skip to content

Commit 90c5927

Browse files
committed
fixed wg config issue
Signed-off-by: bhumi46 <thisisbn46@gmail.com>
1 parent a4a9248 commit 90c5927

2 files changed

Lines changed: 58 additions & 6 deletions

File tree

.github/workflows/terraform-destroy.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,39 @@ jobs:
176176
echo "Please configure the WireGuard configuration secret for this branch/environment"
177177
exit 1
178178
fi
179-
echo "${{ secrets.TF_WG_CONFIG }}" | sudo tee /etc/wireguard/wg0.conf
180-
# Verify config file is not empty
179+
180+
# Debug: Check if secret is available (without exposing content)
181+
echo "🔍 Checking TF_WG_CONFIG secret..."
182+
if [ ${#TF_WG_CONFIG} -eq 0 ]; then
183+
echo "❌ ERROR: TF_WG_CONFIG environment variable is empty"
184+
echo "Secret may contain only whitespace or special characters"
185+
exit 1
186+
fi
187+
echo "✅ Secret length: ${#TF_WG_CONFIG} characters"
188+
189+
# Create config file with proper handling of multiline content
190+
sudo mkdir -p /etc/wireguard
191+
echo "$TF_WG_CONFIG" | sudo tee /etc/wireguard/wg0.conf > /dev/null
192+
193+
# Verify config file is not empty and has expected content
181194
if [ ! -s /etc/wireguard/wg0.conf ]; then
182-
echo "❌ ERROR: WireGuard config file is empty!"
195+
echo "❌ ERROR: WireGuard config file is empty after writing!"
196+
echo "This usually means the secret contains only whitespace or invalid characters"
183197
exit 1
184198
fi
199+
200+
# Basic validation that it looks like a WireGuard config
201+
if ! grep -q "\[Interface\]" /etc/wireguard/wg0.conf; then
202+
echo "❌ ERROR: WireGuard config doesn't contain [Interface] section"
203+
echo "Please check that TF_WG_CONFIG contains a valid WireGuard configuration"
204+
echo "Config file size: $(wc -c < /etc/wireguard/wg0.conf) bytes"
205+
exit 1
206+
fi
207+
185208
echo "✅ WireGuard configuration applied successfully"
209+
echo "Config file size: $(wc -c < /etc/wireguard/wg0.conf) bytes"
210+
env:
211+
TF_WG_CONFIG: ${{ secrets.TF_WG_CONFIG }}
186212
if: "${{ inputs.TERRAFORM_COMPONENT != 'base-infra' }}"
187213

188214
- name: Start WireGuard

.github/workflows/terraform.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,39 @@ jobs:
138138
echo "Please configure the WireGuard configuration secret for this branch/environment"
139139
exit 1
140140
fi
141-
echo "${{ secrets.TF_WG_CONFIG }}" | sudo tee /etc/wireguard/wg0.conf
142-
# Verify config file is not empty
141+
142+
# Debug: Check if secret is available (without exposing content)
143+
echo "🔍 Checking TF_WG_CONFIG secret..."
144+
if [ ${#TF_WG_CONFIG} -eq 0 ]; then
145+
echo "❌ ERROR: TF_WG_CONFIG environment variable is empty"
146+
echo "Secret may contain only whitespace or special characters"
147+
exit 1
148+
fi
149+
echo "✅ Secret length: ${#TF_WG_CONFIG} characters"
150+
151+
# Create config file with proper handling of multiline content
152+
sudo mkdir -p /etc/wireguard
153+
echo "$TF_WG_CONFIG" | sudo tee /etc/wireguard/wg0.conf > /dev/null
154+
155+
# Verify config file is not empty and has expected content
143156
if [ ! -s /etc/wireguard/wg0.conf ]; then
144-
echo "❌ ERROR: WireGuard config file is empty!"
157+
echo "❌ ERROR: WireGuard config file is empty after writing!"
158+
echo "This usually means the secret contains only whitespace or invalid characters"
145159
exit 1
146160
fi
161+
162+
# Basic validation that it looks like a WireGuard config
163+
if ! grep -q "\[Interface\]" /etc/wireguard/wg0.conf; then
164+
echo "❌ ERROR: WireGuard config doesn't contain [Interface] section"
165+
echo "Please check that TF_WG_CONFIG contains a valid WireGuard configuration"
166+
echo "Config file size: $(wc -c < /etc/wireguard/wg0.conf) bytes"
167+
exit 1
168+
fi
169+
147170
echo "✅ WireGuard configuration applied successfully"
171+
echo "Config file size: $(wc -c < /etc/wireguard/wg0.conf) bytes"
172+
env:
173+
TF_WG_CONFIG: ${{ secrets.TF_WG_CONFIG }}
148174
if: "${{ inputs.TERRAFORM_COMPONENT != 'base-infra' }}"
149175

150176
- name: Start WireGuard

0 commit comments

Comments
 (0)