From adcadf0af21c17ff783b098b006e2093407f72b9 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Wed, 5 May 2021 16:16:08 +0200 Subject: [PATCH] Use location specifed by user if provided, and do not override with group location. ACI allow deploying in any location regardless of resource group Signed-off-by: Guillaume Tardif --- aci/context.go | 5 ++++- aci/context_test.go | 23 ++++++++++++++++++++++- cli/cmd/context/create_aci.go | 4 ++-- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/aci/context.go b/aci/context.go index 7f9cdb4c2..2ce1b6c1c 100644 --- a/aci/context.go +++ b/aci/context.go @@ -99,7 +99,10 @@ func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts } } - location := *group.Location + location := opts.Location + if opts.Location == "" { + location = *group.Location + } description := fmt.Sprintf("%s@%s", *group.Name, location) if opts.Description != "" { diff --git a/aci/context_test.go b/aci/context_test.go index 88d726566..51a384e3d 100644 --- a/aci/context_test.go +++ b/aci/context_test.go @@ -107,6 +107,28 @@ func TestCreateNewResourceGroup(t *testing.T) { assert.DeepEqual(t, data, aciContext("1234", "newResourceGroup", "eastus")) } +func TestCreateNewResourceGroupWithSpecificLocation(t *testing.T) { + ctx := context.TODO() + opts := options("1234", "") + opts.Location = "eastus2" + m := testContextMocks() + m.resourceGroupHelper.On("GetSubscriptionIDs", ctx).Return([]subscription.Model{subModel("1234", "Subscription1")}, nil) + m.resourceGroupHelper.On("GetGroup", ctx, "1234", "myResourceGroup").Return(group("myResourceGroup", "eastus"), nil) + + selectOptions := []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"} + m.userPrompt.On("Select", "Select a resource group", selectOptions).Return(0, nil) + m.resourceGroupHelper.On("CreateOrUpdate", ctx, "1234", mock.AnythingOfType("string"), mock.AnythingOfType("resources.Group")).Return(group("newResourceGroup", "eastus"), nil) + m.resourceGroupHelper.On("ListGroups", ctx, "1234").Return([]resources.Group{ + group("group1", "eastus"), + group("group2", "westeurope"), + }, nil) + + data, description, err := m.contextCreateHelper.createContextData(ctx, opts) + assert.NilError(t, err) + assert.Equal(t, description, "newResourceGroup@eastus2") + assert.DeepEqual(t, data, aciContext("1234", "newResourceGroup", "eastus2")) +} + func TestSelectExistingResourceGroup(t *testing.T) { ctx := context.TODO() opts := options("1234", "") @@ -194,7 +216,6 @@ func options(subscriptionID string, resourceGroupName string) ContextParams { return ContextParams{ SubscriptionID: subscriptionID, ResourceGroup: resourceGroupName, - Location: "eastus", } } diff --git a/cli/cmd/context/create_aci.go b/cli/cmd/context/create_aci.go index 3efaee52c..775fd8103 100644 --- a/cli/cmd/context/create_aci.go +++ b/cli/cmd/context/create_aci.go @@ -49,8 +49,8 @@ func createAciCommand() *cobra.Command { } addDescriptionFlag(cmd, &opts.Description) - cmd.Flags().StringVar(&opts.Location, "location", "eastus", "Location") - cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Location") + cmd.Flags().StringVar(&opts.Location, "location", "", "Location") + cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Subscription id") cmd.Flags().StringVar(&opts.ResourceGroup, "resource-group", "", "Resource group") return cmd