Skip to content

Commit 1b82f8e

Browse files
authored
Fix Runner deployment issues and docs (#289)
* fixing deployment issues * chore: update azd version to 1.19.0 and add Node.js setup in workflows * refactor: move validation check for missing security roles into lifecycle block * fix: add --debug flag to azd provision for enhanced troubleshooting * chore: update Node.js and Terraform versions in CI workflow * chore: update azd version to 1.20.0 and enable Azure CLI authentication for azapi provider * fix: update azapi provider version to 2.7.0 * fix: update azapi provider version to 2.7.0 in multiple terraform files * fix: add environment variable logging to Azure deployment workflow * fix: add debug logging for environment variables in Azure deployment workflow * fix: downgrade azd version from 1.20.0 to 1.19.0 and comment out TF_LOG debug * fix: add wait for Azure OpenAI account provisioning and update dependencies in search configuration * fix: update azCliVersion to 2.74.0 and reduce timeout to 5 minutes in search index configuration * refactor: comment out non-dataverse user resource block in Power Platform configuration * refactor: uncomment data blocks for power platform user configuration * fix: update azd version to 1.20.0 in workflow configuration * fix: update azd version to 1.20.0 in workflow configuration * fix: update cognitive deployment model name to text-embedding-3-small * feat: add security rule to allow outbound internet access in network security group feat: update storage account configuration to clarify public network access chore: add launch configuration for .NET Core debugging chore: add tasks configuration for building and publishing .NET projects * refactor: move private endpoint creation outside module for proper provisioning wait time * cleaning up * feat: enhance GitHub runner installation script with user existence check and cleanup of existing configurations * fix: restore denied inbound and outbound traffic rules in network security group * fix: add comment to clarify purpose of security rule for storage IP * fix: remove redundant deny rules for inbound and outbound traffic in network security group * feat: add default outbound access configuration and update tagging for network resources
1 parent 67eb019 commit 1b82f8e

File tree

18 files changed

+109
-79
lines changed

18 files changed

+109
-79
lines changed

.github/workflows/azure-dev-down.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ jobs:
3333
- name: Install azd
3434
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
3535
with:
36-
version: '1.18.1' # Specify your desired azd version here
36+
version: '1.20.0' # Specify your desired azd version here
37+
38+
- name: Setup Node.js
39+
uses: actions/setup-node@v4
40+
with:
41+
node-version: '18.x'
3742

3843
- name: Install Terraform
3944
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
4045
with:
41-
terraform_version: 1.12.2
46+
terraform_version: 1.13.3
4247

4348
- name: Login to Azure with Federated Identity
4449
uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0

.github/workflows/azure-dev.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ jobs:
4545
- name: Install azd
4646
uses: Azure/setup-azd@ae0f8b5482eeac61e940f447327d84c73beb8b1e # v2.1.0
4747
with:
48-
version: '1.18.1' # Specify your desired azd version here
48+
version: '1.20.0' # Specify your desired azd version here
49+
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: '18.x'
54+
55+
- name: Install Terraform
56+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
57+
with:
58+
terraform_version: 1.13.3
4959

5060
- name: Install TFLint
5161
uses: terraform-linters/setup-tflint@90f302c255ef959cbfb4bd10581afecdb7ece3e6 # v4.1.1

cicd/github_runner_aca/terraform.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
}
88
azapi = {
99
source = "Azure/azapi"
10-
version = "~> 2.5"
10+
version = "~> 2.7.0"
1111
}
1212
}
1313
}

cicd/github_runner_vm/install-github-runner.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ usermod -aG docker azureuser
113113

114114
# Create a dedicated user for the runner
115115
log "Creating GitHub runner user..."
116-
useradd -m -d /home/github-runner -s /bin/bash github-runner
116+
if id "github-runner" &>/dev/null; then
117+
log "User github-runner already exists, skipping creation"
118+
else
119+
useradd -m -d /home/github-runner -s /bin/bash github-runner
120+
log "User github-runner created successfully"
121+
fi
117122
usermod -aG docker github-runner
118123

119124
# Create sudoers file for github-runner
@@ -178,8 +183,20 @@ rm "$${RUNNER_TARBALL}"
178183
# Set ownership
179184
chown -R github-runner:github-runner "$RUNNER_DIR"
180185

