Skip to content

Commit 7e9ed3e

Browse files
committed
corrected terraform cmd
1 parent 6fce1eb commit 7e9ed3e

6 files changed

Lines changed: 64 additions & 23 deletions

File tree

run-samples.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ for (( i=START; i<START+COUNT; i++ )); do
118118
eval "$test"
119119
fi
120120

121+
# Cleanup Terraform state for terraform tests
122+
if [[ "$path" == *"/terraform" ]]; then
123+
echo "Cleaning up Terraform state..."
124+
rm -rf .terraform terraform.tfstate terraform.tfstate.backup .terraform.lock.hcl tfplan || true
125+
fi
126+
121127
popd > /dev/null
122128
echo "Completed: $path"
123129

samples/function-app-managed-identity/python/terraform/deploy.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ LOCATION='westeurope'
77
MANAGED_IDENTITY_TYPE='UserAssigned' # SystemAssigned or UserAssigned
88
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
99
ZIPFILE="function_app.zip"
10-
ENVIRONMENT=$(az account show --query environmentName --output tsv)
1110

1211
# Change the current directory to the script's directory
1312
cd "$CURRENT_DIR" || exit
1413

14+
# Determine environment - check if azlocal is configured first
15+
ENVIRONMENT=$(azlocal account show --query environmentName --output tsv 2>/dev/null || echo "")
16+
17+
if [[ -z "$ENVIRONMENT" ]]; then
18+
# Try with regular az if azlocal failed
19+
ENVIRONMENT=$(az account show --query environmentName --output tsv 2>/dev/null || echo "AzureCloud")
20+
fi
21+
1522
# Run terraform init and apply
1623
if [[ $ENVIRONMENT == "LocalStack" ]]; then
17-
echo "Using tflocal and azlocal for LocalStack emulator environment and ."
24+
echo "Using tflocal and azlocal for LocalStack emulator environment."
1825
TERRAFORM="tflocal"
1926
AZ="azlocal"
2027
else
@@ -49,8 +56,8 @@ if [[ $? != 0 ]]; then
4956
fi
5057

5158
# Get the output values
52-
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
53-
FUNCTION_APP_NAME=$(terraform output -raw function_app_name)
59+
RESOURCE_GROUP_NAME=$($TERRAFORM output -raw resource_group_name)
60+
FUNCTION_APP_NAME=$($TERRAFORM output -raw function_app_name)
5461

5562
if [[ -z "$RESOURCE_GROUP_NAME" || -z "$FUNCTION_APP_NAME" ]]; then
5663
echo "Resource Group Name or Function App Name is empty. Exiting."

samples/function-app-storage-http/dotnet/terraform/deploy.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ SUFFIX='test'
66
LOCATION='westeurope'
77
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
88
ZIPFILE="function_app.zip"
9-
ENVIRONMENT=$(az account show --query environmentName --output tsv)
109

1110
# Change the current directory to the script's directory
1211
cd "$CURRENT_DIR" || exit
1312

13+
# Determine environment - check if azlocal is configured first
14+
ENVIRONMENT=$(azlocal account show --query environmentName --output tsv 2>/dev/null || echo "")
15+
16+
if [[ -z "$ENVIRONMENT" ]]; then
17+
# Try with regular az if azlocal failed
18+
ENVIRONMENT=$(az account show --query environmentName --output tsv 2>/dev/null || echo "AzureCloud")
19+
fi
20+
1421
# Run terraform init and apply
1522
if [[ $ENVIRONMENT == "LocalStack" ]]; then
16-
echo "Using tflocal and azlocal for LocalStack emulator environment and ."
23+
echo "Using tflocal and azlocal for LocalStack emulator environment."
1724
TERRAFORM="tflocal"
1825
AZ="azlocal"
1926
else
@@ -47,8 +54,8 @@ if [[ $? != 0 ]]; then
4754
fi
4855

4956
# Get the output values
50-
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
51-
FUNCTION_APP_NAME=$(terraform output -raw function_app_name)
57+
RESOURCE_GROUP_NAME=$($TERRAFORM output -raw resource_group_name)
58+
FUNCTION_APP_NAME=$($TERRAFORM output -raw function_app_name)
5259

5360
# Print the variables
5461
echo "Resource Group: $RESOURCE_GROUP_NAME"

samples/web-app-cosmosdb-mongodb-api/python/terraform/deploy.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ SUFFIX='test'
66
LOCATION='westeurope'
77
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
88
ZIPFILE="planner_website.zip"
9-
ENVIRONMENT=$(az account show --query environmentName --output tsv)
109

1110
# Change the current directory to the script's directory
1211
cd "$CURRENT_DIR" || exit
1312

13+
# Determine environment - check if azlocal is configured first
14+
ENVIRONMENT=$(azlocal account show --query environmentName --output tsv 2>/dev/null || echo "")
15+
16+
if [[ -z "$ENVIRONMENT" ]]; then
17+
# Try with regular az if azlocal failed
18+
ENVIRONMENT=$(az account show --query environmentName --output tsv 2>/dev/null || echo "AzureCloud")
19+
fi
20+
1421
# Run terraform init and apply
1522
if [[ $ENVIRONMENT == "LocalStack" ]]; then
16-
echo "Using tflocal and azlocal for LocalStack emulator environment and ."
23+
echo "Using tflocal and azlocal for LocalStack emulator environment."
1724
TERRAFORM="tflocal"
1825
AZ="azlocal"
1926
else
@@ -47,8 +54,8 @@ if [[ $? != 0 ]]; then
4754
fi
4855

