Skip to content

Commit 63fd046

Browse files
rajbosCopilot
andcommitted
fix: pass all TF_VARs to import step and add -input=false
terraform import prompts interactively for missing required variables, blocking the workflow and holding the state lock open. Fix by passing all the same env vars as plan/apply, and adding -input=false to fail fast rather than prompt if any variable is still missing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 257dcd4 commit 63fd046

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

.github/workflows/sharing-server-deploy.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,23 @@ jobs:
170170
if: steps.prereqs.outputs.configured == 'true' && vars.SHARING_CUSTOM_DOMAIN != ''
171171
working-directory: sharing-server/infra
172172
env:
173-
TF_VAR_resource_group_name: ${{ vars.AZURE_RESOURCE_GROUP }}
174-
TF_VAR_app_name: ${{ needs.setup.outputs.app_name }}
175-
TF_VAR_custom_domain: ${{ vars.SHARING_CUSTOM_DOMAIN }}
173+
TF_VAR_resource_group_name: ${{ vars.AZURE_RESOURCE_GROUP }}
174+
TF_VAR_location: ${{ vars.AZURE_LOCATION || 'westeurope' }}
175+
TF_VAR_app_name: ${{ needs.setup.outputs.app_name }}
176+
TF_VAR_container_image: ${{ needs.build.outputs.image }}
177+
TF_VAR_github_client_id: ${{ secrets.SHARING_GITHUB_CLIENT_ID }}
178+
TF_VAR_github_client_secret: ${{ secrets.SHARING_GITHUB_CLIENT_SECRET }}
179+
TF_VAR_session_secret: ${{ secrets.SHARING_SESSION_SECRET }}
180+
TF_VAR_allowed_github_org: ${{ vars.SHARING_ALLOWED_GITHUB_ORG }}
181+
TF_VAR_github_org_check_token: ${{ secrets.ORG_CHECK_TOKEN }}
182+
TF_VAR_min_replicas: ${{ needs.setup.outputs.min_replicas }}
183+
TF_VAR_custom_domain: ${{ vars.SHARING_CUSTOM_DOMAIN }}
176184
run: |
177-
# Authenticate az CLI with the same service principal used by Terraform.
178185
az login --service-principal -u "$ARM_CLIENT_ID" -p "$ARM_CLIENT_SECRET" --tenant "$ARM_TENANT_ID" --output none
179186
az account set --subscription "$ARM_SUBSCRIPTION_ID"
180187
181188
ENV_NAME="${TF_VAR_app_name}-env"
182189
183-
# Import managed certificate if it already exists in Azure but not in state.
184190
if ! terraform state show 'azurerm_container_app_environment_managed_certificate.this[0]' > /dev/null 2>&1; then
185191
CERT_ID=$(az containerapp env certificate list \
186192
--name "$ENV_NAME" \
@@ -189,16 +195,15 @@ jobs:
189195
-o tsv 2>/dev/null || true)
190196
if [[ -n "$CERT_ID" && "$CERT_ID" != "None" ]]; then
191197
echo "Importing managed certificate: $CERT_ID"
192-
terraform import 'azurerm_container_app_environment_managed_certificate.this[0]' "$CERT_ID"
198+
terraform import -input=false 'azurerm_container_app_environment_managed_certificate.this[0]' "$CERT_ID"
193199
fi
194200
fi
195201
196-
# Import custom domain binding if it already exists in Azure but not in state.
197202
if ! terraform state show 'azurerm_container_app_custom_domain.this[0]' > /dev/null 2>&1; then
198203
DOMAIN_ID="/subscriptions/$ARM_SUBSCRIPTION_ID/resourceGroups/$TF_VAR_resource_group_name/providers/Microsoft.App/containerApps/$TF_VAR_app_name/customDomainName/$TF_VAR_custom_domain"
199204
if az rest --method get --url "https://management.azure.com${DOMAIN_ID}?api-version=2024-03-01" > /dev/null 2>&1; then
200205
echo "Importing custom domain: $DOMAIN_ID"
201-
terraform import 'azurerm_container_app_custom_domain.this[0]' "$DOMAIN_ID"
206+
terraform import -input=false 'azurerm_container_app_custom_domain.this[0]' "$DOMAIN_ID"
202207
fi
203208
fi
204209

0 commit comments

Comments
 (0)