Azure template: Eliminate unneeded variables

This commit is contained in:
Jack Ivanov 2019-03-14 18:06:32 +01:00
parent 3b76884c93
commit 4b484daf53
2 changed files with 23 additions and 32 deletions

View file

@ -2,15 +2,9 @@
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json", "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0", "contentVersion": "1.0.0.0",
"parameters": { "parameters": {
"AlgoServerName": {
"type": "string"
},
"sshKeyData": { "sshKeyData": {
"type": "string" "type": "string"
}, },
"location": {
"type": "string"
},
"WireGuardPort": { "WireGuardPort": {
"type": "int" "type": "int"
}, },
@ -22,15 +16,15 @@
} }
}, },
"variables": { "variables": {
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks', parameters('AlgoServerName'))]", "vnetID": "[resourceId('Microsoft.Network/virtualNetworks', resourceGroup().name)]",
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/', parameters('AlgoServerName'))]" "subnet1Ref": "[concat(variables('vnetID'),'/subnets/', resourceGroup().name)]"
}, },
"resources": [ "resources": [
{ {
"apiVersion": "2015-06-15", "apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkSecurityGroups", "type": "Microsoft.Network/networkSecurityGroups",
"name": "[parameters('AlgoServerName')]", "name": "[resourceGroup().name]",
"location": "[parameters('location')]", "location": "[resourceGroup().location]",
"properties": { "properties": {
"securityRules": [ "securityRules": [
{ {
@ -95,8 +89,8 @@
{ {
"apiVersion": "2015-06-15", "apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses", "type": "Microsoft.Network/publicIPAddresses",
"name": "[parameters('AlgoServerName')]", "name": "[resourceGroup().name]",
"location": "[parameters('location')]", "location": "[resourceGroup().location]",
"properties": { "properties": {
"publicIPAllocationMethod": "Static" "publicIPAllocationMethod": "Static"
} }
@ -104,8 +98,8 @@
{ {
"apiVersion": "2015-06-15", "apiVersion": "2015-06-15",
"type": "Microsoft.Network/virtualNetworks", "type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('AlgoServerName')]", "name": "[resourceGroup().name]",
"location": "[parameters('location')]", "location": "[resourceGroup().location]",
"properties": { "properties": {
"addressSpace": { "addressSpace": {
"addressPrefixes": [ "addressPrefixes": [
@ -114,7 +108,7 @@
}, },
"subnets": [ "subnets": [
{ {
"name": "[parameters('AlgoServerName')]", "name": "[resourceGroup().name]",
"properties": { "properties": {
"addressPrefix": "10.10.0.0/24" "addressPrefix": "10.10.0.0/24"
} }
@ -125,16 +119,16 @@
{ {
"apiVersion": "2015-06-15", "apiVersion": "2015-06-15",
"type": "Microsoft.Network/networkInterfaces", "type": "Microsoft.Network/networkInterfaces",
"name": "[parameters('AlgoServerName')]", "name": "[resourceGroup().name]",
"location": "[parameters('location')]", "location": "[resourceGroup().location]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/networkSecurityGroups/', parameters('AlgoServerName'))]", "[concat('Microsoft.Network/networkSecurityGroups/', resourceGroup().name)]",
"[concat('Microsoft.Network/publicIPAddresses/', parameters('AlgoServerName'))]", "[concat('Microsoft.Network/publicIPAddresses/', resourceGroup().name)]",
"[concat('Microsoft.Network/virtualNetworks/', parameters('AlgoServerName'))]" "[concat('Microsoft.Network/virtualNetworks/', resourceGroup().name)]"
], ],
"properties": { "properties": {
"networkSecurityGroup": { "networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('AlgoServerName'))]" "id": "[resourceId('Microsoft.Network/networkSecurityGroups', resourceGroup().name)]"
}, },
"ipConfigurations": [ "ipConfigurations": [
{ {
@ -142,7 +136,7 @@
"properties": { "properties": {
"privateIPAllocationMethod": "Dynamic", "privateIPAllocationMethod": "Dynamic",
"publicIPAddress": { "publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('AlgoServerName'))]" "id": "[resourceId('Microsoft.Network/publicIPAddresses', resourceGroup().name)]"
}, },
"subnet": { "subnet": {
"id": "[variables('subnet1Ref')]" "id": "[variables('subnet1Ref')]"
@ -155,17 +149,17 @@
{ {
"apiVersion": "2016-04-30-preview", "apiVersion": "2016-04-30-preview",
"type": "Microsoft.Compute/virtualMachines", "type": "Microsoft.Compute/virtualMachines",
"name": "[parameters('AlgoServerName')]", "name": "[resourceGroup().name]",
"location": "[parameters('location')]", "location": "[resourceGroup().location]",
"dependsOn": [ "dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', parameters('AlgoServerName'))]" "[concat('Microsoft.Network/networkInterfaces/', resourceGroup().name)]"
], ],
"properties": { "properties": {
"hardwareProfile": { "hardwareProfile": {
"vmSize": "[parameters('vmSize')]" "vmSize": "[parameters('vmSize')]"
}, },
"osProfile": { "osProfile": {
"computerName": "[parameters('AlgoServerName')]", "computerName": "[resourceGroup().name]",
"adminUsername": "ubuntu", "adminUsername": "ubuntu",
"linuxConfiguration": { "linuxConfiguration": {
"disablePasswordAuthentication": true, "disablePasswordAuthentication": true,
@ -193,7 +187,7 @@
"networkProfile": { "networkProfile": {
"networkInterfaces": [ "networkInterfaces": [
{ {
"id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('AlgoServerName'))]" "id": "[resourceId('Microsoft.Network/networkInterfaces', resourceGroup().name)]"
} }
] ]
} }
@ -203,7 +197,7 @@
"outputs": { "outputs": {
"publicIPAddresses": { "publicIPAddresses": {
"type": "string", "type": "string",
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',parameters('AlgoServerName')),providers('Microsoft.Network', 'publicIPAddresses').apiVersions[0]).ipAddress]", "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',resourceGroup().name),providers('Microsoft.Network', 'publicIPAddresses').apiVersions[0]).ipAddress]",
} }
} }
} }

View file

@ -23,13 +23,10 @@
client_id: "{{ client_id }}" client_id: "{{ client_id }}"
subscription_id: "{{ subscription_id }}" subscription_id: "{{ subscription_id }}"
resource_group_name: "{{ algo_server_name }}" resource_group_name: "{{ algo_server_name }}"
location: "{{ algo_region }}"
parameters: parameters:
AlgoServerName:
value: "{{ algo_server_name }}"
sshKeyData: sshKeyData:
value: "{{ lookup('file', '{{ SSH_keys.public }}') }}" value: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
location:
value: "{{ algo_region }}"
WireGuardPort: WireGuardPort:
value: "{{ wireguard_port }}" value: "{{ wireguard_port }}"
vmSize: vmSize: