Skip to content

Commit b1bf7ea

Browse files
committed
Fixed Artifact not found for name: terraform-outputs
1 parent 8f7d1c6 commit b1bf7ea

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

.github/workflows/main.yml

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,30 @@ name: Deploy API
22

33
on:
44
workflow_run:
5-
workflows: ["Terraform CI/CD"] # ⚠️ Nombre EXACTO del workflow de Terraform
5+
workflows: ["Terraform CI/CD"]
66
branches: [master]
7-
types:
8-
- completed # Espera a que el workflow de Terraform termine
7+
types: [completed]
98

109
env:
1110
NODE_VERSION: 16
1211

1312
permissions:
1413
contents: read
14+
actions: read # Required for cross-workflow artifacts
1515
id-token: write
1616

1717
jobs:
1818
deploy:
19-
# ⚠️ Solo se ejecuta si Terraform CI/CD fue exitoso
2019
if: ${{ github.event.workflow_run.conclusion == 'success' }}
2120
runs-on: ubuntu-latest
2221

2322
steps:
2423
- uses: actions/checkout@v3
2524

25+
# Add delay to ensure artifact availability
26+
- name: ⏳ Wait for artifact propagation
27+
run: sleep 15
28+
2629
- name: 🟢 Set up Node.js
2730
uses: actions/setup-node@v3
2831
with:
@@ -48,37 +51,47 @@ jobs:
4851
with:
4952
name: terraform-outputs
5053
path: infra/
51-
pattern: tf_outputs.json
54+
continue-on-error: true # Will fallback to direct method if fails
5255

53-
- name: 🔍 Verify Download
54-
run: |
55-
ls -la infra/
56-
if [ -f "infra/terraform-outputs.json" ]; then
57-
echo "✅ File downloaded successfully"
58-
cat infra/terraform-outputs.json
59-
else
60-
echo "❌ File not found"
61-
exit 1
62-
fi
63-
- name: 📤 Export Terraform Outputs (Versión usando el artifact)
64-
id: tf
56+
# Fallback method if artifact download fails
57+
- name: 📤 Get Outputs Directly (Fallback)
58+
if: ${{ failure() && steps.download.outcome == 'failure' }}
59+
env:
60+
TF_CLI_ARGS: "-chdir=infra"
6561
run: |
66-
json=$(cat infra/tf_outputs.json)
67-
echo "DB_HOST=$(echo $json | jq -r '.mysql_fqdn.value')" >> $GITHUB_ENV
68-
echo "DB_USER=$(echo $json | jq -r '.mysql_admin_user.value')" >> $GITHUB_ENV
69-
echo "DB_NAME=$(echo $json | jq -r '.mysql_database_name.value')" >> $GITHUB_ENV
62+
terraform init \
63+
-backend-config="resource_group_name=soft-tfstate-rg" \
64+
-backend-config="storage_account_name=softsastate" \
65+
-backend-config="container_name=tfstate" \
66+
-backend-config="key=terraform.tfstate"
67+
68+
echo "DB_HOST=$(terraform output -raw mysql_fqdn)" >> $GITHUB_ENV
69+
echo "DB_USER=$(terraform output -raw mysql_admin_user)" >> $GITHUB_ENV
70+
echo "DB_NAME=$(terraform output -raw mysql_database_name)" >> $GITHUB_ENV
7071
echo "DB_PASS<<EOF" >> $GITHUB_ENV
71-
echo "$(echo $json | jq -r '.mysql_admin_pwd.value')" >> $GITHUB_ENV
72+
echo "$(terraform output -raw mysql_admin_pwd)" >> $GITHUB_ENV
7273
echo "EOF" >> $GITHUB_ENV
7374
74-
# ... (el resto de tus pasos permanecen igual)
75-
- name: ✅ Validate Terraform Outputs
75+
- name: 🔍 Verify Outputs
7676
run: |
77-
if [ -z "$DB_HOST" ] || [ -z "$DB_USER" ] || [ -z "$DB_PASS" ] || [ -z "$DB_NAME" ]; then
78-
echo "❌ One or more Terraform outputs are missing"
77+
echo "Verifying infrastructure outputs..."
78+
if [ -f "infra/tf_outputs.json" ]; then
79+
echo "✅ Using artifact file"
80+
json=$(cat infra/tf_outputs.json)
81+
echo "DB_HOST=$(echo $json | jq -r '.mysql_fqdn.value')" >> $GITHUB_ENV
82+
echo "DB_USER=$(echo $json | jq -r '.mysql_admin_user.value')" >> $GITHUB_ENV
83+
echo "DB_NAME=$(echo $json | jq -r '.mysql_database_name.value')" >> $GITHUB_ENV
84+
echo "DB_PASS<<EOF" >> $GITHUB_ENV
85+
echo "$(echo $json | jq -r '.mysql_admin_pwd.value')" >> $GITHUB_ENV
86+
echo "EOF" >> $GITHUB_ENV
87+
fi
88+
89+
if [ -z "$DB_HOST" ] || [ -z "$DB_USER" ] || [ -z "$DB_PASS" ] || [ -z "$DB_NAME" ]; then
90+
echo "❌ Critical: Missing required environment variables"
7991
exit 1
80-
fi
92+
fi
8193
94+
# Rest of your steps remain unchanged
8295
- name: 🔑 Configure SSH
8396
run: |
8497
mkdir -p ~/.ssh

.github/workflows/terraform.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: read
11+
actions: read
1112
id-token: write
1213

1314
env:
@@ -123,13 +124,20 @@ jobs:
123124
echo "File content:"
124125
head -n 3 infra/tf_outputs.json
125126
127+
# - name: 📦 Upload Terraform Outputs
128+
# uses: actions/upload-artifact@v4
129+
# with:
130+
# name: terraform-outputs
131+
# path: infra/tf_outputs.json
132+
# if-no-files-found: error
133+
# retention-days: 3
134+
126135
- name: 📦 Upload Terraform Outputs
127136
uses: actions/upload-artifact@v4
128137
with:
129-
name: terraform-outputs
138+
name: terraform-outputs-v1
130139
path: infra/tf_outputs.json
131-
if-no-files-found: error
132-
retention-days: 3
140+
retention-days: 1
133141

134142
- name: 📦 Upload inventory.ini as artifact
135143
uses: actions/upload-artifact@v4

0 commit comments

Comments
 (0)