farmer icon indicating copy to clipboard operation
farmer copied to clipboard

Order of `location` in `arm` builder changes resource location

Open ninjarobot opened this issue 4 years ago • 3 comments

When setting the location in the arm builder, I found that the order matters, which is confusing, especially if the location is only set once in the builder. While this could be used to intentionally deploy different resources to different locations, we probably should have a different default (maybe "[resourceGroup().location]") or consider rebuilding the resources that are added after a location change so they get the updated location.

Given a resource:

let vault =
    keyVault {
        name "my-farmer-kv"
        sku Sku.Standard
    }

if I set the location first, the resource will have that location:

let deployment = arm {
    location Location.EastUS
    add_resource vault
}

result:

      "dependsOn": [],
      "location": "eastus",
      "name": "my-farmer-kv",
      "properties": {
        "accessPolicies": [],

But if I set the location after the resource, it will be in the default location of west europe:

let deployment = arm {
    add_resource vault
    location Location.EastUS
}

result:

      "dependsOn": [],
      "location": "westeurope",
      "name": "my-farmer-kv",
      "properties": {
        "accessPolicies": [],

ninjarobot avatar Jul 08 '21 11:07 ninjarobot

Mmmmm. We could fix this by moving the creation of all resources into Run() on the ARM builder. Then simply the last location specified in the template would "win" (or we could fail if that happens).

isaacabraham avatar Jul 08 '21 16:07 isaacabraham

Or we could look to move to resourceGroup.location in general for all resources and just set the location on the RG itself.

isaacabraham avatar Jul 08 '21 16:07 isaacabraham

I think it would make sense to add Locations.ResourceGroup or something like that. I use it a lot myself, and it would be a good default.

But I think if we wanted to make it easier for some resource to be in different locations, maybe some operation like add_resources_in_location would be better than something implicit.

ninjarobot avatar Jul 10 '21 21:07 ninjarobot