You can use these common use case examples to help you define vSphere resources in blueprints that achieve your provisioning goals.

Create a Basic vSphere Resource

Table 1. Basic vSphere Machine Resource

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource

inputs: {}
resources:
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      name: demo-machine
      cpuCount: 1
      totalMemoryMB: 1024
      image: ubuntu

Create a vSphere Resource with an Additional Disk

Table 2. Basic vSphere Machine Resource With An Additional Disk

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource with an additional disk

inputs: {}
resources:
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      name: demo-machine
      cpuCount: 1
      totalMemoryMB: 1024
      imageRef: 'https://bintray.com/vmware/photon/download_file?file_path=2.0%2FRC%2Fova%2Fphoton-custom-hw11-2.0-31bb961.ova'
  storage:
    disks:
      - name: DISK_001
        capacityGb: 4
        provisioningType: thin

Create a vSphere Storage Resource

Table 3. Basic vSphere Storage Resource

Example of...

Sample Blueprint YAML

YAML code for a vSphere machine with a storage resource

inputs: {}
resources:
  demo-vsphere-disk-001:
    type: Cloud.vSphere.Disk
    properties:
        name: DISK_001
        type: 'HDD'
        capacityGb: 10
        dataStore: 'datastore-01'
        provisioningType: thick

Create a vSphere Resource and Attach a Disk

Table 4. Basic vSphere Machine Resource With Attached Disk

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource with an attached a disk

inputs: {}
resources:
  demo-vsphere-disk-001:
    type: Cloud.vSphere.Disk
    properties:
      name: DISK_001
      type: HDD
      capacityGb: 10
      dataStore: 'datastore-01'
      provisioningType: thin
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      name: demo-machine
      cpuCount: 2
      totalMemoryMB: 2048
      imageRef: >-
        https://bintray.com/vmware/photon/download_file?file_path=2.0%2FRC%2Fova%2Fphoton-custom-hw11-2.0-31bb961.ova
      attachedDisks:
        - source: '${demo-vsphere-disk-001.id}'

Create a vSphere Resource in a Specific Folder in vCenter

Table 5. Basic vSphere Machine Resource In A Specific Folder

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource in a named folder in vCenter

inputs: {}
resources:
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      name: demo-machine
      cpuCount: 2
      totalMemoryMB: 1024
      imageRef: ubuntu
      resourceGroupName: 'myFolder'

Create a vSphere Resource with Multiple NICs

Table 6. Basic vSphere Machine Resource With Multiple NICs

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource with multiple NICs

inputs: {}
resources:
  demo-machine:
    type: Cloud.Machine
    properties:
      image: ubuntu
      flavor: small
      networks:
        - name: '${network-01.name}'
          deviceIndex: 0
        - name: '${network-02.name}'
          deviceIndex: 1
  network-01:
    type: Cloud.vSphere.Network
    properties:
      name: network-01
  network-02:
    type: Cloud.vSphere.Network
    properties:
      name: network-02

Create a vSphere Resource from a Snapshot Image

Table 7. Basic vSphere Machine Resource With Snapshot Image

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource from a snapshot image

inputs: {}
resources:
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      imageRef: 'demo-machine/snapshot-01'
      cpuCount: 1
      totalMemoryMB: 1024

Create a vSphere Resource and Attach a Tag in vCenter

Table 8. Basic vSphere Machine Resource With Tag

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource with a tag

inputs: {}
resources:
  demo-machine:
    type: Cloud.Machine
    properties:
      flavor: small
      image: ubuntu
      tags:
        - key: env
          value: demo

Create a vSphere Resource with a Customization Spec

Table 9. Basic vSphere Machine Resource With Customization Specification

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine component resource

inputs: {}
resources:
  demo-machine:
      type: Cloud.vSphere.Machine
      properties:
        name: demo-machine
        image: ubuntu
        flavor: small
        customizationSpec: Linux

Create a vSphere Resource with Remote Access

Table 10. Basic vSphere Machine Resource With Remote Access

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource with remote access
inputs:
  username:
    type: string
    title: Username
    description: Username
    default: testUser
  password:
    type: string
    title: Password
    default: VMware@123
    encrypted: true
    description: Password for the given username
resources:
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      flavor: small
      imageRef: >-
        https://cloud-images.ubuntu.com/releases/16.04/release-20170307/ubuntu-16.04-server-cloudimg-amd64.ova
      cloudConfig: |
        ssh_pwauth: yes
        chpasswd:
          list: |
            ${input.username}:${input.password}
          expire: false
        users:
          - default
          - name: ${input.username}
            lock_passwd: false
            sudo: ['ALL=(ALL) NOPASSWD:ALL']
            groups: [wheel, sudo, admin]
            shell: '/bin/bash'
        runcmd:
          - echo "Defaults:${input.username}  !requiretty" >> /etc/sudoers.d/${input.username}

Create a vSphere Resource with a Static IP Address

Table 11. Basic vSphere Machine Resource With Static IP Address

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource with static IP address

inputs: {}
resources:
  demo-network:
    type: Cloud.vSphere.Network
    properties:
      name: demo-network
  demo-machine:
    type: Cloud.vSphere.Machine
    properties:
      image: ubuntu
      flavor: small
      networks:
        - name: demo-network
          assignment: static

Create vSphere Resources Definition For Wordpress Use Case