186+
# Remove existing runner configuration if it exists
187+
log "Checking for existing runner configuration..."
188+
if [ -f "$RUNNER_DIR/.runner" ]; then
189+
log "Existing runner configuration found, removing..."
190+
# Stop and uninstall the service first
191+
cd "$RUNNER_DIR"
192+
./svc.sh stop 2>/dev/null || log "Service was not running"
193+
./svc.sh uninstall 2>/dev/null || log "Service was not installed"
194+
# Now remove the configuration
195+
sudo -u github-runner bash -c "cd '$RUNNER_DIR' && ./config.sh remove --token '$RUNNER_TOKEN'" || log "Failed to remove existing configuration, continuing anyway"
196+
fi
197+
181198
log "Configuring GitHub Actions runner..."
182-
sudo -u github-runner bash -c "cd '$RUNNER_DIR' && ./config.sh --url '$GITHUB_URL' --token '$RUNNER_TOKEN' --name '$RUNNER_NAME' --work '$RUNNER_WORK_FOLDER' --labels '$RUNNER_LABELS' --unattended --replace"
199+
sudo -u github-runner bash -c "cd '$RUNNER_DIR' && ./config.sh --url '$GITHUB_URL' --token '$RUNNER_TOKEN' --name '$RUNNER_NAME' --work '$RUNNER_WORK_FOLDER' --labels '$RUNNER_LABELS' --unattended --replace" || true
183200

184201
# Install the runner as a service
185202
log "Installing runner as a service..."

cicd/github_runner_vm/main.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ resource "local_file" "github_runner_private_key" {
6767
file_permission = "0600"
6868
}
6969

