Skip to content

Commit 2d7c48b

Browse files
Merge branch 'main' into upgrade-dotnet-to-net10
2 parents f119cb1 + c15235f commit 2d7c48b

25 files changed

Lines changed: 202 additions & 385 deletions

File tree

.github/workflows/run-samples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
matrix:
2727
shard: [1, 2, 3, 4]
2828
splits: [4]
29-
runs-on: ubuntu-latest
29+
runs-on: github-ubuntu2204-amd64-4
3030

3131
env:
3232
IMAGE_NAME: localstack/localstack-azure-alpha

run-samples.sh

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ command -v localstack >/dev/null 2>&1 || { echo >&2 "localstack CLI is required
3232
command -v az >/dev/null 2>&1 || { echo >&2 "az CLI is required but not installed. Aborting."; exit 1; }
3333
command -v azlocal >/dev/null 2>&1 || { echo >&2 "azlocal is required but not installed. Run 'pip install azlocal'. Aborting."; exit 1; }
3434
command -v funclocal >/dev/null 2>&1 || { echo >&2 "funclocal is required but not installed. Run 'pip install azlocal'. Aborting."; exit 1; }
35-
command -v tflocal >/dev/null 2>&1 || { echo >&2 "tflocal is required but not installed. Run 'pip install terraform-local'. Aborting."; exit 1; }
35+
#command -v tflocal >/dev/null 2>&1 || { echo >&2 "tflocal is required but not installed. Run 'pip install terraform-local'. Aborting."; exit 1; }
3636
command -v terraform >/dev/null 2>&1 || { echo >&2 "terraform CLI is required but not installed. Aborting."; exit 1; }
3737
command -v func >/dev/null 2>&1 || { echo >&2 "Azure Functions Core Tools (func) is required but not installed. Aborting."; exit 1; }
3838

@@ -145,33 +145,29 @@ for (( i=START; i<START+COUNT; i++ )); do
145145
# Cleanup Bicep artifacts for bicep tests
146146
if [[ "$path" == *"/bicep" ]]; then
147147
echo "Cleaning up Bicep artifacts..."
148-
# Clean up zip files if any were created
149148
rm -f *.zip || true
150-
151-
# Clean up Azure resources to prevent state pollution between tests
152-
echo "Cleaning up Azure resources in LocalStack..."
153-
if command -v azlocal >/dev/null 2>&1; then
154-
echo "Deleting all resource groups..."
155-
# List and delete all resource groups
156-
RG_LIST=$(azlocal group list --query "[].name" -o tsv 2>/dev/null || echo "")
157-
if [[ -n "$RG_LIST" ]]; then
158-
echo "$RG_LIST" | while read -r rg; do
159-
if [[ -n "$rg" ]]; then
160-
echo " - Deleting resource group: $rg"
161-
azlocal group delete --name "$rg" --yes --no-wait 2>/dev/null || true
162-
fi
163-
done
164-
# Wait a bit for deletions to process
165-
sleep 2
166-
else
167-
echo " No resource groups to clean up"
168-
fi
169-
fi
170149
fi
171150

172151
popd > /dev/null
173152
echo "Completed: $path"
174153

154+
# Clean up Azure resources to prevent state pollution between tests
155+
echo "Cleaning up Azure resources in LocalStack..."
156+
if command -v azlocal >/dev/null 2>&1; then
157+
RG_LIST=$(azlocal group list --query "[].name" -o tsv 2>/dev/null || echo "")
158+
if [[ -n "$RG_LIST" ]]; then
159+
echo "$RG_LIST" | while read -r rg; do
160+
if [[ -n "$rg" ]]; then
161+
echo " - Deleting resource group: $rg"
162+
azlocal group delete --name "$rg" --yes --no-wait 2>/dev/null || true
163+
fi
164+
done
165+
sleep 2
166+
else
167+
echo " No resource groups to clean up"
168+
fi
169+
fi
170+
175171
# Cleanup Docker resources after each test to free up disk space
176172
echo "Cleaning up Docker resources..."
177173
docker system prune -af --volumes || true

samples/function-app-managed-identity/python/terraform/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,25 @@ The [deploy.sh](deploy.sh) script executes the following steps:
5656

5757
## Configuration
5858

59-
Before deploying the Terraform modules, update the `terraform.tfvars` file with your specific values:
59+
When using LocalStack for Azure, configure the `metadata_host` and `subscription_id` settings in the [Azure Provider for Terraform](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs) to ensure proper connectivity:
60+
6061

6162
```hcl
62-
location = "westeurope"
63-
python_version = "3.13"
63+
provider "azurerm" {
64+
features {
65+
resource_group {
66+
prevent_deletion_if_contains_resources = false
67+
}
68+
}
69+
70+
# Set the hostname of the Azure Metadata Service (for example management.azure.com)
71+
# used to obtain the Cloud Environment when using LocalStack's Azure emulator.
72+
# This allows the provider to correctly identify the environment and avoid making calls to the real Azure endpoints.
73+
metadata_host="localhost.localstack.cloud:4566"
74+
75+
# Set the subscription ID to a dummy value when using LocalStack's Azure emulator.
76+
subscription_id = "00000000-0000-0000-0000-000000000000"
77+
}
6478
```
6579

6680
## Deployment

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

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,45 @@
11
#!/bin/bash
22

33
# Variables
4-
PREFIX='funcmi'
4+
PREFIX='local'
55
SUFFIX='test'
66
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)
1011

