Repository navigation
Expand file tree
/
Copy pathGet-LabEnvironment.ps1
More file actions
111 lines (101 loc) · 4.33 KB
/
Copy pathGet-LabEnvironment.ps1
File metadata and controls
111 lines (101 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<#
.SYNOPSIS
Resolve deployed lab resource names from Terraform outputs.
.DESCRIPTION
Single source of truth for resource names. The name suffix is randomly generated,
so it changes on every rebuild - scripts must never hardcode it.
Returns an object with names, endpoints, ARM ids, and the private hostname list.
Use -AsJsonPath to emit a JSON copy for scripts that run on the jumpbox, where
Terraform is not available.
.EXAMPLE
$lab = .\scripts\Get-LabEnvironment.ps1
$lab.Primary.Account
#>
[CmdletBinding()]
param(
[string]$TerraformDir = (Join-Path $PSScriptRoot '..\terraform'),
[string]$AsJsonPath
)
$ErrorActionPreference = 'Stop'
Push-Location $TerraformDir
try {
$raw = terraform output -json 2>$null
if ($LASTEXITCODE -ne 0 -or -not $raw) {
throw "terraform output failed in '$TerraformDir'. Is the lab deployed?"
}
}
finally {
Pop-Location
}
$o = $raw | ConvertFrom-Json
$accountId = [string]$o.foundry_primary_account_id.value
if ($accountId -notmatch '^/subscriptions/([^/]+)/resourceGroups/') { throw 'Foundry account output does not contain a subscription-bound ARM ID.' }
$subId = $Matches[1]
$selectedSubscription = az account show --query id -o tsv
if ($LASTEXITCODE -ne 0 -or $selectedSubscription -ne $subId) { throw 'Azure CLI subscription must match the Terraform deployment before running lab operations.' }
$rg = $o.resource_groups.value
$p = $o.foundry_primary.value
$s = $o.foundry_secondary.value
$armBase = "/subscriptions/$subId/resourceGroups/$($rg.primary)/providers"
$lab = [pscustomobject]@{
SubscriptionId = $subId
ResourceGroups = [pscustomobject]@{
Network = $rg.network
Primary = $rg.primary
Secondary = $rg.secondary
}
Primary = [pscustomobject]@{
Account = $p.account
Project = $p.project
Search = $p.search
Cosmos = $p.cosmos
KeyVault = $p.key_vault
Storage = $p.storage
ProjectEndpoint = $p.project_endpoint
SearchEndpoint = $p.search_endpoint
AgentToolModel = $p.agent_tool_model
PlannerDeployment = $p.planner_deployment
PlannerModel = $p.planner_model
}
Secondary = [pscustomobject]@{
Account = $s.account
Project = $s.project
StagingStorage = $s.staging_storage
Endpoint = $s.endpoint
}
FoundryId = "$armBase/Microsoft.CognitiveServices/accounts/$($p.account)"
SearchId = "$armBase/Microsoft.Search/searchServices/$($p.search)"
SecondaryFoundryId = "/subscriptions/$subId/resourceGroups/$($rg.secondary)/providers/Microsoft.CognitiveServices/accounts/$($s.account)"
FirewallPrivateIps = $o.firewall_private_ips.value
Jumpbox = $o.jumpbox.value
SharePoint = [pscustomobject]@{
Hostname = $o.sharepoint.value.hostname
SitePath = $o.sharepoint.value.site_path
FilePath = $o.sharepoint.value.file_path
}
Function = [pscustomobject]@{
Name = $o.ingest_function.value.name
Hostname = $o.ingest_function.value.hostname
IdentityClient = $o.ingest_function.value.identity_client
IdentityObject = $o.ingest_function.value.identity_object
ApiClientId = $o.ingest_function.value.api_client_id
ApiScope = $o.ingest_function.value.api_scope
}
NativeIngestion = if ($o.PSObject.Properties['native_ingestion']) { $o.native_ingestion.value } else { $null }
Hosts = [pscustomobject]@{
FoundryServices = "$($p.account).services.ai.azure.com"
FoundryCogSvc = "$($p.account).cognitiveservices.azure.com"
FoundryOpenAI = "$($p.account).openai.azure.com"
Search = "$($p.search).search.windows.net"
Storage = "$($p.storage).blob.core.windows.net"
Cosmos = "$($p.cosmos).documents.azure.com"
KeyVault = "$($p.key_vault).vault.azure.net"
ContentUnderstanding = "$($s.account).cognitiveservices.azure.com"
StagingStorage = "$($s.staging_storage).blob.core.windows.net"
}
}
if ($AsJsonPath) {
$lab | ConvertTo-Json -Depth 10 | Set-Content -Path $AsJsonPath -Encoding UTF8
Write-Verbose "Wrote lab environment to $AsJsonPath"
}
$lab