70+
# Cleanup existing extension before creating new one
71+
resource "null_resource" "cleanup_extension" {
72+
count = var.github_runner_os_type == "linux" ? 1 : 0
73+
74+
triggers = {
75+
always = timestamp()
76+
}
77+
78+
provisioner "local-exec" {
79+
command = <<-EOT
80+
az vm extension delete \
81+
--resource-group ${var.resource_group_name} \
82+
--vm-name vm-github-runner-${var.unique_id} \
83+
--name install-github-runner \
84+
2>/dev/null || true
85+
EOT
86+
}
87+
88+
depends_on = [azurerm_linux_virtual_machine.github_runner]
89+
}
90+
7091
# Custom Script Extension to install and configure GitHub Actions Runner
7192
resource "azurerm_virtual_machine_extension" "github_runner" {
7293
count = var.github_runner_os_type == "linux" ? 1 : 0
@@ -90,6 +111,15 @@ resource "azurerm_virtual_machine_extension" "github_runner" {
90111

91112
tags = var.tags
92113

93-
depends_on = [azurerm_linux_virtual_machine.github_runner]
114+
lifecycle {
115+
replace_triggered_by = [
116+
null_resource.cleanup_extension[0]
117+
]
118+
}
119+
120+
depends_on = [
121+
azurerm_linux_virtual_machine.github_runner,
122+
null_resource.cleanup_extension
123+
]
94124
}
95125

cicd/network.runner.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ resource "azurerm_subnet" "github_runner" {
88
# GitHub runners don't need private endpoint policies
99
private_endpoint_network_policies = "Disabled"
1010

11+
default_outbound_access_enabled = "false"
12+
1113
dynamic "delegation" {
1214
for_each = var.github_runner_type == "aca" ? [1] : []
1315
content {
@@ -26,7 +28,7 @@ resource "azurerm_network_security_group" "github_runner" {
2628
name = "nsg-github-runner-${random_id.suffix.hex}"
2729
location = azurerm_resource_group.tfstate.location
2830
resource_group_name = azurerm_resource_group.tfstate.name
29-
tags = local.common_tags
31+
tags = var.tags
3032

3133
# VM-specific rules (conditionally added when github_runner_type == "vm")
3234
# dynamic "security_rule" {
@@ -182,7 +184,7 @@ resource "azurerm_public_ip" "github_runner_nat_ip" {
182184
resource_group_name = azurerm_resource_group.tfstate.name
183185
allocation_method = "Static"
184186
sku = "Standard"
185-
tags = local.common_tags
187+
tags = var.tags
186188
}
187189

188190
# Create NAT Gateway
@@ -191,7 +193,7 @@ resource "azurerm_nat_gateway" "github_runner" {
191193
location = azurerm_resource_group.tfstate.location
192194
resource_group_name = azurerm_resource_group.tfstate.name
193195
sku_name = "Standard"
194-
tags = local.common_tags
196+
tags = var.tags
195197
}
196198

197199
# Associate Public IP with NAT Gateway

cicd/network.storage.tf

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,16 @@ resource "azurerm_subnet" "storage" {
1010

1111
# Enable private endpoint network policies
1212
private_endpoint_network_policies = "Enabled"
13+
14+
default_outbound_access_enabled = "false"
1315
}
1416

1517
# Create Network Security Group
1618
resource "azurerm_network_security_group" "storage" {
1719
name = local.nsg_name
1820
location = azurerm_resource_group.tfstate.location
1921
resource_group_name = azurerm_resource_group.tfstate.name
20-
tags = local.common_tags
21-
22-
# Allow inbound HTTPS traffic within the subnet
23-
security_rule {
24-
name = "AllowHTTPSInbound"
25-
priority = 100
26-
direction = "Inbound"
27-
access = "Allow"
28-
protocol = "Tcp"
29-
source_port_range = "*"
30-
destination_port_range = "443"
31-
source_address_prefix = azurerm_subnet.storage.address_prefixes[0]
32-
destination_address_prefix = azurerm_subnet.storage.address_prefixes[0]
33-
}
22+
tags = var.tags
3423

3524
# Allow outbound HTTPS traffic
3625
security_rule {
@@ -57,31 +46,6 @@ resource "azurerm_network_security_group" "storage" {
5746
source_address_prefix = azurerm_subnet.github_runner.address_prefixes[0]
5847
destination_address_prefix = azurerm_subnet.storage.address_prefixes[0]
5948
}
60-
61-
# Deny all other inbound traffic
62-
security_rule {
63-
name = "DenyAllInbound"
64-
priority = 4096
65-
direction = "Inbound"
66-
access = "Deny"
67-
protocol = "*"
68-
source_port_range = "*"
69-
destination_port_range = "*"
70-
source_address_prefix = "*"
71-
destination_address_prefix = "*"
72-
}
73-
# Deny all other outbound traffic
74-
security_rule {
75-
name = "DenyAllOutbound"
76-
priority = 4096
77-
direction = "Outbound"
78-
access = "Deny"
79-
protocol = "*"
80-
source_port_range = "*"
81-
destination_port_range = "*"
82-
source_address_prefix = "*"
83-
destination_address_prefix = "*"
84-
}
8549
}
8650

8751
# Associate NSG with Subnet
@@ -94,7 +58,7 @@ resource "azurerm_subnet_network_security_group_association" "storage" {
9458
resource "azurerm_private_dns_zone" "blob" {
9559
name = "privatelink.blob.core.windows.net"
9660
resource_group_name = azurerm_resource_group.tfstate.name
97-
tags = local.common_tags
61+
tags = var.tags
9862
}
9963

10064
# Link Private DNS Zone to Virtual Network
@@ -104,7 +68,7 @@ resource "azurerm_private_dns_zone_virtual_network_link" "blob" {
10468
private_dns_zone_name = azurerm_private_dns_zone.blob.name
10569
virtual_network_id = azurerm_virtual_network.tfstate.id
10670
registration_enabled = false
107-
tags = local.common_tags
71+
tags = var.tags
10872
}
10973

11074
# Create Private Endpoint for Storage Account
@@ -113,7 +77,7 @@ resource "azurerm_private_endpoint" "storage_blob" {
11377
location = azurerm_resource_group.tfstate.location
11478
resource_group_name = azurerm_resource_group.tfstate.name
11579
subnet_id = azurerm_subnet.storage.id
116-
tags = local.common_tags
80+
tags = var.tags
11781

11882
private_service_connection {
11983
name = "pe-connection-${random_id.suffix.hex}"

cicd/network.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ resource "azurerm_virtual_network" "tfstate" {
44
address_space = var.network_config.vnet_address_space
55
location = azurerm_resource_group.tfstate.location
66
resource_group_name = azurerm_resource_group.tfstate.name
7-
tags = local.common_tags
7+
tags = var.tags
88
}

cicd/runner.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module "github_runner_vm" {
1919
github_runner_registration_token = var.github_runner_registration_token
2020

2121
# Tags
22-
tags = local.common_tags
22+
tags = var.tags
2323

2424
# Ensure NSG is associated to the subnet before provisioning the VM and its extension
2525
depends_on = [
@@ -47,7 +47,7 @@ module "github_runner_aca_primary" {
4747

4848
# openai_endpoint = module.azure_open_ai.endpoint
4949

50-
tags = local.common_tags
50+
tags = var.tags
5151

5252
# Ensure NSG is associated to the subnet before provisioning ACA
5353
depends_on = [

cicd/terraform.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ terraform {
77
}
88
azapi = {
99
source = "Azure/azapi"
10-
version = "~> 2.5"
10+
version = "~> 2.7.0"
1111
}
1212
random = {
1313
source = "hashicorp/random"

0 commit comments

Comments
 (0)