Skip to content

Commit b9ac095

Browse files
committed
Fixes
1 parent dd3b131 commit b9ac095

File tree

8 files changed

+67
-71
lines changed

8 files changed

+67
-71
lines changed

scenarios/AksOpenAiTerraform/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Terraform uses the ARM_SUBSCRIPTION_ID environment variable to authenticate whil
2424
export ARM_SUBSCRIPTION_ID="0c8875c7-e423-4caa-827a-1f0350bd8dd3"
2525
```
2626

27+
## Init Terraform
28+
29+
```bash
30+
terraform init
31+
```
32+
2733
## Run Terraform
2834

2935
```bash

scenarios/AksOpenAiTerraform/terraform/main.tf

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ provider "azurerm" {
1414
data "azurerm_client_config" "current" {
1515
}
1616

17+
resource "random_string" "rg_suffix" {
18+
length = 6
19+
special = false
20+
lower = false
21+
upper = false
22+
numeric = true
23+
}
24+
1725
locals {
1826
tenant_id = data.azurerm_client_config.current.tenant_id
27+
subscription_id = data.azurerm_client_config.current.subscription_id
28+
random_id = random_string.rg_suffix.result
1929

2030
vm_subnet_name = "VmSubnet"
2131
system_node_pool_subnet_name = "SystemSubnet"
@@ -29,14 +39,6 @@ locals {
2939
log_analytics_retention_days = 30
3040
}
3141

32-
resource "random_string" "rg_suffix" {
33-
length = 6
34-
special = false
35-
lower = false
36-
upper = false
37-
numeric = true
38-
}
39-
4042
resource "random_string" "storage_account_suffix" {
4143
length = 8
4244
special = false
@@ -46,16 +48,20 @@ resource "random_string" "storage_account_suffix" {
4648
}
4749

4850
resource "azurerm_resource_group" "rg" {
49-
name = "${var.name_prefix}-${random_string.rg_suffix.result}-rg"
51+
name = "${var.resource_group_name_prefix}-${local.random_id}-rg"
5052
location = var.location
53+
54+
lifecycle {
55+
ignore_changes = [tags]
56+
}
5157
}
5258

5359
###############################################################################
5460
# Application
5561
###############################################################################
5662
module "openai" {
5763
source = "./modules/openai"
58-
name = "${var.name_prefix}OpenAi"
64+
name = "OpenAi-${local.random_id}"
5965
location = var.location
6066
resource_group_name = azurerm_resource_group.rg.name
6167

@@ -69,16 +75,16 @@ module "openai" {
6975
}
7076
}
7177
]
72-
custom_subdomain_name = lower("${var.name_prefix}OpenAi")
78+
custom_subdomain_name = "magic8ball"
7379
public_network_access_enabled = true
74-
75-
log_analytics_workspace_id = module.log_analytics_workspace.id
76-
log_analytics_retention_days = local.log_analytics_retention_days
80+
81+
log_analytics_workspace_id = module.log_analytics_workspace.id
82+
log_analytics_retention_days = local.log_analytics_retention_days
7783
}
7884

7985
module "aks_cluster" {
8086
source = "./modules/aks"
81-
name = "${var.name_prefix}AksCluster"
87+
name = "AksCluster"
8288
location = var.location
8389
resource_group_name = azurerm_resource_group.rg.name
8490
resource_group_id = azurerm_resource_group.rg.id
@@ -103,7 +109,7 @@ module "aks_cluster" {
103109

104110
module "container_registry" {
105111
source = "./modules/container_registry"
106-
name = "${var.name_prefix}Acr"
112+
name = "azure-container-registry"
107113
location = var.location
108114
resource_group_name = azurerm_resource_group.rg.name
109115

@@ -127,7 +133,7 @@ module "storage_account" {
127133

128134
module "key_vault" {
129135
source = "./modules/key_vault"
130-
name = "${var.name_prefix}Vault"
136+
name = "KeyVault-${local.random_id}"
131137
location = var.location
132138
resource_group_name = azurerm_resource_group.rg.name
133139

@@ -147,20 +153,21 @@ module "key_vault" {
147153

148154
module "deployment_script" {
149155
source = "./modules/deployment_script"
150-
name = "${var.name_prefix}BashScript"
156+
name = "DeployBashScript"
151157
location = var.location
152158
resource_group_name = azurerm_resource_group.rg.name
153159

154-
azure_cli_version = "2.68.0"
155-
managed_identity_name = "${var.name_prefix}ScriptManagedIdentity"
160+
azure_cli_version = "2.64.0"
161+
aks_cluster_id = module.aks_cluster.id
162+
managed_identity_name = "ScriptManagedIdentity"
156163
aks_cluster_name = module.aks_cluster.name
157164
hostname = "magic8ball.contoso.com"
158165
namespace = local.namespace
159166
service_account_name = local.service_account_name
160167
email = var.email
161168
primary_script_uri = "https://paolosalvatori.blob.core.windows.net/scripts/install-nginx-via-helm-and-create-sa.sh"
162169
tenant_id = local.tenant_id
163-
subscription_id = data.azurerm_client_config.current.subscription_id
170+
subscription_id = local.subscription_id
164171
workload_managed_identity_client_id = azurerm_user_assigned_identity.aks_workload_identity.client_id
165172

166173
depends_on = [
@@ -170,7 +177,7 @@ module "deployment_script" {
170177

171178
module "log_analytics_workspace" {
172179
source = "./modules/log_analytics"
173-
name = "${var.name_prefix}${local.log_analytics_workspace_name}"
180+
name = "${local.log_analytics_workspace_name}"
174181
location = var.location
175182
resource_group_name = azurerm_resource_group.rg.name
176183

@@ -231,7 +238,7 @@ module "virtual_network" {
231238

232239
module "nat_gateway" {
233240
source = "./modules/nat_gateway"
234-
name = "${var.name_prefix}NatGateway"
241+
name = "NatGateway"
235242
location = var.location
236243
resource_group_name = azurerm_resource_group.rg.name
237244

@@ -240,7 +247,7 @@ module "nat_gateway" {
240247

241248
module "bastion_host" {
242249
source = "./modules/bastion_host"
243-
name = "${var.name_prefix}BastionHost"
250+
name = "BastionHost"
244251
location = var.location
245252
resource_group_name = azurerm_resource_group.rg.name
246253

@@ -259,7 +266,7 @@ module "acr_private_dns_zone" {
259266
resource_group_name = azurerm_resource_group.rg.name
260267
virtual_networks_to_link = {
261268
(module.virtual_network.name) = {
262-
subscription_id = data.azurerm_client_config.current.subscription_id
269+
subscription_id = local.subscription_id
263270
resource_group_name = azurerm_resource_group.rg.name
264271
}
265272
}
@@ -271,7 +278,7 @@ module "openai_private_dns_zone" {
271278
resource_group_name = azurerm_resource_group.rg.name
272279
virtual_networks_to_link = {
273280
(module.virtual_network.name) = {
274-
subscription_id = data.azurerm_client_config.current.subscription_id
281+
subscription_id = local.subscription_id
275282
resource_group_name = azurerm_resource_group.rg.name
276283
}
277284
}
@@ -283,7 +290,7 @@ module "key_vault_private_dns_zone" {
283290
resource_group_name = azurerm_resource_group.rg.name
284291
virtual_networks_to_link = {
285292
(module.virtual_network.name) = {
286-
subscription_id = data.azurerm_client_config.current.subscription_id
293+
subscription_id = local.subscription_id
287294
resource_group_name = azurerm_resource_group.rg.name
288295
}
289296
}
@@ -295,7 +302,7 @@ module "blob_private_dns_zone" {
295302
resource_group_name = azurerm_resource_group.rg.name
296303
virtual_networks_to_link = {
297304
(module.virtual_network.name) = {
298-
subscription_id = data.azurerm_client_config.current.subscription_id
305+
subscription_id = local.subscription_id
299306
resource_group_name = azurerm_resource_group.rg.name
300307
}
301308
}
@@ -306,7 +313,7 @@ module "blob_private_dns_zone" {
306313
###############################################################################
307314
module "openai_private_endpoint" {
308315
source = "./modules/private_endpoint"
309-
name = "${module.openai.name}PrivateEndpoint"
316+
name = "OpenAiPrivateEndpoint"
310317
location = var.location
311318
resource_group_name = azurerm_resource_group.rg.name
312319
subnet_id = module.virtual_network.subnet_ids[local.vm_subnet_name]
@@ -318,7 +325,7 @@ module "openai_private_endpoint" {
318325

319326
module "acr_private_endpoint" {
320327
source = "./modules/private_endpoint"
321-
name = "${module.container_registry.name}PrivateEndpoint"
328+
name = "AcrPrivateEndpoint"
322329
location = var.location
323330
resource_group_name = azurerm_resource_group.rg.name
324331
subnet_id = module.virtual_network.subnet_ids[local.vm_subnet_name]
@@ -330,7 +337,7 @@ module "acr_private_endpoint" {
330337

331338
module "key_vault_private_endpoint" {
332339
source = "./modules/private_endpoint"
333-
name = "${module.key_vault.name}PrivateEndpoint"
340+
name = "VaultPrivateEndpoint"
334341
location = var.location
335342
resource_group_name = azurerm_resource_group.rg.name
336343
subnet_id = module.virtual_network.subnet_ids[local.vm_subnet_name]
@@ -342,7 +349,7 @@ module "key_vault_private_endpoint" {
342349

343350
module "blob_private_endpoint" {
344351
source = "./modules/private_endpoint"
345-
name = "${var.name_prefix}BlobStoragePrivateEndpoint"
352+
name = "BlobStoragePrivateEndpoint"
346353
location = var.location
347354
resource_group_name = azurerm_resource_group.rg.name
348355
subnet_id = module.virtual_network.subnet_ids[local.vm_subnet_name]
@@ -356,7 +363,7 @@ module "blob_private_endpoint" {
356363
# Identities/Roles
357364
###############################################################################
358365
resource "azurerm_user_assigned_identity" "aks_workload_identity" {
359-
name = "${var.name_prefix}WorkloadManagedIdentity"
366+
name = "WorkloadManagedIdentity"
360367
resource_group_name = azurerm_resource_group.rg.name
361368
location = var.location
362369
}

scenarios/AksOpenAiTerraform/terraform/modules/aks/main.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ resource "azurerm_kubernetes_cluster" "aks_cluster" {
3030
zones = ["1", "2", "3"]
3131
max_pods = 50
3232
os_disk_type = "Ephemeral"
33+
34+
upgrade_settings {
35+
drain_timeout_in_minutes = 0
36+
max_surge = "10%"
37+
node_soak_duration_in_minutes = 0
38+
}
3339
}
3440

3541
identity {

scenarios/AksOpenAiTerraform/terraform/modules/deployment_script/main.tf

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@ resource "azurerm_user_assigned_identity" "script_identity" {
44
resource_group_name = var.resource_group_name
55
}
66

7-
data "azurerm_kubernetes_cluster" "aks_cluster" {
8-
name = var.aks_cluster_name
9-
resource_group_name = var.resource_group_name
10-
}
11-
127
resource "azurerm_role_assignment" "network_contributor_assignment" {
13-
scope = data.azurerm_kubernetes_cluster.aks_cluster.id
8+
scope = var.aks_cluster_id
149
role_definition_name = "Azure Kubernetes Service Cluster Admin Role"
1510
principal_id = azurerm_user_assigned_identity.script_identity.principal_id
16-
skip_service_principal_aad_check = true
1711
}
1812

1913
resource "azurerm_resource_deployment_script_azure_cli" "script" {
2014
name = var.name
2115
resource_group_name = var.resource_group_name
2216
location = var.location
17+
2318
version = var.azure_cli_version
2419
retention_interval = "P1D"
2520
command_line = "'foo' 'bar'"
2621
cleanup_preference = "OnSuccess"
2722
force_update_tag = "1"
2823
timeout = "PT30M"
2924
primary_script_uri = var.primary_script_uri
30-
tags = var.tags
3125

3226
identity {
3327
type = "UserAssigned"
Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,60 @@
11
variable "resource_group_name" {
2-
description = "(Required) Specifies the resource group name"
32
type = string
43
}
54

65
variable "location" {
7-
description = "(Required) Specifies the location of the Azure OpenAI Service"
86
type = string
97
}
108

119
variable "name" {
12-
description = "(Required) Specifies the name of the Azure OpenAI Service"
1310
type = string
14-
default = "BashScript"
11+
}
12+
13+
variable "aks_cluster_id" {
14+
type = string
1515
}
1616

1717
variable "azure_cli_version" {
18-
description = "(Required) Azure CLI module version to be used."
1918
type = string
20-
default = "2.9.1"
2119
}
2220

2321
variable "managed_identity_name" {
24-
description = "Specifies the name of the user-defined managed identity used by the deployment script."
2522
type = string
26-
default = "ScriptManagedIdentity"
2723
}
2824

2925
variable "primary_script_uri" {
30-
description = "(Optional) Uri for the script. This is the entry point for the external script. Changing this forces a new Resource Deployment Script to be created."
3126
type = string
3227
}
3328

3429
variable "aks_cluster_name" {
35-
description = "Specifies the name of the AKS cluster."
3630
type = string
3731
}
3832

3933
variable "tenant_id" {
40-
description = "Specifies the Azure AD tenant id."
4134
type = string
4235
}
4336

4437
variable "subscription_id" {
45-
description = "Specifies the Azure subscription id."
4638
type = string
4739
}
4840

4941
variable "hostname" {
50-
description = "Specifies the hostname of the application."
5142
type = string
5243
}
5344

5445
variable "namespace" {
55-
description = "Specifies the namespace of the application."
5646
type = string
5747
}
5848

5949
variable "service_account_name" {
60-
description = "Specifies the service account of the application."
6150
type = string
6251
}
6352

6453
variable "workload_managed_identity_client_id" {
65-
description = "Specifies the client id of the workload user-defined managed identity."
6654
type = string
6755
}
6856

6957
variable "email" {
7058
description = "Specifies the email address for the cert-manager cluster issuer."
7159
type = string
72-
}
73-
74-
variable "tags" {
75-
description = "(Optional) Specifies the tags of the Azure OpenAI Service"
76-
type = map(any)
77-
default = {}
7860
}

scenarios/AksOpenAiTerraform/terraform/modules/openai/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ resource "azurerm_cognitive_account" "openai" {
22
name = var.name
33
location = var.location
44
resource_group_name = var.resource_group_name
5+
56
kind = "OpenAI"
67
custom_subdomain_name = var.custom_subdomain_name
78
sku_name = var.sku_name

0 commit comments

Comments
 (0)