1112
# Change the current directory to the script's directory
1213
cd "$CURRENT_DIR" || exit
1314

14-
# Determine environment
15-
if command -v az >/dev/null 2>&1; then
16-
CLOUD_NAME=$(az cloud show --query name --output tsv 2>&1 || echo "")
17-
18-
if [[ "$CLOUD_NAME" == "LocalStack" ]]; then
19-
ENVIRONMENT="LocalStack"
20-
elif [[ "$CLOUD_NAME" == "AzureCloud" ]]; then
21-
ENVIRONMENT="AzureCloud"
22-
else
23-
ENVIRONMENT="AzureCloud"
24-
fi
25-
else
26-
ENVIRONMENT="AzureCloud"
27-
fi
28-
2915
# Run terraform init and apply
3016
if [[ $ENVIRONMENT == "LocalStack" ]]; then
31-
echo "Using tflocal and azlocal for LocalStack emulator environment."
32-
TERRAFORM="tflocal"
33-
34-
# Log Azure auth environment variables before unsetting
35-
echo "[DEBUG] Azure auth env vars before unsetting:"
36-
echo "[DEBUG] ARM_CLIENT_ID=${ARM_CLIENT_ID:-<not set>}"
37-
echo "[DEBUG] ARM_CLIENT_SECRET=${ARM_CLIENT_SECRET:+<set but hidden>}${ARM_CLIENT_SECRET:-<not set>}"
38-
echo "[DEBUG] ARM_TENANT_ID=${ARM_TENANT_ID:-<not set>}"
39-
echo "[DEBUG] ARM_SUBSCRIPTION_ID=${ARM_SUBSCRIPTION_ID:-<not set>}"
40-
echo "[DEBUG] AZURE_CLIENT_ID=${AZURE_CLIENT_ID:-<not set>}"
41-
echo "[DEBUG] AZURE_TENANT_ID=${AZURE_TENANT_ID:-<not set>}"
42-
43-
echo "[DEBUG] Azure auth env vars after unsetting: all cleared"
17+
echo "Using azlocal for LocalStack emulator environment."
4418
AZ="azlocal"
4519
else
4620
echo "Using standard terraform and az for AzureCloud environment."
47-
TERRAFORM="terraform"
4821
AZ="az"
4922
fi
5023

