Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit adcadf0

Browse files
committed
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 <[email protected]>
1 parent 04c78c2 commit adcadf0

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

aci/context.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ func (helper contextCreateACIHelper) createContextData(ctx context.Context, opts
9999
}
100100
}
101101

102-
location := *group.Location
102+
location := opts.Location
103+
if opts.Location == "" {
104+
location = *group.Location
105+
}
103106

104107
description := fmt.Sprintf("%s@%s", *group.Name, location)
105108
if opts.Description != "" {

aci/context_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ func TestCreateNewResourceGroup(t *testing.T) {
107107
assert.DeepEqual(t, data, aciContext("1234", "newResourceGroup", "eastus"))
108108
}
109109

110+
func TestCreateNewResourceGroupWithSpecificLocation(t *testing.T) {
111+
ctx := context.TODO()
112+
opts := options("1234", "")
113+
opts.Location = "eastus2"
114+
m := testContextMocks()
115+
m.resourceGroupHelper.On("GetSubscriptionIDs", ctx).Return([]subscription.Model{subModel("1234", "Subscription1")}, nil)
116+
m.resourceGroupHelper.On("GetGroup", ctx, "1234", "myResourceGroup").Return(group("myResourceGroup", "eastus"), nil)
117+
118+
selectOptions := []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"}
119+
m.userPrompt.On("Select", "Select a resource group", selectOptions).Return(0, nil)
120+
m.resourceGroupHelper.On("CreateOrUpdate", ctx, "1234", mock.AnythingOfType("string"), mock.AnythingOfType("resources.Group")).Return(group("newResourceGroup", "eastus"), nil)
121+
m.resourceGroupHelper.On("ListGroups", ctx, "1234").Return([]resources.Group{
122+
group("group1", "eastus"),
123+
group("group2", "westeurope"),
124+
}, nil)
125+
126+
data, description, err := m.contextCreateHelper.createContextData(ctx, opts)
127+
assert.NilError(t, err)
128+
assert.Equal(t, description, "newResourceGroup@eastus2")
129+
assert.DeepEqual(t, data, aciContext("1234", "newResourceGroup", "eastus2"))
130+
}
131+
110132
func TestSelectExistingResourceGroup(t *testing.T) {
111133
ctx := context.TODO()
112134
opts := options("1234", "")
@@ -194,7 +216,6 @@ func options(subscriptionID string, resourceGroupName string) ContextParams {
194216
return ContextParams{
195217
SubscriptionID: subscriptionID,
196218
ResourceGroup: resourceGroupName,
197-
Location: "eastus",
198219
}
199220
}
200221

cli/cmd/context/create_aci.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ func createAciCommand() *cobra.Command {
4949
}
5050

5151
addDescriptionFlag(cmd, &opts.Description)
52-
cmd.Flags().StringVar(&opts.Location, "location", "eastus", "Location")
53-
cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Location")
52+
cmd.Flags().StringVar(&opts.Location, "location", "", "Location")
53+
cmd.Flags().StringVar(&opts.SubscriptionID, "subscription-id", "", "Subscription id")
5454
cmd.Flags().StringVar(&opts.ResourceGroup, "resource-group", "", "Resource group")
5555

5656
return cmd

0 commit comments

Comments
 (0)