A cloud-agnostic version of the Wordpress use case is illustrated in the The WordPress Use Case workflow.

Table 12. Basic vSphere Resources Definition for Wordpress Use Case

Example of...

Sample Blueprint YAML

YAML code for a basic vSphere machine resource for WordPress Use Case 4

name: vSphereStorageUC4
iteration: 1
description: 'Complete vSphere-based Wordpress App with LB, Storage'
inputs:
  webTierCpu:
    type: integer
    minimum: 2
    default: 2
    maximum: 5
    title: Web Server CPU Count
    description: The number of CPUs for the Web nodes
  webTierMemory:
    type: integer
    minimum: 1024
    default: 1024
    maximum: 4096
    title: Web Server Memory (MB)
    description: The amount of memory for the Web nodes
  dbTierCpu:
    type: integer
    minimum: 2
    default: 2
    maximum: 5
    title: DB Server CPU Count
    description: The number of CPUs for the DB node
  dbTierMemory:
    type: integer
    minimum: 1024
    default: 1024
    maximum: 4096
    title: DB Server Memory (MB)
    description: The amount of memory for the DB node
resources:
  Cloud_vSphere_EXT_Disk:
    type: Cloud.vSphere.Disk
    properties:
      capacityGb: 8
      name: External_DB_Disk
  WebTier:
    type: Cloud.vSphere.Machine
    properties:
      cpuCount: '${input.webTierCpu}'
      totalMemoryMB: '${input.webTierMemory}'
      imageRef: >-
        https://bintray.com/vmware/photon/download_file?file_path=2.0%2FRC%2Fova%2Fphoton-custom-hw11-2.0-31bb961.ova
      count: 3
      cloudConfig: |
        #cloud-config
        hostname: wordpress-web
        chpasswd:
          list: |
            ubuntu:VMware1!
          expire: False
        users:
          - name: ubuntu
            passwd: "$1$Lg35t2vk$MIw6mB5VSuZsztttRGlJe0"
            lock-passwd: False
            groups: sudo
            shell: /bin/bash
            sudo: ['ALL=(ALL) NOPASSWD:ALL']
        repo_update: true
        repo_upgrade: all
        packages:
          - apache2
          - php
          - php-mysql
          - libapache2-mod-php
          - php-mcrypt
          - mysql-client
        runcmd:
          - touch /etc/network/interfaces.d/ens33.cfg
          - echo 'auto ens33 \r\niface ens33 inet dhcp' >> /etc/network/interfaces.d/ens33.cfg
          - /sbin/ifup ens33
          - route add default gw 192.168.209.1 ens33
          - mkdir -p /var/www/html/mywordpresssite && cd /var/www/html && wget https://wordpress.org/latest.tar.gz && tar -xzf /var/www/html/latest.tar.gz -C /var/www/html/mywordpresssite --strip-components 1
          - for i in {1..5}; do mysql --connect-timeout=3 -h ${DBTier.address} -u root -pmysqlpassword -e "SHOW STATUS;" && break || sleep 15; done
          - mysql -u root -pmysqlpassword -h ${DBTier.address} -e "create database wordpress_blog;"
          - mv /var/www/html/mywordpresssite/wp-config-sample.php /var/www/html/mywordpresssite/wp-config.php
          - sed -i -e s/"define('DB_NAME', 'database_name_here');"/"define('DB_NAME', 'wordpress_blog');"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define('DB_USER', 'username_here');"/"define('DB_USER', 'root');"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define('DB_PASSWORD', 'password_here');"/"define('DB_PASSWORD', 'mysqlpassword');"/ /var/www/html/mywordpresssite/wp-config.php && sed -i -e s/"define('DB_HOST', 'localhost');"/"define('DB_HOST', '${DBTier.address}');"/ /var/www/html/mywordpresssite/wp-config.php
          - service apache2 reload
      networks:
        - name: '${Cloud_vSphere_Network_1.name}'
  DBTier:
    type: Cloud.vSphere.Machine
    properties:
      cpuCount: '${input.dbTierCpu}'
      totalMemoryMB: '${input.dbTierMemory}'
      imageRef: https://bintray.com/vmware/photon/download_file?file_path=2.0%2FRC%2Fova%2Fphoton-custom-hw11-2.0-31bb961.ova
      cloudConfig: |
        #cloud-config
        hostname: wordpress-mysql.sqa.local
        users:
          - name: ubuntu
            passwd: "$1$Lg35t2vk$MIw6mB5VSuZsztttRGlJe0"
            lock-passwd: False
            groups: sudo
            shell: /bin/bash
            sudo: ['ALL=(ALL) NOPASSWD:ALL']
        chpasswd:
          list: |
            ubuntu:VMware1!
          expire: False
        repo_update: true
        repo_upgrade: all
        packages:
         - mysql-server
        runcmd:
         - sed -e '/bind-address/ s/^#*/#/' -i /etc/mysql/mysql.conf.d/mysqld.cnf
         - service mysql restart
         - mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mysqlpassword';"
         - mysql -e "FLUSH PRIVILEGES;"
      attachedDisks:
        - source: '${Cloud_vSphere_EXT_Disk.id}'
      networks:
        - name: '${Cloud_vSphere_Network_1.name}'
  Cloud_vSphere_Network_1:
    type: Cloud.vSphere.Network
    properties:
      name: 'network-01'