{
  "name": "Basic Create VM",
  "nodes": [
    {
      "parameters": {
        "formTitle": "Create VM",
        "formFields": {
          "values": [
            {
              "fieldLabel": "VM Name",
              "placeholder": "New-VM",
              "requiredField": true
            },
            {
              "fieldLabel": "RAM",
              "fieldType": "number",
              "placeholder": "2",
              "requiredField": true
            },
            {
              "fieldLabel": "CPU",
              "fieldType": "number",
              "placeholder": "1",
              "requiredField": true
            },
            {
              "fieldLabel": "Disk Space (GB)",
              "fieldType": "number",
              "placeholder": "50",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.2,
      "position": [
        -672,
        -432
      ],
      "id": "7aec35e8-bcb4-4fe8-aa46-256ccab05104",
      "name": "On form submission"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        -336,
        -704
      ],
      "id": "cfda6bbf-3bf8-4969-be03-fbc22d5d98c9",
      "name": "Merge"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://vcenter.lab/api/vcenter/vm/{{ $json['new-vm-id'] }}/power?action=start",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "vmware-api-session-id",
              "value": "={{ $json['api-key'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "new-vm-id"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2304,
        -432
      ],
      "id": "ccf3443b-d47e-4139-9baf-29a77e748c62",
      "name": "Power On VM",
      "notes": ""
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://vcenter.lab/api/vcenter/vm",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "vmware-api-session-id",
              "value": "={{ $json['api-key'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n\t\"name\": \"{{ $json['VM Name'] }}\",\n\t\"memory\": {\n\t\t\"size_MiB\": \"{{ $json.RAM * 1024 }}\",\n\t\t\"hot_add_enabled\": true\n\t},\n\t\"cpu\": {\n\t\t\"count\": \"{{ $json.CPU }}\"\n\t},\n\t\"guest_OS\": \"RHEL_9_64\",\n\t\"placement\": {\n\t\t\"cluster\": \"domain-c10007\",\n\t\t\"folder\": \"group-v13014\",\n\t\t\"datastore\": \"datastore-3008\"\n\t},\n\t    \"nics\": [\n        {\n            \"type\": \"VMXNET3\",\n            \"mac_type\": \"ASSIGNED\",\n            \"backing\": {\n                \"type\": \"STANDARD_PORTGROUP\",\n                \"network\": \"network-3010\"\n            },\n            \"start_connected\": true,\n            \"allow_guest_control\": true\n        }\n    ],\n    \"cdroms\": [\n        {\n            \"start_connected\": false,\n            \"allow_guest_control\": true\n        }\n    ],\n\t\"disks\": [\n\t\t{\n\t\t\t\"type\": \"SCSI\",\n\t\t\t\"scsi\": {\n\t\t\t\t\"bus\": 0,\n\t\t\t\t\"unit\": 0\n\t\t\t},\n\t\t\t\"new_vmdk\": {\n\t\t\t\t\"capacity\": \"{{ $json['Disk Space (GB)'] * 1024 * 1024 * 1024 }}\"\n\t\t\t}\n\t\t}\n\t]\n}",
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "new-vm-id"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        672,
        -432
      ],
      "id": "3b99301b-4217-4b36-9274-ea1f8c22066b",
      "name": "Create VM",
      "notes": ""
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://vcenter.lab/api/session",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpBasicAuth",
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "api-key"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -464,
        -432
      ],
      "id": "7c49430e-a117-4861-9695-38b9f1e0e033",
      "name": "Get API Token",
      "credentials": {
        "httpBasicAuth": {
          "name": "<your credential>"
        }
      },
      "notes": ""
    },
    {
      "parameters": {
        "method": "PATCH",
        "url": "=https://vcenter.lab/api/vcenter/vm/{{ $json['new-vm-id'] }}/hardware/cdrom/{{ $json['cdrom-id'].parseJson()[0].cdrom }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "vmware-api-session-id",
              "value": "={{ $json['api-key'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "{\n    \"backing\": {\n      \"type\": \"ISO_FILE\",\n      \"iso_file\": \"[NFS-datastore] ISOs/centos-10-ks.iso\"\n    },\n    \"allow_guest_control\": true,\n    \"start_connected\": true\n  }",
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "new-vm-id"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1232,
        -432
      ],
      "id": "38ecded3-2f83-4081-90ec-573c8e6758c5",
      "name": "Mount Install ISO",
      "notes": ""
    },
    {
      "parameters": {
        "url": "=https://vcenter.lab/api/vcenter/vm/{{ $json['new-vm-id'] }}/hardware/cdrom",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "vmware-api-session-id",
              "value": "={{ $json['api-key'] }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "text",
              "outputPropertyName": "cdrom-id"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        976,
        -432
      ],
      "id": "285dfbe8-27e0-46ab-85f9-87a6ecb16ddc",
      "name": "Get CDROM id",
      "notes": ""
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        816,
        -688
      ],
      "id": "84bde2cb-0d5b-49cd-b2c7-77b4995d3306",
      "name": "Merge1"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1072,
        -656
      ],
      "id": "93c3edb9-70f3-4849-ae06-e728abe8d335",
      "name": "Merge2"
    },
    {
      "parameters": {
        "url": "=https://vcenter.lab/api/vcenter/vm/{{ $json['new-vm-id'] }}/power",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "vmware-api-session-id",
              "value": "={{ $json['api-key'] }}"
            }
          ]
        },
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1648,
        -416
      ],
      "id": "dfcc7225-2c74-4c09-8b3c-96e07b1816ba",
      "name": "Check VM Status",
      "alwaysOutputData": false,
      "retryOnFail": false,
      "waitBetweenTries": 3000,
      "notes": ""
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "9cc4169e-162b-4760-ad98-ab3c1d30df59",
              "leftValue": "={{ $json.success }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "or"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        256,
        -448
      ],
      "id": "8e32bb3e-a5bf-463d-b34a-48460a0eb049",
      "name": "If"
    },
    {
      "parameters": {
        "url": "https://vcenter.lab/api/vcenter/vm",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "vmware-api-session-id",
              "value": "={{ $json['api-key'] }}"
            }
          ]
        },
        "options": {
          "allowUnauthorizedCerts": true,
          "response": {
            "response": {
              "responseFormat": "json"
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -128,
        -448
      ],
      "id": "50b01a25-cc96-4458-aa2e-456e791676fd",
      "name": "Get VM List",
      "notes": ""
    },
    {
      "parameters": {
        "mode": "combineBySql",
        "query": "SELECT * FROM input1 INNER JOIN input2 ON input1.vm-name = input2.name",
        "options": {
          "emptyQueryResult": "=success"
        }
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        96,
        -448
      ],
      "id": "ab145c7b-9f85-4d36-b609-ffe7f45e339e",
      "name": "Merge3",
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5ea7cd1f-5ba5-42f4-9bc9-2245d0c88402",
              "name": "vm-name",
              "value": "={{ $json['VM Name'] }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -128,
        -576
      ],
      "id": "81aadfad-bba5-4d1c-a805-b5b2d4123b4e",
      "name": "Strip to VM Name"
    },
    {
      "parameters": {
        "errorMessage": "VM Already Exists!"
      },
      "type": "n8n-nodes-base.stopAndError",
      "typeVersion": 1,
      "position": [
        496,
        -240
      ],
      "id": "6d3e1bbe-6777-4177-a188-949932faa15a",
      "name": "Stop and Error"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        496,
        -512
      ],
      "id": "364bba5a-4909-49c1-aa19-1f10b418a8e0",
      "name": "Merge4"
    },
    {
      "parameters": {
        "mode": "chooseBranch"
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1408,
        -656
      ],
      "id": "21af8fc2-6d7f-4e19-a4c8-30d9d9251764",
      "name": "Merge5"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "5cf606a6-27e1-4029-b2e3-0f8b11429dea",
              "leftValue": "={{ $json.state }}",
              "rightValue": "POWERED_OFF",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1856,
        -416
      ],
      "id": "b52f2cd2-fb7a-4f71-a677-6e253d8b8f64",
      "name": "If1"
    },
    {
      "parameters": {
        "mode": "chooseBranch"
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        2080,
        -640
      ],
      "id": "70579b7d-4146-4a98-af4c-028bf51ef7d3",
      "name": "Merge6"
    }
  ],
  "connections": {
    "On form submission": {
      "main": [
        [
          {
            "node": "Get API Token",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get VM List",
            "type": "main",
            "index": 0
          },
          {
            "node": "Strip to VM Name",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get API Token": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create VM": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Get CDROM id": {
      "main": [
        [
          {
            "node": "Merge2",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Get CDROM id",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge2": {
      "main": [
        [
          {
            "node": "Mount Install ISO",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge5",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mount Install ISO": {
      "main": [
        [
          {
            "node": "Merge5",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Check VM Status": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Merge4",
            "type": "main",
            "index": 1
          }
        ],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get VM List": {
      "main": [
        [
          {
            "node": "Merge3",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge3": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Strip to VM Name": {
      "main": [
        [
          {
            "node": "Merge3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge4": {
      "main": [
        [
          {
            "node": "Create VM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge5": {
      "main": [
        [
          {
            "node": "Check VM Status",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Merge6",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge6": {
      "main": [
        [
          {
            "node": "Power On VM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": false,
    "callerPolicy": "workflowsFromSameOwner",
    "executionTimeout": -1
  },
  "versionId": "77d579a0-30c7-4073-a04e-8e188b784147",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "xAodhMxT0AlNCOqX",
  "tags": []
}