51-
echo "[DEBUG] Cloud name: '$CLOUD_NAME', Environment: '$ENVIRONMENT', Tools: TERRAFORM=$TERRAFORM, AZ=$AZ"
52-
echo "[DEBUG] TERRAFORM command location: $(which $TERRAFORM 2>/dev/null || echo 'not found')"
53-
54-
# Enable Terraform debug logging
55-
export TF_LOG=DEBUG
56-
export TF_LOG_PATH="$CURRENT_DIR/terraform-debug.log"
57-
echo "[DEBUG] Checking what tflocal does..."echo "[DEBUG] tflocal version: $($TERRAFORM version 2>&1 | head -1)"echo "[DEBUG] Contents of current directory before init:"ls -la . 2>&1 | head -20
58-
echo "[DEBUG] Terraform debug logging enabled: TF_LOG=DEBUG, TF_LOG_PATH=$TF_LOG_PATH"
59-
6024
echo "Initializing Terraform..."
61-
$TERRAFORM init -upgrade
25+
terraform init -upgrade
6226

6327
# Run terraform plan and check for errors
6428
echo "Planning Terraform deployment..."
65-
$TERRAFORM plan -out=tfplan \
29+
terraform plan -out=tfplan \
6630
-var "prefix=$PREFIX" \
6731
-var "suffix=$SUFFIX" \
6832
-var "location=$LOCATION" \
6933
-var "managed_identity_type=$MANAGED_IDENTITY_TYPE"
7034

7135
if [[ $? != 0 ]]; then
7236
echo "Terraform plan failed. Exiting."
73-
echo "============================================================"
74-
echo "Last 100 lines of Terraform debug log:"
75-
echo "============================================================"
76-
tail -100 "$TF_LOG_PATH" 2>/dev/null || echo "Debug log not found"
77-
echo "============================================================"
7837
exit 1
7938
fi
8039

8140
# Apply the Terraform configuration
8241
echo "Applying Terraform configuration..."
83-
$TERRAFORM apply -auto-approve tfplan
42+
terraform apply -auto-approve tfplan
8443

8544
if [[ $? != 0 ]]; then
8645
echo "Terraform apply failed. Exiting."

samples/function-app-managed-identity/python/terraform/providers.tf

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@ provider "azurerm" {
1616
}
1717
}
1818

19-
# LocalStack Azure emulator configuration
20-
# Uses fixed credentials that tflocal intercepts via HTTPS proxy
21-
subscription_id = "00000000-0000-0000-0000-000000000000"
22-
tenant_id = "00000000-0000-0000-0000-000000000000"
23-
client_id = "00000000-0000-0000-0000-000000000000"
24-
client_secret = "fake-secret"
25-
26-
# Skip provider registration - LocalStack doesn't support this API
27-
skip_provider_registration = true
19+
# Set the hostname of the Azure Metadata Service (for example management.azure.com)
20+
# used to obtain the Cloud Environment when using LocalStack's Azure emulator.
21+
# This allows the provider to correctly identify the environment and avoid making calls to the real Azure endpoints.
22+
metadata_host="localhost.localstack.cloud:4566"
2823

29-
# Disable CLI/MSI authentication - use static credentials instead
30-
use_cli = false
31-
use_msi = false
24+
# Set the subscription ID to a dummy value when using LocalStack's Azure emulator.
25+
subscription_id = "00000000-0000-0000-0000-000000000000"
3226
}

samples/function-app-storage-http/dotnet/terraform/README.md

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,38 +49,61 @@ See [deploy.sh](deploy.sh) for the complete deployment automation. The script pe
4949
- Creates deployment zip package from published output
5050
- Deploys the zip to Azure Function App using Azure CLI
5151

52+
## Configuration
53+
54+
When using LocalStack for Azure, configure the `metadata_host` and `subscription_id` settings in the [Azure Provider for Terraform](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs) to ensure proper connectivity:
55+
56+
57+
```hcl
58+
provider "azurerm" {
59+
features {
60+
resource_group {
61+
prevent_deletion_if_contains_resources = false
62+
}
63+
}
64+
65+
# Set the hostname of the Azure Metadata Service (for example management.azure.com)
66+
# used to obtain the Cloud Environment when using LocalStack's Azure emulator.
67+
# This allows the provider to correctly identify the environment and avoid making calls to the real Azure endpoints.
68+
metadata_host="localhost.localstack.cloud:4566"
69+
70+
# Set the subscription ID to a dummy value when using LocalStack's Azure emulator.
71+
subscription_id = "00000000-0000-0000-0000-000000000000"
72+
}
73+
```
74+
5275
## Deployment
5376

