Azure / azurehpc

This repository provides easy automation scripts for building a HPC environment in Azure. It also includes examples to build e2e environment and run some of the key HPC benchmarks and applications.
MIT License
124 stars 66 forks source link

Add ability to use variables in config dictionary keys #664

Closed yosoyjay closed 2 years ago

yosoyjay commented 2 years ago

Adds the ability to use variables (e.g. "variables.") in config dictionary key names which is useful in avoiding name collisions for resources created in the same account.

As an example, the json blob below is an example where a jumpbox VM is named using the expansion of the variable variables.jumpbox_name in the definition of resources.

{
    "location": "variables.location",
    "resource_group": "variables.resource_group",
    "install_from": "variables.jumpbox_name",
    "admin_user": "variables.admin_user",
    "variables": {
        "location": "<NOT-SET>",
        "resource_group": "<NOT-SET>",
        "vnet_resource_group": "variables.resource_group",
        "vnet_name": "<NOT-SET>",
        "admin_user": "hpcadmin",
        "image": "OpenLogic:CentOS:7.7:latest",
        "jb_vm_type": "Standard_D8s_v3",
        "jumpbox_name": "test-jumpbox"
    },
    "vnet": {
        "resource_group": "variables.vnet_resource_group",
        "name": "variables.vnet_name"
    },
    "resources": {
        "variables.jumpbox_name": {
            "type": "vm",
            "vm_type": "variables.jb_vm_type",
            "accelerated_networking": true,
            "public_ip": false,
            "image": "variables.image",
            "subnet": "default",
            "tags": [
                "jumpbox"
            ]
        }
    },
    "install": [
        {
            "script": "disable-selinux.sh",
            "tag": "variables.jumpbox_name",
            "sudo": true
        },
        {
            "script": "cndefault.sh",
            "tag": "variables.jumpbox_name",
            "sudo": true
        }
    ]
}

Commits also include removal of trailing whitespace in changed files.

yosoyjay commented 2 years ago

@edwardsp Hugo suggested you review this PR as you might have good visibility to identify some undesired side effects.

yosoyjay commented 2 years ago

I tested creating a new VM in two scenarios and was able to connect using azhpc connect test-jumpbox. In the first, I provision the new VM in an existing VNet. In the second, I create a new VNet and then peer it with an existing VNet to use the VNG that exists within it and then create a new VM in the VNet.

Did you have a specific test that it failed for that you could share?

For reference. The first scenario (existing VNet):

{
    "location": "variables.location",
    "resource_group": "variables.resource_group",
    "install_from": "variables.jumpbox_name",
    "admin_user": "variables.admin_user",
    "variables": {
        "location": "<NOT-SET>",
        "resource_group": "<NOT-SET>",
        "vnet_resource_group": "<NOT-SET>",
        "vnet_name": "<NOT-SET>",
        "admin_user": "hpcadmin",
        "image": "OpenLogic:CentOS:7.7:latest",
        "jb_vm_type": "Standard_D8s_v3",
        "jumpbox_name": "test-jumpbox"
    },
    "vnet": {
        "resource_group": "variables.vnet_resource_group",
        "name": "variables.vnet_name"
    },
    "resources": {
        "variables.jumpbox_name": {
            "type": "vm",
            "vm_type": "variables.jb_vm_type",
            "accelerated_networking": true,
            "public_ip": false,
            "image": "variables.image",
            "subnet": "default",
            "tags": [
                "jumpbox"
            ]
        }
    },
    "install": [
        {
            "script": "disable-selinux.sh",
            "tag": "variables.jumpbox_name",
            "sudo": true
        },
        {
            "script": "cndefault.sh",
            "tag": "variables.jumpbox_name",
            "sudo": true
        }
    ]
}

The second (create a new VNet, add peering and setup the gateway):

{
    "location": "variables.location",
    "resource_group": "variables.resource_group",
    "install_from": "variables.jumpbox_name",
    "admin_user": "variables.admin_user",
    "variables": {
        "location": "<NOT-SET>",
        "resource_group": "<NOT-SET>",
        "vnet_resource_group": "variables.resource_group",
        "vnet_name": "<NOT-SET>",
        "admin_user": "hpcadmin",
        "image": "OpenLogic:CentOS:7.7:latest",
        "jb_vm_type": "Standard_D8s_v3",
        "jumpbox_name": "test-jumpbox",
        "vnet_peer": "<NOT-SET>",
        "vnet_peer_rg": "<NOT-SET>"
    },
    "vnet": {
        "resource_group": "variables.vnet_resource_group",
        "name": "variables.vnet_name",
        "address_prefix": "10.2.0.0/20",
        "subnets": {
            "default": "10.2.1.0/24"
        },
        "peer": {
            "variables.vnet_peer": {
                "resource_group": "variables.vnet_peer_rg",
                "vnet_name": "variables.vnet_peer",
                "gateway": {
                    "peer_use_remote_gateways": true,
                    "vnet_allow_gateway_transit": true
                }
            }
        }
    },
    "resources": {
        "variables.jumpbox_name": {
            "type": "vm",
            "vm_type": "variables.jb_vm_type",
            "accelerated_networking": true,
            "public_ip": false,
            "image": "variables.image",
            "subnet": "default",
            "tags": [
                "jumpbox"
            ]
        }
    },
    "install": [
        {
            "script": "disable-selinux.sh",
            "tag": "variables.jumpbox_name",
            "sudo": true
        },
        {
            "script": "cndefault.sh",
            "tag": "variables.jumpbox_name",
            "sudo": true
        }
    ]
}
yosoyjay commented 2 years ago

Should I cherry-pick the changes to the tests from https://github.com/Azure/azurehpc/commit/7e897c3043b87add885877a5c0eda984f2dc29eb?