4956
# Get the output values
50-
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
51-
WEB_APP_NAME=$(terraform output -raw web_app_name)
57+
RESOURCE_GROUP_NAME=$($TERRAFORM output -raw resource_group_name)
58+
WEB_APP_NAME=$($TERRAFORM output -raw web_app_name)
5259

5360
# Print the variables
5461
echo "Resource Group: $RESOURCE_GROUP_NAME"

samples/web-app-managed-identity/python/terraform/deploy.sh

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ LOCATION='westeurope'
77
MANAGED_IDENTITY_TYPE='SystemAssigned' # SystemAssigned or UserAssigned
88
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
99
ZIPFILE="planner_website.zip"
10-
ENVIRONMENT=$(az account show --query environmentName --output tsv)
1110

1211
# Change the current directory to the script's directory
1312
cd "$CURRENT_DIR" || exit
1413

14+
# Determine environment - check if azlocal is configured first
15+
ENVIRONMENT=$(azlocal account show --query environmentName --output tsv 2>/dev/null || echo "")
16+
17+
if [[ -z "$ENVIRONMENT" ]]; then
18+
# Try with regular az if azlocal failed
19+
ENVIRONMENT=$(az account show --query environmentName --output tsv 2>/dev/null || echo "AzureCloud")
20+
fi
21+
1522
# Run terraform init and apply
1623
if [[ $ENVIRONMENT == "LocalStack" ]]; then
17-
echo "Using tflocal and azlocal for LocalStack emulator environment and ."
24+
echo "Using tflocal and azlocal for LocalStack emulator environment."
1825
TERRAFORM="tflocal"
1926
AZ="azlocal"
2027
else
@@ -49,9 +56,9 @@ if [[ $? != 0 ]]; then
4956
fi
5057

5158
# Get the output values
52-
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
53-
STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name)
54-
WEB_APP_NAME=$(terraform output -raw web_app_name)
59+
RESOURCE_GROUP_NAME=$($TERRAFORM output -raw resource_group_name)
60+
STORAGE_ACCOUNT_NAME=$($TERRAFORM output -raw storage_account_name)
61+
WEB_APP_NAME=$($TERRAFORM output -raw web_app_name)
5562

5663
# Check if output values are empty
5764
if [[ -z "$WEB_APP_NAME" || -z "$STORAGE_ACCOUNT_NAME" ]]; then

samples/web-app-sql-database/python/terraform/deploy.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,22 @@ DATABASE_USER_NAME='testuser'
1010
DATABASE_USER_PASSWORD='TestP@ssw0rd123'
1111
CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)"
1212
ZIPFILE="planner_website.zip"
13-
ENVIRONMENT=$(az account show --query environmentName --output tsv)
1413
DEPLOY_APP=1
1514

1615
# Change the current directory to the script's directory
1716
cd "$CURRENT_DIR" || exit
1817

18+
# Determine environment - check if azlocal is configured first
19+
ENVIRONMENT=$(azlocal account show --query environmentName --output tsv 2>/dev/null || echo "")
20+
21+
if [[ -z "$ENVIRONMENT" ]]; then
22+
# Try with regular az if azlocal failed
23+
ENVIRONMENT=$(az account show --query environmentName --output tsv 2>/dev/null || echo "AzureCloud")
24+
fi
25+
1926
# Run terraform init and apply
2027
if [[ $ENVIRONMENT == "LocalStack" ]]; then
21-
echo "Using tflocal and azlocal for LocalStack emulator environment and ."
28+
echo "Using tflocal and azlocal for LocalStack emulator environment."
2229
TERRAFORM="tflocal"
2330
AZ="azlocal"
2431
else
@@ -56,10 +63,10 @@ if [[ $? != 0 ]]; then
5663
fi
5764

5865
# Get the output values
59-
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
60-
WEB_APP_NAME=$(terraform output -raw web_app_name)
61-
SQL_SERVER_NAME=$(terraform output -raw sql_server_name)
62-
SQL_DATABASE_NAME=$(terraform output -raw sql_database_name)
66+
RESOURCE_GROUP_NAME=$($TERRAFORM output -raw resource_group_name)
67+
WEB_APP_NAME=$($TERRAFORM output -raw web_app_name)
68+
SQL_SERVER_NAME=$($TERRAFORM output -raw sql_server_name)
69+
SQL_DATABASE_NAME=$($TERRAFORM output -raw sql_database_name)
6370

6471
if [[ -z "$WEB_APP_NAME" || -z "$SQL_SERVER_NAME" || -z "$SQL_DATABASE_NAME" ]]; then
6572
echo "Web App Name, SQL Server Name, or SQL Database Name is empty. Exiting."

0 commit comments

Comments
 (0)