@@ -34,7 +34,7 @@ import (
34
34
"github.com/azure/azure-dev/cli/azd/pkg/convert"
35
35
"github.com/azure/azure-dev/cli/azd/pkg/environment"
36
36
"github.com/azure/azure-dev/cli/azd/pkg/infra"
37
- . "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
37
+ "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
38
38
"github.com/azure/azure-dev/cli/azd/pkg/input"
39
39
"github.com/azure/azure-dev/cli/azd/pkg/keyvault"
40
40
"github.com/azure/azure-dev/cli/azd/pkg/output"
@@ -64,14 +64,14 @@ type BicepProvider struct {
64
64
env * environment.Environment
65
65
envManager environment.Manager
66
66
projectPath string
67
- options Options
67
+ options provisioning. Options
68
68
console input.Console
69
69
bicepCli * bicep.Cli
70
70
azCli azcli.AzCli
71
71
resourceService * azapi.ResourceService
72
72
deploymentManager * infra.DeploymentManager
73
73
prompters prompt.Prompter
74
- curPrincipal CurrentPrincipalIdProvider
74
+ curPrincipal provisioning. CurrentPrincipalIdProvider
75
75
alphaFeatureManager * alpha.FeatureManager
76
76
ignoreDeploymentState bool
77
77
// compileBicepResult is cached to avoid recompiling the same bicep file multiple times in the same azd run.
@@ -98,7 +98,7 @@ func (p *BicepProvider) RequiredExternalTools() []tools.ExternalTool {
98
98
99
99
// Initialize initializes provider state from the options.
100
100
// It also calls EnsureEnv, which ensures the client-side state is ready for provisioning.
101
- func (p * BicepProvider ) Initialize (ctx context.Context , projectPath string , options Options ) error {
101
+ func (p * BicepProvider ) Initialize (ctx context.Context , projectPath string , options provisioning. Options ) error {
102
102
p .projectPath = projectPath
103
103
p .options = options
104
104
if p .options .Module == "" {
@@ -130,7 +130,7 @@ func (p *BicepProvider) EnsureEnv(ctx context.Context) error {
130
130
// for .bicepparam, we first prompt for environment values before calling compiling bicepparam file
131
131
// which can reference these values
132
132
if isBicepParamFile (modulePath ) {
133
- if err := EnsureSubscriptionAndLocation (ctx , p .envManager , p .env , p .prompters , nil ); err != nil {
133
+ if err := provisioning . EnsureSubscriptionAndLocation (ctx , p .envManager , p .env , p .prompters , nil ); err != nil {
134
134
return err
135
135
}
136
136
}
@@ -154,7 +154,8 @@ func (p *BicepProvider) EnsureEnv(ctx context.Context) error {
154
154
return true
155
155
}
156
156
157
- if err := EnsureSubscriptionAndLocation (ctx , p .envManager , p .env , p .prompters , filterLocation ); err != nil {
157
+ err := provisioning .EnsureSubscriptionAndLocation (ctx , p .envManager , p .env , p .prompters , filterLocation )
158
+ if err != nil {
158
159
return err
159
160
}
160
161
@@ -206,9 +207,9 @@ func (p *BicepProvider) LastDeployment(ctx context.Context) (*azapi.ResourceDepl
206
207
return p .latestDeploymentResult (ctx , scope )
207
208
}
208
209
209
- func (p * BicepProvider ) State (ctx context.Context , options * StateOptions ) (* StateResult , error ) {
210
+ func (p * BicepProvider ) State (ctx context.Context , options * provisioning. StateOptions ) (* provisioning. StateResult , error ) {
210
211
if options == nil {
211
- options = & StateOptions {}
212
+ options = & provisioning. StateOptions {}
212
213
}
213
214
214
215
var err error
@@ -296,11 +297,11 @@ func (p *BicepProvider) State(ctx context.Context, options *StateOptions) (*Stat
296
297
Message : fmt .Sprintf ("Retrieving Azure deployment (%s)" , output .WithHighLightFormat (deployment .Name )),
297
298
})
298
299
299
- state := State {}
300
- state .Resources = make ([]Resource , len (deployment .Resources ))
300
+ state := provisioning. State {}
301
+ state .Resources = make ([]provisioning. Resource , len (deployment .Resources ))
301
302
302
303
for idx , res := range deployment .Resources {
303
- state .Resources [idx ] = Resource {
304
+ state .Resources [idx ] = provisioning. Resource {
304
305
Id : * res .ID ,
305
306
}
306
307
}
@@ -324,7 +325,7 @@ func (p *BicepProvider) State(ctx context.Context, options *StateOptions) (*Stat
324
325
output .WithHyperlink (outputsUrl , deployment .Name ),
325
326
))
326
327
327
- return & StateResult {
328
+ return & provisioning. StateResult {
328
329
State : & state ,
329
330
}, nil
330
331
}
@@ -444,7 +445,7 @@ func (p *BicepProvider) deploymentState(
444
445
return nil , fmt .Errorf ("can't get hash from current template: %w" , err )
445
446
}
446
447
447
- if ! prevDeploymentEqualToCurrent (ctx , prevDeploymentResult , templateHash , currentParamsHash ) {
448
+ if ! prevDeploymentEqualToCurrent (prevDeploymentResult , templateHash , currentParamsHash ) {
448
449
return nil , fmt .Errorf ("deployment state has changed" )
449
450
}
450
451
@@ -498,8 +499,7 @@ func parametersHash(templateParameters azure.ArmTemplateParameterDefinitions, pa
498
499
}
499
500
500
501
// prevDeploymentEqualToCurrent compares the template hash from a previous deployment against a current template.
501
- func prevDeploymentEqualToCurrent (
502
- ctx context.Context , prev * azapi.ResourceDeployment , templateHash , paramsHash string ) bool {
502
+ func prevDeploymentEqualToCurrent (prev * azapi.ResourceDeployment , templateHash , paramsHash string ) bool {
503
503
if prev == nil {
504
504
logDS ("No previous deployment." )
505
505
return false
@@ -536,7 +536,7 @@ func logDS(msg string, v ...any) {
536
536
}
537
537
538
538
// Provisioning the infrastructure within the specified template
539
- func (p * BicepProvider ) Deploy (ctx context.Context ) (* DeployResult , error ) {
539
+ func (p * BicepProvider ) Deploy (ctx context.Context ) (* provisioning. DeployResult , error ) {
540
540
if p .ignoreDeploymentState {
541
541
logDS ("Azure Deployment State is disabled by --no-state arg." )
542
542
}
@@ -568,9 +568,9 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*DeployResult, error) {
568
568
azapi .CreateDeploymentOutput (deploymentState .Outputs ),
569
569
)
570
570
571
- return & DeployResult {
571
+ return & provisioning. DeployResult {
572
572
Deployment : deployment ,
573
- SkippedReason : DeploymentStateSkipped ,
573
+ SkippedReason : provisioning . DeploymentStateSkipped ,
574
574
}, nil
575
575
}
576
576
logDS ("%s" , err .Error ())
@@ -635,13 +635,13 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*DeployResult, error) {
635
635
azapi .CreateDeploymentOutput (deployResult .Outputs ),
636
636
)
637
637
638
- return & DeployResult {
638
+ return & provisioning. DeployResult {
639
639
Deployment : deployment ,
640
640
}, nil
641
641
}
642
642
643
643
// Preview runs deploy using the what-if argument
644
- func (p * BicepProvider ) Preview (ctx context.Context ) (* DeployPreviewResult , error ) {
644
+ func (p * BicepProvider ) Preview (ctx context.Context ) (* provisioning. DeployPreviewResult , error ) {
645
645
bicepDeploymentData , err := p .plan (ctx )
646
646
if err != nil {
647
647
return nil , err
@@ -682,24 +682,24 @@ func (p *BicepProvider) Preview(ctx context.Context) (*DeployPreviewResult, erro
682
682
)
683
683
}
684
684
685
- var changes []* DeploymentPreviewChange
685
+ var changes []* provisioning. DeploymentPreviewChange
686
686
for _ , change := range deployPreviewResult .Properties .Changes {
687
687
resourceAfter := change .After .(map [string ]interface {})
688
688
689
- changes = append (changes , & DeploymentPreviewChange {
690
- ChangeType : ChangeType (* change .ChangeType ),
691
- ResourceId : Resource {
689
+ changes = append (changes , & provisioning. DeploymentPreviewChange {
690
+ ChangeType : provisioning . ChangeType (* change .ChangeType ),
691
+ ResourceId : provisioning. Resource {
692
692
Id : * change .ResourceID ,
693
693
},
694
694
ResourceType : resourceAfter ["type" ].(string ),
695
695
Name : resourceAfter ["name" ].(string ),
696
696
})
697
697
}
698
698
699
- return & DeployPreviewResult {
700
- Preview : & DeploymentPreview {
699
+ return & provisioning. DeployPreviewResult {
700
+ Preview : & provisioning. DeploymentPreview {
701
701
Status : * deployPreviewResult .Status ,
702
- Properties : & DeploymentPreviewProperties {
702
+ Properties : & provisioning. DeploymentPreviewProperties {
703
703
Changes : changes ,
704
704
},
705
705
},
@@ -740,7 +740,10 @@ func (p *BicepProvider) inferScopeFromEnv() (infra.Scope, error) {
740
740
}
741
741
742
742
// Destroys the specified deployment by deleting all azure resources, resource groups & deployments that are referenced.
743
- func (p * BicepProvider ) Destroy (ctx context.Context , options DestroyOptions ) (* DestroyResult , error ) {
743
+ func (p * BicepProvider ) Destroy (
744
+ ctx context.Context ,
745
+ options provisioning.DestroyOptions ,
746
+ ) (* provisioning.DestroyResult , error ) {
744
747
modulePath := p .modulePath ()
745
748
// TODO: Report progress, "Compiling Bicep template"
746
749
compileResult , err := p .compileBicep (ctx , modulePath )
@@ -868,7 +871,7 @@ func (p *BicepProvider) Destroy(ctx context.Context, options DestroyOptions) (*D
868
871
return nil , fmt .Errorf ("purging resources: %w" , err )
869
872
}
870
873
871
- destroyResult := & DestroyResult {
874
+ destroyResult := & provisioning. DestroyResult {
872
875
InvalidatedEnvKeys : slices .Collect (maps .Keys (p .createOutputParameters (
873
876
compileResult .Template .Outputs ,
874
877
azapi .CreateDeploymentOutput (mostRecentDeployment .Outputs ),
@@ -1006,7 +1009,7 @@ func (p *BicepProvider) generateResourcesToDelete(groupedResources map[string][]
1006
1009
// Deletes the azure resources within the deployment
1007
1010
func (p * BicepProvider ) destroyDeploymentWithConfirmation (
1008
1011
ctx context.Context ,
1009
- options DestroyOptions ,
1012
+ options provisioning. DestroyOptions ,
1010
1013
deployment infra.Deployment ,
1011
1014
groupedResources map [string ][]* azapi.Resource ,
1012
1015
resourceCount int ,
@@ -1076,7 +1079,7 @@ func itemsCountAsText(items []itemToPurge) string {
1076
1079
func (p * BicepProvider ) purgeItems (
1077
1080
ctx context.Context ,
1078
1081
items []itemToPurge ,
1079
- options DestroyOptions ,
1082
+ options provisioning. DestroyOptions ,
1080
1083
) error {
1081
1084
if len (items ) == 0 {
1082
1085
// nothing to purge
@@ -1429,18 +1432,18 @@ func (p *BicepProvider) purgeAPIManagement(
1429
1432
return nil
1430
1433
}
1431
1434
1432
- func (p * BicepProvider ) mapBicepTypeToInterfaceType (s string ) ParameterType {
1435
+ func (p * BicepProvider ) mapBicepTypeToInterfaceType (s string ) provisioning. ParameterType {
1433
1436
switch s {
1434
1437
case "String" , "string" , "secureString" , "securestring" :
1435
- return ParameterTypeString
1438
+ return provisioning . ParameterTypeString
1436
1439
case "Bool" , "bool" :
1437
- return ParameterTypeBoolean
1440
+ return provisioning . ParameterTypeBoolean
1438
1441
case "Int" , "int" :
1439
- return ParameterTypeNumber
1442
+ return provisioning . ParameterTypeNumber
1440
1443
case "Object" , "object" , "secureObject" , "secureobject" :
1441
- return ParameterTypeObject
1444
+ return provisioning . ParameterTypeObject
1442
1445
case "Array" , "array" :
1443
- return ParameterTypeArray
1446
+ return provisioning . ParameterTypeArray
1444
1447
default :
1445
1448
panic (fmt .Sprintf ("unexpected bicep type: '%s'" , s ))
1446
1449
}
@@ -1451,14 +1454,14 @@ func (p *BicepProvider) mapBicepTypeToInterfaceType(s string) ParameterType {
1451
1454
func (p * BicepProvider ) createOutputParameters (
1452
1455
templateOutputs azure.ArmTemplateOutputs ,
1453
1456
azureOutputParams map [string ]azapi.AzCliDeploymentOutput ,
1454
- ) map [string ]OutputParameter {
1457
+ ) map [string ]provisioning. OutputParameter {
1455
1458
canonicalOutputCasings := make (map [string ]string , len (templateOutputs ))
1456
1459
1457
1460
for key := range templateOutputs {
1458
1461
canonicalOutputCasings [strings .ToLower (key )] = key
1459
1462
}
1460
1463
1461
- outputParams := make (map [string ]OutputParameter , len (azureOutputParams ))
1464
+ outputParams := make (map [string ]provisioning. OutputParameter , len (azureOutputParams ))
1462
1465
1463
1466
for key , azureParam := range azureOutputParams {
1464
1467
var paramName string
@@ -1472,7 +1475,7 @@ func (p *BicepProvider) createOutputParameters(
1472
1475
paramName = strings .ToUpper (key )
1473
1476
}
1474
1477
1475
- outputParams [paramName ] = OutputParameter {
1478
+ outputParams [paramName ] = provisioning. OutputParameter {
1476
1479
Type : p .mapBicepTypeToInterfaceType (azureParam .Type ),
1477
1480
Value : azureParam .Value ,
1478
1481
}
@@ -1692,20 +1695,20 @@ func definitionName(typeDefinitionRef string) (string, error) {
1692
1695
}
1693
1696
1694
1697
// Converts a Bicep parameters file to a generic provisioning template
1695
- func (p * BicepProvider ) convertToDeployment (bicepTemplate azure.ArmTemplate ) (* Deployment , error ) {
1696
- template := Deployment {}
1697
- parameters := make (map [string ]InputParameter )
1698
- outputs := make (map [string ]OutputParameter )
1698
+ func (p * BicepProvider ) convertToDeployment (bicepTemplate azure.ArmTemplate ) (* provisioning. Deployment , error ) {
1699
+ template := provisioning. Deployment {}
1700
+ parameters := make (map [string ]provisioning. InputParameter )
1701
+ outputs := make (map [string ]provisioning. OutputParameter )
1699
1702
1700
1703
for key , param := range bicepTemplate .Parameters {
1701
- parameters [key ] = InputParameter {
1704
+ parameters [key ] = provisioning. InputParameter {
1702
1705
Type : string (p .mapBicepTypeToInterfaceType (param .Type )),
1703
1706
DefaultValue : param .DefaultValue ,
1704
1707
}
1705
1708
}
1706
1709
1707
1710
for key , param := range bicepTemplate .Outputs {
1708
- outputs [key ] = OutputParameter {
1711
+ outputs [key ] = provisioning. OutputParameter {
1709
1712
Type : p .mapBicepTypeToInterfaceType (param .Type ),
1710
1713
Value : param .Value ,
1711
1714
}
@@ -1866,7 +1869,7 @@ func (p *BicepProvider) ensureParameters(
1866
1869
// If the parameter is tagged with {type: "generate"}, skip prompting.
1867
1870
// We generate it once, then save to config for next attempts.`.
1868
1871
azdMetadata , hasMetadata := param .AzdMetadata ()
1869
- if hasMetadata && parameterType == ParameterTypeString && azdMetadata .Type != nil &&
1872
+ if hasMetadata && parameterType == provisioning . ParameterTypeString && azdMetadata .Type != nil &&
1870
1873
* azdMetadata .Type == azure .AzdMetadataTypeGenerate {
1871
1874
1872
1875
// - generate once
@@ -1973,27 +1976,27 @@ func mustSetParamAsConfig(key string, value any, config config.Config, isSecured
1973
1976
}
1974
1977
1975
1978
// Convert the ARM parameters file value into a value suitable for deployment
1976
- func armParameterFileValue (paramType ParameterType , value any , defaultValue any ) any {
1979
+ func armParameterFileValue (paramType provisioning. ParameterType , value any , defaultValue any ) any {
1977
1980
// Quick return if the value being converted is not a string
1978
1981
if value == nil || reflect .TypeOf (value ).Kind () != reflect .String {
1979
1982
return value
1980
1983
}
1981
1984
1982
1985
// Relax the handling of bool and number types to accept convertible strings
1983
1986
switch paramType {
1984
- case ParameterTypeBoolean :
1987
+ case provisioning . ParameterTypeBoolean :
1985
1988
if val , ok := value .(string ); ok {
1986
1989
if boolVal , err := strconv .ParseBool (val ); err == nil {
1987
1990
return boolVal
1988
1991
}
1989
1992
}
1990
- case ParameterTypeNumber :
1993
+ case provisioning . ParameterTypeNumber :
1991
1994
if val , ok := value .(string ); ok {
1992
1995
if intVal , err := strconv .ParseInt (val , 10 , 64 ); err == nil {
1993
1996
return intVal
1994
1997
}
1995
1998
}
1996
- case ParameterTypeString :
1999
+ case provisioning . ParameterTypeString :
1997
2000
// Use Cases
1998
2001
// 1. Non-empty input value, return input value (no prompt)
1999
2002
// 2. Empty input value and no default - return nil (prompt user)
@@ -2014,15 +2017,15 @@ func armParameterFileValue(paramType ParameterType, value any, defaultValue any)
2014
2017
return nil
2015
2018
}
2016
2019
2017
- func isValueAssignableToParameterType (paramType ParameterType , value any ) bool {
2020
+ func isValueAssignableToParameterType (paramType provisioning. ParameterType , value any ) bool {
2018
2021
switch paramType {
2019
- case ParameterTypeArray :
2022
+ case provisioning . ParameterTypeArray :
2020
2023
_ , ok := value .([]any )
2021
2024
return ok
2022
- case ParameterTypeBoolean :
2025
+ case provisioning . ParameterTypeBoolean :
2023
2026
_ , ok := value .(bool )
2024
2027
return ok
2025
- case ParameterTypeNumber :
2028
+ case provisioning . ParameterTypeNumber :
2026
2029
switch t := value .(type ) {
2027
2030
case int , int8 , int16 , int32 , int64 :
2028
2031
return true
@@ -2038,10 +2041,10 @@ func isValueAssignableToParameterType(paramType ParameterType, value any) bool {
2038
2041
default :
2039
2042
return false
2040
2043
}
2041
- case ParameterTypeObject :
2044
+ case provisioning . ParameterTypeObject :
2042
2045
_ , ok := value .(map [string ]any )
2043
2046
return ok
2044
- case ParameterTypeString :
2047
+ case provisioning . ParameterTypeString :
2045
2048
_ , ok := value .(string )
2046
2049
return ok
2047
2050
default :
@@ -2059,11 +2062,11 @@ func NewBicepProvider(
2059
2062
env * environment.Environment ,
2060
2063
console input.Console ,
2061
2064
prompters prompt.Prompter ,
2062
- curPrincipal CurrentPrincipalIdProvider ,
2065
+ curPrincipal provisioning. CurrentPrincipalIdProvider ,
2063
2066
alphaFeatureManager * alpha.FeatureManager ,
2064
2067
keyvaultService keyvault.KeyVaultService ,
2065
2068
cloud * cloud.Cloud ,
2066
- ) Provider {
2069
+ ) provisioning. Provider {
2067
2070
return & BicepProvider {
2068
2071
envManager : envManager ,
2069
2072
env : env ,
0 commit comments