54-
1. You can set up the Azure emulator by utilizing LocalStack for Azure Docker image. Before starting, ensure you have a valid `LOCALSTACK_AUTH_TOKEN` to access the Azure emulator. Refer to the [Auth Token guide](https://docs.localstack.cloud/getting-started/auth-token/?__hstc=108988063.8aad2b1a7229945859f4d9b9bb71e05d.1743148429561.1758793541854.1758810151462.32&__hssc=108988063.3.1758810151462&__hsfp=3945774529) to obtain your Auth Token and specify it in the `LOCALSTACK_AUTH_TOKEN` environment variable. The Azure Docker image is available on the [LocalStack Docker Hub](https://hub.docker.com/r/localstack/localstack-azure-alpha). To pull the Azure Docker image, execute the following command:
77+
You can set up the Azure emulator by utilizing LocalStack for Azure Docker image. Before starting, ensure you have a valid `LOCALSTACK_AUTH_TOKEN` to access the Azure emulator. Refer to the [Auth Token guide](https://docs.localstack.cloud/getting-started/auth-token/?__hstc=108988063.8aad2b1a7229945859f4d9b9bb71e05d.1743148429561.1758793541854.1758810151462.32&__hssc=108988063.3.1758810151462&__hsfp=3945774529) to obtain your Auth Token and specify it in the `LOCALSTACK_AUTH_TOKEN` environment variable. The Azure Docker image is available on the [LocalStack Docker Hub](https://hub.docker.com/r/localstack/localstack-azure-alpha). To pull the Azure Docker image, execute the following command:
5578

56-
```bash
57-
docker pull localstack/localstack-azure-alpha
58-
```
79+
```bash
80+
docker pull localstack/localstack-azure-alpha
81+
```
5982

60-
2. Start the LocalStack Azure emulator using the localstack CLI, execute the following command:
83+
Start the LocalStack Azure emulator using the localstack CLI, execute the following command:
6184

62-
```bash
63-
export LOCALSTACK_AUTH_TOKEN=<your_auth_token>
64-
IMAGE_NAME=localstack/localstack-azure-alpha localstack start
65-
```
85+
```bash
86+
export LOCALSTACK_AUTH_TOKEN=<your_auth_token>
87+
IMAGE_NAME=localstack/localstack-azure-alpha localstack start
88+
```
6689

67-
3. Navigate to the scripts directory
90+
Navigate to the `terraform` folder:
6891

69-
```bash
70-
cd samples/function-app-and-storage/dotnet/terraform
71-
```
92+
```bash
93+
cd samples/function-app-managed-identity/python/terraform
94+
```
7295

73-
4. Make the script executable:
96+
Make the script executable:
7497

75-
```bash
76-
chmod +x deploy.sh
77-
```
98+
```bash
99+
chmod +x deploy.sh
100+
```
78101

79-
5. Run the deployment script:
102+
Run the deployment script:
80103

81-
```bash
82-
./deploy.sh
83-
```
104+
```bash
105+
./deploy.sh
106+
```
84107

85108
## Validation
86109

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

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,88 +6,42 @@ 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)
910

1011
# Change the current directory to the script's directory
1112
cd "$CURRENT_DIR" || exit
1213

13-
# Determine environment
14-
if command -v az >/dev/null 2>&1; then
15-
CLOUD_NAME=$(az cloud show --query name --output tsv 2>&1 || echo "")
16-
17-
if [[ "$CLOUD_NAME" == "LocalStack" ]]; then
18-
ENVIRONMENT="LocalStack"
19-
elif [[ "$CLOUD_NAME" == "AzureCloud" ]]; then
20-
ENVIRONMENT="AzureCloud"
21-
else
22-
ENVIRONMENT="AzureCloud"
23-
fi
24-
else
25-
ENVIRONMENT="AzureCloud"
26-
fi
27-
2814
# Run terraform init and apply
2915
if [[ $ENVIRONMENT == "LocalStack" ]]; then
30-
echo "Using tflocal and azlocal for LocalStack emulator environment."
31-
TERRAFORM="tflocal"
32-
33-
# Log Azure auth environment variables before unsetting
34-
echo "[DEBUG] Azure auth env vars before unsetting:"
35-
echo "[DEBUG] ARM_CLIENT_ID=${ARM_CLIENT_ID:-<not set>}"
36-
echo "[DEBUG] ARM_CLIENT_SECRET=${ARM_CLIENT_SECRET:+<set but hidden>}${ARM_CLIENT_SECRET:-<not set>}"
37-
echo "[DEBUG] ARM_TENANT_ID=${ARM_TENANT_ID:-<not set>}"
38-
echo "[DEBUG] ARM_SUBSCRIPTION_ID=${ARM_SUBSCRIPTION_ID:-<not set>}"
39-
echo "[DEBUG] AZURE_CLIENT_ID=${AZURE_CLIENT_ID:-<not set>}"
40-
echo "[DEBUG] AZURE_TENANT_ID=${AZURE_TENANT_ID:-<not set>}"
41-
42-
echo "[DEBUG] Azure auth env vars after unsetting: all cleared"
16+
echo "Using azlocal for LocalStack emulator environment."
4317
AZ="azlocal"
4418
else
4519
echo "Using standard terraform and az for AzureCloud environment."
46-
TERRAFORM="terraform"
4720
AZ="az"
4821
fi
4922

50-
echo "[DEBUG] Cloud name: '$CLOUD_NAME', Environment: '$ENVIRONMENT', Tools: TERRAFORM=$TERRAFORM, AZ=$AZ"
51-
echo "[DEBUG] TERRAFORM command location: $(which $TERRAFORM 2>/dev/null || echo 'not found')"
52-
53-
# Enable Terraform debug logging
54-
export TF_LOG=DEBUG
55-
export TF_LOG_PATH="$CURRENT_DIR/terraform-debug.log"
56-
echo "[DEBUG] Checking what tflocal does..."echo "[DEBUG] tflocal version: $($TERRAFORM version 2>&1 | head -1)"echo "[DEBUG] Contents of current directory before init:"ls -la . 2>&1 | head -20
57-
echo "[DEBUG] Terraform debug logging enabled: TF_LOG=DEBUG, TF_LOG_PATH=$TF_LOG_PATH"
58-
5923
echo "Initializing Terraform..."
60-
$TERRAFORM init -upgrade
24+
terraform init -upgrade
6125

6226
# Run terraform plan and check for errors
6327
echo "Planning Terraform deployment..."
64-
$TERRAFORM plan -out=tfplan \
28+
terraform plan -out=tfplan \
6529
-var "prefix=$PREFIX" \
6630
-var "suffix=$SUFFIX" \
6731
-var "location=$LOCATION"
6832

69-
if [[ $? != 0 ]]; then
70-
echo "Terraform plan failed. Exiting."
71-
echo "============================================================"
72-
echo "Last 100 lines of Terraform debug log:"
73-
echo "============================================================"
74-
tail -100 "$TF_LOG_PATH" 2>/dev/null || echo "Debug log not found"
75-
echo "============================================================"
76-
exit 1
77-
fi
78-
7933
# Apply the Terraform configuration
8034
echo "Applying Terraform configuration..."
81-
$TERRAFORM apply -auto-approve tfplan
35+
terraform apply -auto-approve tfplan
8236

8337
if [[ $? != 0 ]]; then
8438
echo "Terraform apply failed. Exiting."
8539
exit 1
8640
fi
8741

8842
# Get the output values
89-
RESOURCE_GROUP_NAME=$($TERRAFORM output -raw resource_group_name)
90-
FUNCTION_APP_NAME=$($TERRAFORM output -raw function_app_name)
43+
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
44+
FUNCTION_APP_NAME=$(terraform output -raw function_app_name)
9145

9246
# Print the variables
9347
echo "Resource Group: $RESOURCE_GROUP_NAME"

0 commit comments

Comments
 (0)