@@ -19,6 +19,7 @@ import (
1919 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
2020 "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
2121 "github.com/azure/azure-dev/cli/azd/pkg/azdext"
22+ "github.com/drone/envsubst"
2223 "github.com/fatih/color"
2324)
2425
@@ -521,16 +522,29 @@ func (p *AgentServiceTargetProvider) deployHostedAgent(
521522 fmt .Fprintf (os .Stderr , "Using endpoint: %s\n " , azdEnv ["AZURE_AI_PROJECT_ENDPOINT" ])
522523 fmt .Fprintf (os .Stderr , "Agent Name: %s\n " , agentDef .Name )
523524
524- // Step 2: Create agent request with image URL
525- request , err := agent_yaml .CreateAgentAPIRequestFromManifest (* agentManifest , agent_yaml .WithImageURL (fullImageURL ))
525+ // Step 2: Resolve environment variables from YAML using azd environment values
526+ resolvedEnvVars := make (map [string ]string )
527+ hostedDef := agentManifest .Template .(agent_yaml.ContainerAgent )
528+ if hostedDef .EnvironmentVariables != nil {
529+ for _ , envVar := range * hostedDef .EnvironmentVariables {
530+ resolvedEnvVars [envVar .Name ] = p .resolveEnvironmentVariables (envVar .Value , azdEnv )
531+ }
532+ }
533+
534+ // Step 3: Create agent request with image URL and resolved environment variables
535+ request , err := agent_yaml .CreateAgentAPIRequestFromManifest (
536+ * agentManifest ,
537+ agent_yaml .WithImageURL (fullImageURL ),
538+ agent_yaml .WithEnvironmentVariables (resolvedEnvVars ),
539+ )
526540 if err != nil {
527541 return nil , fmt .Errorf ("failed to create agent request: %w" , err )
528542 }
529543
530544 // Display agent information
531545 p .displayAgentInfo (request )
532546
533- // Step 3 : Create agent
547+ // Step 4 : Create agent
534548 progress ("Creating agent" )
535549 agentVersionResponse , err := p .createAgent (ctx , request , azdEnv , cred )
536550 if err != nil {
@@ -544,7 +558,7 @@ func (p *AgentServiceTargetProvider) deployHostedAgent(
544558 return nil , err
545559 }
546560
547- // Step 4 : Start agent container
561+ // Step 5 : Start agent container
548562 progress ("Starting agent container" )
549563 err = p .startAgentContainer (ctx , agentManifest , agentVersionResponse , azdEnv , cred )
550564 if err != nil {
@@ -655,7 +669,7 @@ func (p *AgentServiceTargetProvider) startAgentContainer(
655669 for {
656670 select {
657671 case <- timeout :
658- return fmt .Errorf ("timeout waiting for operation to complete after %v" , maxWaitTime )
672+ return fmt .Errorf ("timeout waiting for operation (id: %s) to complete after %v" , operation . Body . ID , maxWaitTime )
659673 case <- ticker .C :
660674 completedOperation , err := agentClient .GetAgentContainerOperation (
661675 ctx , agentVersionResponse .Name , operation .Body .ID , apiVersion )
@@ -776,3 +790,16 @@ func (p *AgentServiceTargetProvider) registerAgentEnvironmentVariables(
776790
777791 return nil
778792}
793+
794+ // resolveEnvironmentVariables resolves ${ENV_VAR} style references in value using azd environment variables.
795+ // Supports default values (e.g., "${VAR:-default}") and multiple expressions (e.g., "${VAR1}-${VAR2}").
796+ func (p * AgentServiceTargetProvider ) resolveEnvironmentVariables (value string , azdEnv map [string ]string ) string {
797+ resolved , err := envsubst .Eval (value , func (varName string ) string {
798+ return azdEnv [varName ]
799+ })
800+ if err != nil {
801+ // If resolution fails, return original value
802+ return value
803+ }
804+ return resolved
805+ }
0 commit comments