Skip to content

Commit 6c024ff

Browse files
author
Berry Langerak
committed
Import namespace into Terraform state to prevent problems.
1 parent 503a2ee commit 6c024ff

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,19 @@ jobs:
208208
- name: Remove container from terraform.tfstate
209209
working-directory: ./terraform
210210
run: |
211-
# Check if state file exists and if resource exists in state
211+
# Check if state file exists and if resources exist in state
212212
if [ -f "terraform.tfstate" ]; then
213-
echo "State file found, checking for existing container resource..."
213+
echo "State file found, checking for existing resources..."
214+
215+
# Remove namespace if it exists in state
216+
if terraform state list | grep -q "nexaa_namespace.namespace"; then
217+
echo "Namespace resource found in state, removing..."
218+
terraform state rm nexaa_namespace.namespace
219+
else
220+
echo "Namespace resource not found in state, skipping removal"
221+
fi
222+
223+
# Remove container if it exists in state
214224
if terraform state list | grep -q "nexaa_container.container"; then
215225
echo "Container resource found in state, removing..."
216226
terraform state rm nexaa_container.container
@@ -227,7 +237,17 @@ jobs:
227237
- name: Terraform Import
228238
working-directory: ./terraform
229239
run: |
230-
# Try to import the container resource, but don't fail if it doesn't exist
240+
# Try to import the namespace resource first
241+
echo "Attempting to import namespace resource..."
242+
if terraform import nexaa_namespace.namespace simple-ci; then
243+
echo "✅ Namespace resource imported successfully"
244+
else
245+
echo "⚠️ Namespace resource import failed (resource may not exist remotely)"
246+
echo "This is normal for first deployments or if the namespace was deleted"
247+
echo "Terraform will create the resource during apply"
248+
fi
249+
250+
# Try to import the container resource
231251
echo "Attempting to import container resource..."
232252
if terraform import nexaa_container.container simple-ci/simple-ci; then
233253
echo "✅ Container resource imported successfully"

0 commit comments

Comments
 (0)