зеркало из https://github.com/Azure/azure-dev.git
provisioning: Don't "import dot" the provisioning package (#4120)
Go has a feature where you can import a package in a way such that you don't have to qualify symbols with the package name, buy using `.` as the import name. We used this in the provisioning sub-packages to import `provisioning` such that it "felt like" it was part of the sub-package. I think this process in practice leads to more confusion instead of less, it becomes less obvious about where things are defined and what is depending on what and how. The Go Wiki also discourages the use of this pattern except in cases in tests where you need it to address a circular dependency issue, which we do not face here. This change removes the use of the pattern across `azd` (we only used it in the provisioning package, and I think this is an artifact of how it evolved when we introduced the terraform provider to be a sibling of the existing bicep provider (which birthed the provisioning interface).
This commit is contained in:
Родитель
72bc4981ad
Коммит
fee5a78bcb
|
@ -34,7 +34,7 @@ import (
|
|||
"github.com/azure/azure-dev/cli/azd/pkg/convert"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/environment"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra"
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/input"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/keyvault"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/output"
|
||||
|
@ -64,14 +64,14 @@ type BicepProvider struct {
|
|||
env *environment.Environment
|
||||
envManager environment.Manager
|
||||
projectPath string
|
||||
options Options
|
||||
options provisioning.Options
|
||||
console input.Console
|
||||
bicepCli *bicep.Cli
|
||||
azCli azcli.AzCli
|
||||
resourceService *azapi.ResourceService
|
||||
deploymentManager *infra.DeploymentManager
|
||||
prompters prompt.Prompter
|
||||
curPrincipal CurrentPrincipalIdProvider
|
||||
curPrincipal provisioning.CurrentPrincipalIdProvider
|
||||
alphaFeatureManager *alpha.FeatureManager
|
||||
ignoreDeploymentState bool
|
||||
// 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 {
|
|||
|
||||
// Initialize initializes provider state from the options.
|
||||
// It also calls EnsureEnv, which ensures the client-side state is ready for provisioning.
|
||||
func (p *BicepProvider) Initialize(ctx context.Context, projectPath string, options Options) error {
|
||||
func (p *BicepProvider) Initialize(ctx context.Context, projectPath string, options provisioning.Options) error {
|
||||
p.projectPath = projectPath
|
||||
p.options = options
|
||||
if p.options.Module == "" {
|
||||
|
@ -130,7 +130,7 @@ func (p *BicepProvider) EnsureEnv(ctx context.Context) error {
|
|||
// for .bicepparam, we first prompt for environment values before calling compiling bicepparam file
|
||||
// which can reference these values
|
||||
if isBicepParamFile(modulePath) {
|
||||
if err := EnsureSubscriptionAndLocation(ctx, p.envManager, p.env, p.prompters, nil); err != nil {
|
||||
if err := provisioning.EnsureSubscriptionAndLocation(ctx, p.envManager, p.env, p.prompters, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,8 @@ func (p *BicepProvider) EnsureEnv(ctx context.Context) error {
|
|||
return true
|
||||
}
|
||||
|
||||
if err := EnsureSubscriptionAndLocation(ctx, p.envManager, p.env, p.prompters, filterLocation); err != nil {
|
||||
err := provisioning.EnsureSubscriptionAndLocation(ctx, p.envManager, p.env, p.prompters, filterLocation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -206,9 +207,9 @@ func (p *BicepProvider) LastDeployment(ctx context.Context) (*azapi.ResourceDepl
|
|||
return p.latestDeploymentResult(ctx, scope)
|
||||
}
|
||||
|
||||
func (p *BicepProvider) State(ctx context.Context, options *StateOptions) (*StateResult, error) {
|
||||
func (p *BicepProvider) State(ctx context.Context, options *provisioning.StateOptions) (*provisioning.StateResult, error) {
|
||||
if options == nil {
|
||||
options = &StateOptions{}
|
||||
options = &provisioning.StateOptions{}
|
||||
}
|
||||
|
||||
var err error
|
||||
|
@ -296,11 +297,11 @@ func (p *BicepProvider) State(ctx context.Context, options *StateOptions) (*Stat
|
|||
Message: fmt.Sprintf("Retrieving Azure deployment (%s)", output.WithHighLightFormat(deployment.Name)),
|
||||
})
|
||||
|
||||
state := State{}
|
||||
state.Resources = make([]Resource, len(deployment.Resources))
|
||||
state := provisioning.State{}
|
||||
state.Resources = make([]provisioning.Resource, len(deployment.Resources))
|
||||
|
||||
for idx, res := range deployment.Resources {
|
||||
state.Resources[idx] = Resource{
|
||||
state.Resources[idx] = provisioning.Resource{
|
||||
Id: *res.ID,
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +325,7 @@ func (p *BicepProvider) State(ctx context.Context, options *StateOptions) (*Stat
|
|||
output.WithHyperlink(outputsUrl, deployment.Name),
|
||||
))
|
||||
|
||||
return &StateResult{
|
||||
return &provisioning.StateResult{
|
||||
State: &state,
|
||||
}, nil
|
||||
}
|
||||
|
@ -444,7 +445,7 @@ func (p *BicepProvider) deploymentState(
|
|||
return nil, fmt.Errorf("can't get hash from current template: %w", err)
|
||||
}
|
||||
|
||||
if !prevDeploymentEqualToCurrent(ctx, prevDeploymentResult, templateHash, currentParamsHash) {
|
||||
if !prevDeploymentEqualToCurrent(prevDeploymentResult, templateHash, currentParamsHash) {
|
||||
return nil, fmt.Errorf("deployment state has changed")
|
||||
}
|
||||
|
||||
|
@ -498,8 +499,7 @@ func parametersHash(templateParameters azure.ArmTemplateParameterDefinitions, pa
|
|||
}
|
||||
|
||||
// prevDeploymentEqualToCurrent compares the template hash from a previous deployment against a current template.
|
||||
func prevDeploymentEqualToCurrent(
|
||||
ctx context.Context, prev *azapi.ResourceDeployment, templateHash, paramsHash string) bool {
|
||||
func prevDeploymentEqualToCurrent(prev *azapi.ResourceDeployment, templateHash, paramsHash string) bool {
|
||||
if prev == nil {
|
||||
logDS("No previous deployment.")
|
||||
return false
|
||||
|
@ -536,7 +536,7 @@ func logDS(msg string, v ...any) {
|
|||
}
|
||||
|
||||
// Provisioning the infrastructure within the specified template
|
||||
func (p *BicepProvider) Deploy(ctx context.Context) (*DeployResult, error) {
|
||||
func (p *BicepProvider) Deploy(ctx context.Context) (*provisioning.DeployResult, error) {
|
||||
if p.ignoreDeploymentState {
|
||||
logDS("Azure Deployment State is disabled by --no-state arg.")
|
||||
}
|
||||
|
@ -568,9 +568,9 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*DeployResult, error) {
|
|||
azapi.CreateDeploymentOutput(deploymentState.Outputs),
|
||||
)
|
||||
|
||||
return &DeployResult{
|
||||
return &provisioning.DeployResult{
|
||||
Deployment: deployment,
|
||||
SkippedReason: DeploymentStateSkipped,
|
||||
SkippedReason: provisioning.DeploymentStateSkipped,
|
||||
}, nil
|
||||
}
|
||||
logDS("%s", err.Error())
|
||||
|
@ -635,13 +635,13 @@ func (p *BicepProvider) Deploy(ctx context.Context) (*DeployResult, error) {
|
|||
azapi.CreateDeploymentOutput(deployResult.Outputs),
|
||||
)
|
||||
|
||||
return &DeployResult{
|
||||
return &provisioning.DeployResult{
|
||||
Deployment: deployment,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Preview runs deploy using the what-if argument
|
||||
func (p *BicepProvider) Preview(ctx context.Context) (*DeployPreviewResult, error) {
|
||||
func (p *BicepProvider) Preview(ctx context.Context) (*provisioning.DeployPreviewResult, error) {
|
||||
bicepDeploymentData, err := p.plan(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -682,13 +682,13 @@ func (p *BicepProvider) Preview(ctx context.Context) (*DeployPreviewResult, erro
|
|||
)
|
||||
}
|
||||
|
||||
var changes []*DeploymentPreviewChange
|
||||
var changes []*provisioning.DeploymentPreviewChange
|
||||
for _, change := range deployPreviewResult.Properties.Changes {
|
||||
resourceAfter := change.After.(map[string]interface{})
|
||||
|
||||
changes = append(changes, &DeploymentPreviewChange{
|
||||
ChangeType: ChangeType(*change.ChangeType),
|
||||
ResourceId: Resource{
|
||||
changes = append(changes, &provisioning.DeploymentPreviewChange{
|
||||
ChangeType: provisioning.ChangeType(*change.ChangeType),
|
||||
ResourceId: provisioning.Resource{
|
||||
Id: *change.ResourceID,
|
||||
},
|
||||
ResourceType: resourceAfter["type"].(string),
|
||||
|
@ -696,10 +696,10 @@ func (p *BicepProvider) Preview(ctx context.Context) (*DeployPreviewResult, erro
|
|||
})
|
||||
}
|
||||
|
||||
return &DeployPreviewResult{
|
||||
Preview: &DeploymentPreview{
|
||||
return &provisioning.DeployPreviewResult{
|
||||
Preview: &provisioning.DeploymentPreview{
|
||||
Status: *deployPreviewResult.Status,
|
||||
Properties: &DeploymentPreviewProperties{
|
||||
Properties: &provisioning.DeploymentPreviewProperties{
|
||||
Changes: changes,
|
||||
},
|
||||
},
|
||||
|
@ -740,7 +740,10 @@ func (p *BicepProvider) inferScopeFromEnv() (infra.Scope, error) {
|
|||
}
|
||||
|
||||
// Destroys the specified deployment by deleting all azure resources, resource groups & deployments that are referenced.
|
||||
func (p *BicepProvider) Destroy(ctx context.Context, options DestroyOptions) (*DestroyResult, error) {
|
||||
func (p *BicepProvider) Destroy(
|
||||
ctx context.Context,
|
||||
options provisioning.DestroyOptions,
|
||||
) (*provisioning.DestroyResult, error) {
|
||||
modulePath := p.modulePath()
|
||||
// TODO: Report progress, "Compiling Bicep template"
|
||||
compileResult, err := p.compileBicep(ctx, modulePath)
|
||||
|
@ -868,7 +871,7 @@ func (p *BicepProvider) Destroy(ctx context.Context, options DestroyOptions) (*D
|
|||
return nil, fmt.Errorf("purging resources: %w", err)
|
||||
}
|
||||
|
||||
destroyResult := &DestroyResult{
|
||||
destroyResult := &provisioning.DestroyResult{
|
||||
InvalidatedEnvKeys: slices.Collect(maps.Keys(p.createOutputParameters(
|
||||
compileResult.Template.Outputs,
|
||||
azapi.CreateDeploymentOutput(mostRecentDeployment.Outputs),
|
||||
|
@ -1006,7 +1009,7 @@ func (p *BicepProvider) generateResourcesToDelete(groupedResources map[string][]
|
|||
// Deletes the azure resources within the deployment
|
||||
func (p *BicepProvider) destroyDeploymentWithConfirmation(
|
||||
ctx context.Context,
|
||||
options DestroyOptions,
|
||||
options provisioning.DestroyOptions,
|
||||
deployment infra.Deployment,
|
||||
groupedResources map[string][]*azapi.Resource,
|
||||
resourceCount int,
|
||||
|
@ -1076,7 +1079,7 @@ func itemsCountAsText(items []itemToPurge) string {
|
|||
func (p *BicepProvider) purgeItems(
|
||||
ctx context.Context,
|
||||
items []itemToPurge,
|
||||
options DestroyOptions,
|
||||
options provisioning.DestroyOptions,
|
||||
) error {
|
||||
if len(items) == 0 {
|
||||
// nothing to purge
|
||||
|
@ -1429,18 +1432,18 @@ func (p *BicepProvider) purgeAPIManagement(
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *BicepProvider) mapBicepTypeToInterfaceType(s string) ParameterType {
|
||||
func (p *BicepProvider) mapBicepTypeToInterfaceType(s string) provisioning.ParameterType {
|
||||
switch s {
|
||||
case "String", "string", "secureString", "securestring":
|
||||
return ParameterTypeString
|
||||
return provisioning.ParameterTypeString
|
||||
case "Bool", "bool":
|
||||
return ParameterTypeBoolean
|
||||
return provisioning.ParameterTypeBoolean
|
||||
case "Int", "int":
|
||||
return ParameterTypeNumber
|
||||
return provisioning.ParameterTypeNumber
|
||||
case "Object", "object", "secureObject", "secureobject":
|
||||
return ParameterTypeObject
|
||||
return provisioning.ParameterTypeObject
|
||||
case "Array", "array":
|
||||
return ParameterTypeArray
|
||||
return provisioning.ParameterTypeArray
|
||||
default:
|
||||
panic(fmt.Sprintf("unexpected bicep type: '%s'", s))
|
||||
}
|
||||
|
@ -1451,14 +1454,14 @@ func (p *BicepProvider) mapBicepTypeToInterfaceType(s string) ParameterType {
|
|||
func (p *BicepProvider) createOutputParameters(
|
||||
templateOutputs azure.ArmTemplateOutputs,
|
||||
azureOutputParams map[string]azapi.AzCliDeploymentOutput,
|
||||
) map[string]OutputParameter {
|
||||
) map[string]provisioning.OutputParameter {
|
||||
canonicalOutputCasings := make(map[string]string, len(templateOutputs))
|
||||
|
||||
for key := range templateOutputs {
|
||||
canonicalOutputCasings[strings.ToLower(key)] = key
|
||||
}
|
||||
|
||||
outputParams := make(map[string]OutputParameter, len(azureOutputParams))
|
||||
outputParams := make(map[string]provisioning.OutputParameter, len(azureOutputParams))
|
||||
|
||||
for key, azureParam := range azureOutputParams {
|
||||
var paramName string
|
||||
|
@ -1472,7 +1475,7 @@ func (p *BicepProvider) createOutputParameters(
|
|||
paramName = strings.ToUpper(key)
|
||||
}
|
||||
|
||||
outputParams[paramName] = OutputParameter{
|
||||
outputParams[paramName] = provisioning.OutputParameter{
|
||||
Type: p.mapBicepTypeToInterfaceType(azureParam.Type),
|
||||
Value: azureParam.Value,
|
||||
}
|
||||
|
@ -1692,20 +1695,20 @@ func definitionName(typeDefinitionRef string) (string, error) {
|
|||
}
|
||||
|
||||
// Converts a Bicep parameters file to a generic provisioning template
|
||||
func (p *BicepProvider) convertToDeployment(bicepTemplate azure.ArmTemplate) (*Deployment, error) {
|
||||
template := Deployment{}
|
||||
parameters := make(map[string]InputParameter)
|
||||
outputs := make(map[string]OutputParameter)
|
||||
func (p *BicepProvider) convertToDeployment(bicepTemplate azure.ArmTemplate) (*provisioning.Deployment, error) {
|
||||
template := provisioning.Deployment{}
|
||||
parameters := make(map[string]provisioning.InputParameter)
|
||||
outputs := make(map[string]provisioning.OutputParameter)
|
||||
|
||||
for key, param := range bicepTemplate.Parameters {
|
||||
parameters[key] = InputParameter{
|
||||
parameters[key] = provisioning.InputParameter{
|
||||
Type: string(p.mapBicepTypeToInterfaceType(param.Type)),
|
||||
DefaultValue: param.DefaultValue,
|
||||
}
|
||||
}
|
||||
|
||||
for key, param := range bicepTemplate.Outputs {
|
||||
outputs[key] = OutputParameter{
|
||||
outputs[key] = provisioning.OutputParameter{
|
||||
Type: p.mapBicepTypeToInterfaceType(param.Type),
|
||||
Value: param.Value,
|
||||
}
|
||||
|
@ -1866,7 +1869,7 @@ func (p *BicepProvider) ensureParameters(
|
|||
// If the parameter is tagged with {type: "generate"}, skip prompting.
|
||||
// We generate it once, then save to config for next attempts.`.
|
||||
azdMetadata, hasMetadata := param.AzdMetadata()
|
||||
if hasMetadata && parameterType == ParameterTypeString && azdMetadata.Type != nil &&
|
||||
if hasMetadata && parameterType == provisioning.ParameterTypeString && azdMetadata.Type != nil &&
|
||||
*azdMetadata.Type == azure.AzdMetadataTypeGenerate {
|
||||
|
||||
// - generate once
|
||||
|
@ -1973,7 +1976,7 @@ func mustSetParamAsConfig(key string, value any, config config.Config, isSecured
|
|||
}
|
||||
|
||||
// Convert the ARM parameters file value into a value suitable for deployment
|
||||
func armParameterFileValue(paramType ParameterType, value any, defaultValue any) any {
|
||||
func armParameterFileValue(paramType provisioning.ParameterType, value any, defaultValue any) any {
|
||||
// Quick return if the value being converted is not a string
|
||||
if value == nil || reflect.TypeOf(value).Kind() != reflect.String {
|
||||
return value
|
||||
|
@ -1981,19 +1984,19 @@ func armParameterFileValue(paramType ParameterType, value any, defaultValue any)
|
|||
|
||||
// Relax the handling of bool and number types to accept convertible strings
|
||||
switch paramType {
|
||||
case ParameterTypeBoolean:
|
||||
case provisioning.ParameterTypeBoolean:
|
||||
if val, ok := value.(string); ok {
|
||||
if boolVal, err := strconv.ParseBool(val); err == nil {
|
||||
return boolVal
|
||||
}
|
||||
}
|
||||
case ParameterTypeNumber:
|
||||
case provisioning.ParameterTypeNumber:
|
||||
if val, ok := value.(string); ok {
|
||||
if intVal, err := strconv.ParseInt(val, 10, 64); err == nil {
|
||||
return intVal
|
||||
}
|
||||
}
|
||||
case ParameterTypeString:
|
||||
case provisioning.ParameterTypeString:
|
||||
// Use Cases
|
||||
// 1. Non-empty input value, return input value (no prompt)
|
||||
// 2. Empty input value and no default - return nil (prompt user)
|
||||
|
@ -2014,15 +2017,15 @@ func armParameterFileValue(paramType ParameterType, value any, defaultValue any)
|
|||
return nil
|
||||
}
|
||||
|
||||
func isValueAssignableToParameterType(paramType ParameterType, value any) bool {
|
||||
func isValueAssignableToParameterType(paramType provisioning.ParameterType, value any) bool {
|
||||
switch paramType {
|
||||
case ParameterTypeArray:
|
||||
case provisioning.ParameterTypeArray:
|
||||
_, ok := value.([]any)
|
||||
return ok
|
||||
case ParameterTypeBoolean:
|
||||
case provisioning.ParameterTypeBoolean:
|
||||
_, ok := value.(bool)
|
||||
return ok
|
||||
case ParameterTypeNumber:
|
||||
case provisioning.ParameterTypeNumber:
|
||||
switch t := value.(type) {
|
||||
case int, int8, int16, int32, int64:
|
||||
return true
|
||||
|
@ -2038,10 +2041,10 @@ func isValueAssignableToParameterType(paramType ParameterType, value any) bool {
|
|||
default:
|
||||
return false
|
||||
}
|
||||
case ParameterTypeObject:
|
||||
case provisioning.ParameterTypeObject:
|
||||
_, ok := value.(map[string]any)
|
||||
return ok
|
||||
case ParameterTypeString:
|
||||
case provisioning.ParameterTypeString:
|
||||
_, ok := value.(string)
|
||||
return ok
|
||||
default:
|
||||
|
@ -2059,11 +2062,11 @@ func NewBicepProvider(
|
|||
env *environment.Environment,
|
||||
console input.Console,
|
||||
prompters prompt.Prompter,
|
||||
curPrincipal CurrentPrincipalIdProvider,
|
||||
curPrincipal provisioning.CurrentPrincipalIdProvider,
|
||||
alphaFeatureManager *alpha.FeatureManager,
|
||||
keyvaultService keyvault.KeyVaultService,
|
||||
cloud *cloud.Cloud,
|
||||
) Provider {
|
||||
) provisioning.Provider {
|
||||
return &BicepProvider{
|
||||
envManager: envManager,
|
||||
env: env,
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
"github.com/azure/azure-dev/cli/azd/pkg/environment"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/exec"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra"
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/input"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/keyvault"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/prompt"
|
||||
|
@ -148,7 +148,7 @@ func TestBicepDestroy(t *testing.T) {
|
|||
|
||||
infraProvider := createBicepProvider(t, mockContext)
|
||||
|
||||
destroyOptions := NewDestroyOptions(false, false)
|
||||
destroyOptions := provisioning.NewDestroyOptions(false, false)
|
||||
destroyResult, err := infraProvider.Destroy(*mockContext.Context, destroyOptions)
|
||||
|
||||
require.Nil(t, err)
|
||||
|
@ -167,7 +167,7 @@ func TestBicepDestroy(t *testing.T) {
|
|||
|
||||
infraProvider := createBicepProvider(t, mockContext)
|
||||
|
||||
destroyOptions := NewDestroyOptions(true, true)
|
||||
destroyOptions := provisioning.NewDestroyOptions(true, true)
|
||||
destroyResult, err := infraProvider.Destroy(*mockContext.Context, destroyOptions)
|
||||
|
||||
require.Nil(t, err)
|
||||
|
@ -303,12 +303,12 @@ func TestPlanForResourceGroup(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsValueAssignableToParameterType(t *testing.T) {
|
||||
cases := map[ParameterType]any{
|
||||
ParameterTypeNumber: 1,
|
||||
ParameterTypeBoolean: true,
|
||||
ParameterTypeString: "hello",
|
||||
ParameterTypeArray: []any{},
|
||||
ParameterTypeObject: map[string]any{},
|
||||
cases := map[provisioning.ParameterType]any{
|
||||
provisioning.ParameterTypeNumber: 1,
|
||||
provisioning.ParameterTypeBoolean: true,
|
||||
provisioning.ParameterTypeString: "hello",
|
||||
provisioning.ParameterTypeArray: []any{},
|
||||
provisioning.ParameterTypeObject: map[string]any{},
|
||||
}
|
||||
|
||||
for k := range cases {
|
||||
|
@ -323,15 +323,15 @@ func TestIsValueAssignableToParameterType(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.True(t, isValueAssignableToParameterType(ParameterTypeNumber, 1.0))
|
||||
assert.True(t, isValueAssignableToParameterType(ParameterTypeNumber, json.Number("1")))
|
||||
assert.False(t, isValueAssignableToParameterType(ParameterTypeNumber, 1.5))
|
||||
assert.False(t, isValueAssignableToParameterType(ParameterTypeNumber, json.Number("1.5")))
|
||||
assert.True(t, isValueAssignableToParameterType(provisioning.ParameterTypeNumber, 1.0))
|
||||
assert.True(t, isValueAssignableToParameterType(provisioning.ParameterTypeNumber, json.Number("1")))
|
||||
assert.False(t, isValueAssignableToParameterType(provisioning.ParameterTypeNumber, 1.5))
|
||||
assert.False(t, isValueAssignableToParameterType(provisioning.ParameterTypeNumber, json.Number("1.5")))
|
||||
}
|
||||
|
||||
func createBicepProvider(t *testing.T, mockContext *mocks.MockContext) *BicepProvider {
|
||||
projectDir := "../../../../test/functional/testdata/samples/webapp"
|
||||
options := Options{
|
||||
options := provisioning.Options{
|
||||
Path: "infra",
|
||||
Module: "main",
|
||||
}
|
||||
|
@ -1075,71 +1075,71 @@ func TestUserDefinedTypes(t *testing.T) {
|
|||
|
||||
func Test_armParameterFileValue(t *testing.T) {
|
||||
t.Run("NilValue", func(t *testing.T) {
|
||||
actual := armParameterFileValue(ParameterTypeString, nil, nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeString, nil, nil)
|
||||
require.Nil(t, actual)
|
||||
})
|
||||
|
||||
t.Run("StringWithValue", func(t *testing.T) {
|
||||
expected := "value"
|
||||
actual := armParameterFileValue(ParameterTypeString, expected, nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeString, expected, nil)
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("EmptyString", func(t *testing.T) {
|
||||
input := ""
|
||||
actual := armParameterFileValue(ParameterTypeString, input, nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeString, input, nil)
|
||||
require.Nil(t, actual)
|
||||
})
|
||||
|
||||
t.Run("EmptyStringWithNonEmptyDefault", func(t *testing.T) {
|
||||
expected := ""
|
||||
actual := armParameterFileValue(ParameterTypeString, expected, "not-empty")
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeString, expected, "not-empty")
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("EmptyStringWithEmptyDefault", func(t *testing.T) {
|
||||
input := ""
|
||||
actual := armParameterFileValue(ParameterTypeString, input, "")
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeString, input, "")
|
||||
require.Nil(t, actual)
|
||||
})
|
||||
|
||||
t.Run("ValidBool", func(t *testing.T) {
|
||||
expected := true
|
||||
actual := armParameterFileValue(ParameterTypeBoolean, expected, nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeBoolean, expected, nil)
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("ActualBool", func(t *testing.T) {
|
||||
expected := true
|
||||
actual := armParameterFileValue(ParameterTypeBoolean, "true", nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeBoolean, "true", nil)
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("InvalidBool", func(t *testing.T) {
|
||||
actual := armParameterFileValue(ParameterTypeBoolean, "NotABool", nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeBoolean, "NotABool", nil)
|
||||
require.Nil(t, actual)
|
||||
})
|
||||
|
||||
t.Run("ValidInt", func(t *testing.T) {
|
||||
var expected int64 = 42
|
||||
actual := armParameterFileValue(ParameterTypeNumber, "42", nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeNumber, "42", nil)
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("ActualInt", func(t *testing.T) {
|
||||
var expected int64 = 42
|
||||
actual := armParameterFileValue(ParameterTypeNumber, expected, nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeNumber, expected, nil)
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
|
||||
t.Run("InvalidInt", func(t *testing.T) {
|
||||
actual := armParameterFileValue(ParameterTypeNumber, "NotAnInt", nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeNumber, "NotAnInt", nil)
|
||||
require.Nil(t, actual)
|
||||
})
|
||||
|
||||
t.Run("Array", func(t *testing.T) {
|
||||
expected := []string{"a", "b", "c"}
|
||||
actual := armParameterFileValue(ParameterTypeArray, expected, nil)
|
||||
actual := armParameterFileValue(provisioning.ParameterTypeArray, expected, nil)
|
||||
require.Equal(t, expected, actual)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/azure/azure-dev/cli/azd/pkg/output"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/password"
|
||||
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
)
|
||||
|
||||
// promptDialogItemForParameter builds the input.PromptDialogItem for the given required parameter.
|
||||
|
@ -34,7 +34,7 @@ func (p *BicepProvider) promptDialogItemForParameter(
|
|||
dialogItem.Description = to.Ptr(help)
|
||||
}
|
||||
|
||||
if paramType == ParameterTypeBoolean {
|
||||
if paramType == provisioning.ParameterTypeBoolean {
|
||||
dialogItem.Kind = "select"
|
||||
dialogItem.Choices = []input.PromptDialogChoice{{Value: "true"}, {Value: "false"}}
|
||||
} else if param.AllowedValues != nil {
|
||||
|
@ -89,7 +89,10 @@ func (p *BicepProvider) promptForParameter(
|
|||
|
||||
var value any
|
||||
|
||||
if paramType == ParameterTypeString && azdMetadata.Type != nil && *azdMetadata.Type == azure.AzdMetadataTypeLocation {
|
||||
if paramType == provisioning.ParameterTypeString &&
|
||||
azdMetadata.Type != nil &&
|
||||
*azdMetadata.Type == azure.AzdMetadataTypeLocation {
|
||||
|
||||
location, err := p.prompters.PromptLocation(ctx, p.env.GetSubscriptionId(), msg, func(loc account.Location) bool {
|
||||
if param.AllowedValues == nil {
|
||||
return true
|
||||
|
@ -105,7 +108,7 @@ func (p *BicepProvider) promptForParameter(
|
|||
return nil, err
|
||||
}
|
||||
value = location
|
||||
} else if paramType == ParameterTypeString &&
|
||||
} else if paramType == provisioning.ParameterTypeString &&
|
||||
azdMetadata.Type != nil &&
|
||||
*azdMetadata.Type == azure.AzdMetadataTypeGenerateOrManual {
|
||||
|
||||
|
@ -161,7 +164,7 @@ func (p *BicepProvider) promptForParameter(
|
|||
value = (*param.AllowedValues)[choice]
|
||||
} else {
|
||||
switch paramType {
|
||||
case ParameterTypeBoolean:
|
||||
case provisioning.ParameterTypeBoolean:
|
||||
options := []string{"False", "True"}
|
||||
choice, err := p.console.Select(ctx, input.ConsoleOptions{
|
||||
Message: msg,
|
||||
|
@ -172,7 +175,7 @@ func (p *BicepProvider) promptForParameter(
|
|||
return nil, err
|
||||
}
|
||||
value = (options[choice] == "True")
|
||||
case ParameterTypeNumber:
|
||||
case provisioning.ParameterTypeNumber:
|
||||
userValue, err := promptWithValidation(ctx, p.console, input.ConsoleOptions{
|
||||
Message: msg,
|
||||
Help: help,
|
||||
|
@ -181,7 +184,7 @@ func (p *BicepProvider) promptForParameter(
|
|||
return nil, err
|
||||
}
|
||||
value = userValue
|
||||
case ParameterTypeString:
|
||||
case provisioning.ParameterTypeString:
|
||||
userValue, err := promptWithValidation(ctx, p.console, input.ConsoleOptions{
|
||||
Message: msg,
|
||||
Help: help,
|
||||
|
@ -191,7 +194,7 @@ func (p *BicepProvider) promptForParameter(
|
|||
return nil, err
|
||||
}
|
||||
value = userValue
|
||||
case ParameterTypeArray:
|
||||
case provisioning.ParameterTypeArray:
|
||||
userValue, err := promptWithValidation(ctx, p.console, input.ConsoleOptions{
|
||||
Message: msg,
|
||||
Help: help,
|
||||
|
@ -200,7 +203,7 @@ func (p *BicepProvider) promptForParameter(
|
|||
return nil, err
|
||||
}
|
||||
value = userValue
|
||||
case ParameterTypeObject:
|
||||
case provisioning.ParameterTypeObject:
|
||||
userValue, err := promptWithValidation(ctx, p.console, input.ConsoleOptions{
|
||||
Message: msg,
|
||||
Help: help,
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
"github.com/azure/azure-dev/cli/azd/pkg/cloud"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/environment"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning/test"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/input"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/prompt"
|
||||
|
@ -47,7 +46,7 @@ func TestProvisionInitializesEnvironment(t *testing.T) {
|
|||
registerContainerDependencies(mockContext, env)
|
||||
|
||||
envManager := &mockenv.MockEnvManager{}
|
||||
mgr := NewManager(
|
||||
mgr := provisioning.NewManager(
|
||||
mockContext.Container,
|
||||
defaultProvider,
|
||||
envManager,
|
||||
|
@ -57,7 +56,7 @@ func TestProvisionInitializesEnvironment(t *testing.T) {
|
|||
nil,
|
||||
cloud.AzurePublic(),
|
||||
)
|
||||
err := mgr.Initialize(*mockContext.Context, "", Options{Provider: "test"})
|
||||
err := mgr.Initialize(*mockContext.Context, "", provisioning.Options{Provider: "test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, "00000000-0000-0000-0000-000000000000", env.GetSubscriptionId())
|
||||
|
@ -74,7 +73,7 @@ func TestManagerPreview(t *testing.T) {
|
|||
registerContainerDependencies(mockContext, env)
|
||||
|
||||
envManager := &mockenv.MockEnvManager{}
|
||||
mgr := NewManager(
|
||||
mgr := provisioning.NewManager(
|
||||
mockContext.Container,
|
||||
defaultProvider,
|
||||
envManager,
|
||||
|
@ -84,7 +83,7 @@ func TestManagerPreview(t *testing.T) {
|
|||
nil,
|
||||
cloud.AzurePublic(),
|
||||
)
|
||||
err := mgr.Initialize(*mockContext.Context, "", Options{Provider: "test"})
|
||||
err := mgr.Initialize(*mockContext.Context, "", provisioning.Options{Provider: "test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
deploymentPlan, err := mgr.Preview(*mockContext.Context)
|
||||
|
@ -103,7 +102,7 @@ func TestManagerGetState(t *testing.T) {
|
|||
registerContainerDependencies(mockContext, env)
|
||||
|
||||
envManager := &mockenv.MockEnvManager{}
|
||||
mgr := NewManager(
|
||||
mgr := provisioning.NewManager(
|
||||
mockContext.Container,
|
||||
defaultProvider,
|
||||
envManager,
|
||||
|
@ -113,7 +112,7 @@ func TestManagerGetState(t *testing.T) {
|
|||
nil,
|
||||
cloud.AzurePublic(),
|
||||
)
|
||||
err := mgr.Initialize(*mockContext.Context, "", Options{Provider: "test"})
|
||||
err := mgr.Initialize(*mockContext.Context, "", provisioning.Options{Provider: "test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
getResult, err := mgr.State(*mockContext.Context, nil)
|
||||
|
@ -132,7 +131,7 @@ func TestManagerDeploy(t *testing.T) {
|
|||
registerContainerDependencies(mockContext, env)
|
||||
|
||||
envManager := &mockenv.MockEnvManager{}
|
||||
mgr := NewManager(
|
||||
mgr := provisioning.NewManager(
|
||||
mockContext.Container,
|
||||
defaultProvider,
|
||||
envManager,
|
||||
|
@ -142,7 +141,7 @@ func TestManagerDeploy(t *testing.T) {
|
|||
nil,
|
||||
cloud.AzurePublic(),
|
||||
)
|
||||
err := mgr.Initialize(*mockContext.Context, "", Options{Provider: "test"})
|
||||
err := mgr.Initialize(*mockContext.Context, "", provisioning.Options{Provider: "test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
deployResult, err := mgr.Deploy(*mockContext.Context)
|
||||
|
@ -167,7 +166,7 @@ func TestManagerDestroyWithPositiveConfirmation(t *testing.T) {
|
|||
envManager := &mockenv.MockEnvManager{}
|
||||
envManager.On("Save", *mockContext.Context, env).Return(nil)
|
||||
|
||||
mgr := NewManager(
|
||||
mgr := provisioning.NewManager(
|
||||
mockContext.Container,
|
||||
defaultProvider,
|
||||
envManager,
|
||||
|
@ -177,10 +176,10 @@ func TestManagerDestroyWithPositiveConfirmation(t *testing.T) {
|
|||
nil,
|
||||
cloud.AzurePublic(),
|
||||
)
|
||||
err := mgr.Initialize(*mockContext.Context, "", Options{Provider: "test"})
|
||||
err := mgr.Initialize(*mockContext.Context, "", provisioning.Options{Provider: "test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
destroyOptions := NewDestroyOptions(false, false)
|
||||
destroyOptions := provisioning.NewDestroyOptions(false, false)
|
||||
destroyResult, err := mgr.Destroy(*mockContext.Context, destroyOptions)
|
||||
|
||||
require.NotNil(t, destroyResult)
|
||||
|
@ -203,7 +202,7 @@ func TestManagerDestroyWithNegativeConfirmation(t *testing.T) {
|
|||
registerContainerDependencies(mockContext, env)
|
||||
|
||||
envManager := &mockenv.MockEnvManager{}
|
||||
mgr := NewManager(
|
||||
mgr := provisioning.NewManager(
|
||||
mockContext.Container,
|
||||
defaultProvider,
|
||||
envManager,
|
||||
|
@ -213,10 +212,10 @@ func TestManagerDestroyWithNegativeConfirmation(t *testing.T) {
|
|||
nil,
|
||||
cloud.AzurePublic(),
|
||||
)
|
||||
err := mgr.Initialize(*mockContext.Context, "", Options{Provider: "test"})
|
||||
err := mgr.Initialize(*mockContext.Context, "", provisioning.Options{Provider: "test"})
|
||||
require.NoError(t, err)
|
||||
|
||||
destroyOptions := NewDestroyOptions(false, false)
|
||||
destroyOptions := provisioning.NewDestroyOptions(false, false)
|
||||
destroyResult, err := mgr.Destroy(*mockContext.Context, destroyOptions)
|
||||
|
||||
require.Nil(t, destroyResult)
|
||||
|
@ -276,6 +275,6 @@ func registerContainerDependencies(mockContext *mocks.MockContext, env *environm
|
|||
})
|
||||
}
|
||||
|
||||
func defaultProvider() (ProviderKind, error) {
|
||||
return Bicep, nil
|
||||
func defaultProvider() (provisioning.ProviderKind, error) {
|
||||
return provisioning.Bicep, nil
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
"github.com/azure/azure-dev/cli/azd/internal"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/environment"
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/input"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/osutil"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/prompt"
|
||||
|
@ -35,9 +35,9 @@ type TerraformProvider struct {
|
|||
prompters prompt.Prompter
|
||||
console input.Console
|
||||
cli *terraform.Cli
|
||||
curPrincipal CurrentPrincipalIdProvider
|
||||
curPrincipal provisioning.CurrentPrincipalIdProvider
|
||||
projectPath string
|
||||
options Options
|
||||
options provisioning.Options
|
||||
}
|
||||
|
||||
type terraformDeploymentDetails struct {
|
||||
|
@ -61,9 +61,9 @@ func NewTerraformProvider(
|
|||
envManager environment.Manager,
|
||||
env *environment.Environment,
|
||||
console input.Console,
|
||||
curPrincipal CurrentPrincipalIdProvider,
|
||||
curPrincipal provisioning.CurrentPrincipalIdProvider,
|
||||
prompters prompt.Prompter,
|
||||
) Provider {
|
||||
) provisioning.Provider {
|
||||
provider := &TerraformProvider{
|
||||
envManager: envManager,
|
||||
env: env,
|
||||
|
@ -76,7 +76,7 @@ func NewTerraformProvider(
|
|||
return provider
|
||||
}
|
||||
|
||||
func (t *TerraformProvider) Initialize(ctx context.Context, projectPath string, options Options) error {
|
||||
func (t *TerraformProvider) Initialize(ctx context.Context, projectPath string, options provisioning.Options) error {
|
||||
t.projectPath = projectPath
|
||||
t.options = options
|
||||
if t.options.Module == "" {
|
||||
|
@ -122,7 +122,7 @@ func (t *TerraformProvider) Initialize(ctx context.Context, projectPath string,
|
|||
// An environment is considered to be in a provision-ready state if it contains both an AZURE_SUBSCRIPTION_ID and
|
||||
// AZURE_LOCATION value.
|
||||
func (t *TerraformProvider) EnsureEnv(ctx context.Context) error {
|
||||
return EnsureSubscriptionAndLocation(
|
||||
return provisioning.EnsureSubscriptionAndLocation(
|
||||
ctx,
|
||||
t.envManager,
|
||||
t.env,
|
||||
|
@ -132,7 +132,7 @@ func (t *TerraformProvider) EnsureEnv(ctx context.Context) error {
|
|||
}
|
||||
|
||||
// Previews the infrastructure through terraform plan
|
||||
func (t *TerraformProvider) plan(ctx context.Context) (*Deployment, *terraformDeploymentDetails, error) {
|
||||
func (t *TerraformProvider) plan(ctx context.Context) (*provisioning.Deployment, *terraformDeploymentDetails, error) {
|
||||
isRemoteBackendConfig, err := t.isRemoteBackendConfig()
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("reading backend config: %w", err)
|
||||
|
@ -179,7 +179,7 @@ func (t *TerraformProvider) plan(ctx context.Context) (*Deployment, *terraformDe
|
|||
}
|
||||
|
||||
// Deploy the infrastructure within the specified template through terraform apply
|
||||
func (t *TerraformProvider) Deploy(ctx context.Context) (*DeployResult, error) {
|
||||
func (t *TerraformProvider) Deploy(ctx context.Context) (*provisioning.DeployResult, error) {
|
||||
t.console.Message(ctx, "Locating plan file...")
|
||||
|
||||
modulePath := t.modulePath()
|
||||
|
@ -210,12 +210,12 @@ func (t *TerraformProvider) Deploy(ctx context.Context) (*DeployResult, error) {
|
|||
}
|
||||
|
||||
deployment.Outputs = outputs
|
||||
return &DeployResult{
|
||||
return &provisioning.DeployResult{
|
||||
Deployment: deployment,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *TerraformProvider) Preview(ctx context.Context) (*DeployPreviewResult, error) {
|
||||
func (t *TerraformProvider) Preview(ctx context.Context) (*provisioning.DeployPreviewResult, error) {
|
||||
// terraform uses plan() to display the what-if output
|
||||
// no changes are added to the properties
|
||||
_, _, err := t.plan(ctx)
|
||||
|
@ -223,16 +223,19 @@ func (t *TerraformProvider) Preview(ctx context.Context) (*DeployPreviewResult,
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return &DeployPreviewResult{
|
||||
Preview: &DeploymentPreview{
|
||||
return &provisioning.DeployPreviewResult{
|
||||
Preview: &provisioning.DeploymentPreview{
|
||||
Status: "done",
|
||||
Properties: &DeploymentPreviewProperties{},
|
||||
Properties: &provisioning.DeploymentPreviewProperties{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Destroys the specified deployment through terraform destroy
|
||||
func (t *TerraformProvider) Destroy(ctx context.Context, options DestroyOptions) (*DestroyResult, error) {
|
||||
func (t *TerraformProvider) Destroy(
|
||||
ctx context.Context,
|
||||
options provisioning.DestroyOptions,
|
||||
) (*provisioning.DestroyResult, error) {
|
||||
isRemoteBackendConfig, err := t.isRemoteBackendConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading backend config: %w", err)
|
||||
|
@ -262,12 +265,15 @@ func (t *TerraformProvider) Destroy(ctx context.Context, options DestroyOptions)
|
|||
return nil, fmt.Errorf("template Deploy failed: %s, err: %w", runResult, err)
|
||||
}
|
||||
|
||||
return &DestroyResult{
|
||||
return &provisioning.DestroyResult{
|
||||
InvalidatedEnvKeys: slices.Collect(maps.Keys(outputs)),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *TerraformProvider) State(ctx context.Context, options *StateOptions) (*StateResult, error) {
|
||||
func (t *TerraformProvider) State(
|
||||
ctx context.Context,
|
||||
options *provisioning.StateOptions,
|
||||
) (*provisioning.StateResult, error) {
|
||||
isRemoteBackendConfig, err := t.isRemoteBackendConfig()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading backend config: %w", err)
|
||||
|
@ -281,12 +287,12 @@ func (t *TerraformProvider) State(ctx context.Context, options *StateOptions) (*
|
|||
return nil, fmt.Errorf("fetching terraform state failed: %w", err)
|
||||
}
|
||||
|
||||
state := State{}
|
||||
state := provisioning.State{}
|
||||
|
||||
state.Outputs = t.convertOutputs(terraformState.Values.Outputs)
|
||||
state.Resources = t.collectAzureResources(terraformState.Values.RootModule)
|
||||
|
||||
return &StateResult{
|
||||
return &provisioning.StateResult{
|
||||
State: &state,
|
||||
}, nil
|
||||
}
|
||||
|
@ -378,7 +384,7 @@ func (t *TerraformProvider) createOutputParameters(
|
|||
ctx context.Context,
|
||||
modulePath string,
|
||||
isRemoteBackend bool,
|
||||
) (map[string]OutputParameter, error) {
|
||||
) (map[string]provisioning.OutputParameter, error) {
|
||||
cmd := []string{}
|
||||
|
||||
if !isRemoteBackend {
|
||||
|
@ -398,18 +404,18 @@ func (t *TerraformProvider) createOutputParameters(
|
|||
return t.convertOutputs(outputMap), nil
|
||||
}
|
||||
|
||||
func (t *TerraformProvider) mapTerraformTypeToInterfaceType(typ any) ParameterType {
|
||||
func (t *TerraformProvider) mapTerraformTypeToInterfaceType(typ any) provisioning.ParameterType {
|
||||
// in the JSON output, the type property maps to either a string (for a primitive type) or an
|
||||
// array of things which describe a complex type.
|
||||
switch v := typ.(type) {
|
||||
case string:
|
||||
switch v {
|
||||
case "string":
|
||||
return ParameterTypeString
|
||||
return provisioning.ParameterTypeString
|
||||
case "bool":
|
||||
return ParameterTypeBoolean
|
||||
return provisioning.ParameterTypeBoolean
|
||||
case "number":
|
||||
return ParameterTypeNumber
|
||||
return provisioning.ParameterTypeNumber
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown primitive type: %s", v))
|
||||
}
|
||||
|
@ -418,27 +424,27 @@ func (t *TerraformProvider) mapTerraformTypeToInterfaceType(typ any) ParameterTy
|
|||
// first part and map to either and object or array.
|
||||
switch v[0].(string) {
|
||||
case "list", "tuple", "set":
|
||||
return ParameterTypeArray
|
||||
return provisioning.ParameterTypeArray
|
||||
case "object", "map":
|
||||
return ParameterTypeObject
|
||||
return provisioning.ParameterTypeObject
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown complex type tag: %s (full type: %+v)", v, typ))
|
||||
}
|
||||
}
|
||||
|
||||
return ParameterTypeString
|
||||
return provisioning.ParameterTypeString
|
||||
}
|
||||
|
||||
// convertOutputs converts a terraform output map to the canonical format shared by all provider implementations.
|
||||
func (t *TerraformProvider) convertOutputs(outputMap map[string]terraformOutput) map[string]OutputParameter {
|
||||
outputParameters := make(map[string]OutputParameter)
|
||||
func (t *TerraformProvider) convertOutputs(outputMap map[string]terraformOutput) map[string]provisioning.OutputParameter {
|
||||
outputParameters := make(map[string]provisioning.OutputParameter)
|
||||
for k, v := range outputMap {
|
||||
if val, ok := v.Value.(string); ok && val == "null" {
|
||||
// omit null
|
||||
continue
|
||||
}
|
||||
|
||||
outputParameters[k] = OutputParameter{
|
||||
outputParameters[k] = provisioning.OutputParameter{
|
||||
Type: t.mapTerraformTypeToInterfaceType(v.Type),
|
||||
Value: v.Value,
|
||||
}
|
||||
|
@ -471,8 +477,8 @@ func (t *TerraformProvider) showCurrentState(
|
|||
}
|
||||
|
||||
// Creates the deployment object from the specified module path
|
||||
func (t *TerraformProvider) createDeployment(ctx context.Context) (*Deployment, error) {
|
||||
templateParameters := make(map[string]InputParameter)
|
||||
func (t *TerraformProvider) createDeployment(ctx context.Context) (*provisioning.Deployment, error) {
|
||||
templateParameters := make(map[string]provisioning.InputParameter)
|
||||
|
||||
//build the template parameters.
|
||||
parameters := make(map[string]any)
|
||||
|
@ -494,13 +500,13 @@ func (t *TerraformProvider) createDeployment(ctx context.Context) (*Deployment,
|
|||
}
|
||||
|
||||
for key, param := range parameters {
|
||||
templateParameters[key] = InputParameter{
|
||||
templateParameters[key] = provisioning.InputParameter{
|
||||
Type: key,
|
||||
Value: param,
|
||||
}
|
||||
}
|
||||
|
||||
template := Deployment{
|
||||
template := provisioning.Deployment{
|
||||
Parameters: templateParameters,
|
||||
}
|
||||
|
||||
|
@ -511,7 +517,7 @@ func (t *TerraformProvider) createDeployment(ctx context.Context) (*Deployment,
|
|||
// resources from all child modules. Only resources managed by azure providers are considered (today, that's
|
||||
// just resources from the `registry.terraform.io/hashicorp/azurerm` provider). Only "managed" resources are
|
||||
// considered.
|
||||
func (t *TerraformProvider) collectAzureResources(rootModule terraformRootModule) []Resource {
|
||||
func (t *TerraformProvider) collectAzureResources(rootModule terraformRootModule) []provisioning.Resource {
|
||||
// the set of resources we've seen (keyed by their id)
|
||||
azureResources := make(map[string]struct{})
|
||||
|
||||
|
@ -547,9 +553,9 @@ func (t *TerraformProvider) collectAzureResources(rootModule terraformRootModule
|
|||
}
|
||||
|
||||
// At this point, allResources contains the ids of all the resources we discovered.
|
||||
resources := make([]Resource, 0, len(azureResources))
|
||||
resources := make([]provisioning.Resource, 0, len(azureResources))
|
||||
for id := range azureResources {
|
||||
resources = append(resources, Resource{
|
||||
resources = append(resources, provisioning.Resource{
|
||||
Id: id,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/azure/azure-dev/cli/azd/pkg/cloud"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/environment"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/exec"
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/prompt"
|
||||
terraformTools "github.com/azure/azure-dev/cli/azd/pkg/tools/terraform"
|
||||
"github.com/azure/azure-dev/cli/azd/test/mocks"
|
||||
|
@ -66,7 +66,7 @@ func TestTerraformDestroy(t *testing.T) {
|
|||
prepareDestroyMocks(mockContext.CommandRunner)
|
||||
|
||||
infraProvider := createTerraformProvider(t, mockContext)
|
||||
destroyOptions := NewDestroyOptions(false, false)
|
||||
destroyOptions := provisioning.NewDestroyOptions(false, false)
|
||||
destroyResult, err := infraProvider.Destroy(*mockContext.Context, destroyOptions)
|
||||
|
||||
require.Nil(t, err)
|
||||
|
@ -99,7 +99,7 @@ func TestTerraformState(t *testing.T) {
|
|||
|
||||
func createTerraformProvider(t *testing.T, mockContext *mocks.MockContext) *TerraformProvider {
|
||||
projectDir := "../../../../test/functional/testdata/samples/resourcegroupterraform"
|
||||
options := Options{
|
||||
options := provisioning.Options{
|
||||
Module: "main",
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/account"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/environment"
|
||||
. "github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/infra/provisioning"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/input"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/prompt"
|
||||
"github.com/azure/azure-dev/cli/azd/pkg/tools"
|
||||
|
@ -22,7 +22,7 @@ type TestProvider struct {
|
|||
envManager environment.Manager
|
||||
env *environment.Environment
|
||||
projectPath string
|
||||
options Options
|
||||
options provisioning.Options
|
||||
console input.Console
|
||||
prompters prompt.Prompter
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func (p *TestProvider) RequiredExternalTools() []tools.ExternalTool {
|
|||
return []tools.ExternalTool{}
|
||||
}
|
||||
|
||||
func (p *TestProvider) Initialize(ctx context.Context, projectPath string, options Options) error {
|
||||
func (p *TestProvider) Initialize(ctx context.Context, projectPath string, options provisioning.Options) error {
|
||||
p.projectPath = projectPath
|
||||
p.options = options
|
||||
|
||||
|
@ -49,7 +49,7 @@ func (p *TestProvider) Initialize(ctx context.Context, projectPath string, optio
|
|||
// An environment is considered to be in a provision-ready state if it contains both an AZURE_SUBSCRIPTION_ID and
|
||||
// AZURE_LOCATION value.
|
||||
func (t *TestProvider) EnsureEnv(ctx context.Context) error {
|
||||
return EnsureSubscriptionAndLocation(
|
||||
return provisioning.EnsureSubscriptionAndLocation(
|
||||
ctx,
|
||||
t.envManager,
|
||||
t.env,
|
||||
|
@ -58,60 +58,63 @@ func (t *TestProvider) EnsureEnv(ctx context.Context) error {
|
|||
)
|
||||
}
|
||||
|
||||
func (p *TestProvider) State(ctx context.Context, options *StateOptions) (*StateResult, error) {
|
||||
func (p *TestProvider) State(ctx context.Context, options *provisioning.StateOptions) (*provisioning.StateResult, error) {
|
||||
// TODO: progress, "Looking up deployment"
|
||||
|
||||
state := State{
|
||||
Outputs: make(map[string]OutputParameter),
|
||||
Resources: make([]Resource, 0),
|
||||
state := provisioning.State{
|
||||
Outputs: make(map[string]provisioning.OutputParameter),
|
||||
Resources: make([]provisioning.Resource, 0),
|
||||
}
|
||||
|
||||
return &StateResult{
|
||||
return &provisioning.StateResult{
|
||||
State: &state,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *TestProvider) GetDeployment(ctx context.Context) (*DeployResult, error) {
|
||||
func (p *TestProvider) GetDeployment(ctx context.Context) (*provisioning.DeployResult, error) {
|
||||
// TODO: progress, "Looking up deployment"
|
||||
|
||||
deployment := Deployment{
|
||||
Parameters: make(map[string]InputParameter),
|
||||
Outputs: make(map[string]OutputParameter),
|
||||
deployment := provisioning.Deployment{
|
||||
Parameters: make(map[string]provisioning.InputParameter),
|
||||
Outputs: make(map[string]provisioning.OutputParameter),
|
||||
}
|
||||
|
||||
return &DeployResult{
|
||||
return &provisioning.DeployResult{
|
||||
Deployment: &deployment,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Provisioning the infrastructure within the specified template
|
||||
func (p *TestProvider) Deploy(ctx context.Context) (*DeployResult, error) {
|
||||
func (p *TestProvider) Deploy(ctx context.Context) (*provisioning.DeployResult, error) {
|
||||
// TODO: progress, "Deploying azure resources"
|
||||
|
||||
deployment := Deployment{
|
||||
Parameters: make(map[string]InputParameter),
|
||||
Outputs: make(map[string]OutputParameter),
|
||||
deployment := provisioning.Deployment{
|
||||
Parameters: make(map[string]provisioning.InputParameter),
|
||||
Outputs: make(map[string]provisioning.OutputParameter),
|
||||
}
|
||||
|
||||
return &DeployResult{
|
||||
return &provisioning.DeployResult{
|
||||
Deployment: &deployment,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Provisioning the infrastructure within the specified template
|
||||
func (p *TestProvider) Preview(ctx context.Context) (*DeployPreviewResult, error) {
|
||||
return &DeployPreviewResult{
|
||||
Preview: &DeploymentPreview{
|
||||
func (p *TestProvider) Preview(ctx context.Context) (*provisioning.DeployPreviewResult, error) {
|
||||
return &provisioning.DeployPreviewResult{
|
||||
Preview: &provisioning.DeploymentPreview{
|
||||
Status: "Completed",
|
||||
Properties: &DeploymentPreviewProperties{},
|
||||
Properties: &provisioning.DeploymentPreviewProperties{},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *TestProvider) Destroy(ctx context.Context, options DestroyOptions) (*DestroyResult, error) {
|
||||
func (p *TestProvider) Destroy(
|
||||
ctx context.Context,
|
||||
options provisioning.DestroyOptions,
|
||||
) (*provisioning.DestroyResult, error) {
|
||||
// TODO: progress, "Starting destroy"
|
||||
|
||||
destroyResult := DestroyResult{
|
||||
destroyResult := provisioning.DestroyResult{
|
||||
InvalidatedEnvKeys: []string{},
|
||||
}
|
||||
|
||||
|
@ -134,7 +137,7 @@ func NewTestProvider(
|
|||
env *environment.Environment,
|
||||
console input.Console,
|
||||
prompters prompt.Prompter,
|
||||
) Provider {
|
||||
) provisioning.Provider {
|
||||
return &TestProvider{
|
||||
envManager: envManager,
|
||||
env: env,
|
||||
|
|
2
go.mod
2
go.mod
|
@ -20,6 +20,7 @@ require (
|
|||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.0.0
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/machinelearning/armmachinelearning/v3 v3.2.0
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resourcegraph/armresourcegraph v0.7.1
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentstacks v1.0.0
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.0.0
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql/v2 v2.0.0-beta.4
|
||||
|
@ -74,7 +75,6 @@ require (
|
|||
require (
|
||||
github.com/Azure/azure-pipeline-go v0.2.1 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armdeploymentstacks v1.0.0 // indirect
|
||||
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0 // indirect
|
||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -51,14 +51,10 @@ github.com/AlecAivazis/survey/v2 v2.3.2 h1:TqTB+aDDCLYhf9/bD2TwSO8u8jDSmMUd2SUVO
|
|||
github.com/AlecAivazis/survey/v2 v2.3.2/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg=
|
||||
github.com/Azure/azure-pipeline-go v0.2.1 h1:OLBdZJ3yvOn2MezlWvbrBMTEUQC72zAftRZOMdj5HYo=
|
||||
github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1 h1:E+OJmp2tPvt1W+amx48v1eqbjDYsgN+RzP4q16yV5eM=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1/go.mod h1:a6xsAQUZg+VsS3TJ05SRp524Hs4pZ/AeFSr5ENf0Yjo=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0 h1:1nGuui+4POelzDwI7RG56yfQJHCnKvwfMoU7VsEp+Zg=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.12.0/go.mod h1:99EvauvlcJ1U06amZiksfYz/3aFGyIhWGHVyiZXtBAI=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0 h1:U2rTu3Ef+7w9FHKIAXM6ZyqF3UOWJZ12zIm8zECAFfg=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.6.0/go.mod h1:9kIvujWAA58nmPmWB1m23fyWic1kYZMxD9CxaWn4Qpg=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0 h1:jBQA3cKT4L2rWMpgE7Yt3Hwh2aUj8KXjIGLxjHeYNNo=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.8.0/go.mod h1:4OG6tQ9EOP/MT0NMjDlRzWoVFxfu9rN9B2X+tlSVktg=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0 h1:H+U3Gk9zY56G3u872L82bk4thcsy2Gghb9ExT4Zvm1o=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/internal v1.9.0/go.mod h1:mgrmMSgaLp9hmax62XQTd0N4aAqSE5E0DulSpVYK7vc=
|
||||
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/apimanagement/armapimanagement v1.0.0 h1:Ai3+BE11JvwQ2PxLGNKAfMNSceYXjeijReLJiCouO6o=
|
||||
|
|
Загрузка…
Ссылка в новой задаче