drivers/azure/azure.go
func (d *Driver) PreCreateCheck() (err error) {
	if d.CustomDataFile != "" {
		if _, err := os.Stat(d.CustomDataFile); os.IsNotExist(err) {
			return fmt.Errorf("custom-data file %s could not be found", d.CustomDataFile)
		}
	}

	c, err := d.newAzureClient()
	if err != nil {
		return err
	}

	// Register used resource providers with current Azure subscription.
	if err := c.RegisterResourceProviders(
		"Microsoft.Compute",
		"Microsoft.Network",
		"Microsoft.Storage"); err != nil {
		return err
	}

	// Validate if firewall rules can be read correctly
	d.ctx.FirewallRules, err = d.getSecurityRules(d.OpenPorts)
	if err != nil {
		return err
	}

	// Check if virtual machine exists. An existing virtual machine cannot be updated.
	log.Debug("Checking if Virtual Machine already exists.")
	if exists, err := c.VirtualMachineExists(d.ResourceGroup, d.naming().VM()); err != nil {
		return err
	} else if exists {
		return fmt.Errorf("Virtual Machine with name %s already exists in resource group %q", d.naming().VM(), d.ResourceGroup)
	}

	// NOTE(ahmetalpbalkan) we could have done more checks here but Azure often
	// returns meaningful error messages and it would be repeating the backend
	// logic on the client side. Some examples:
	//   - Deployment of a machine to an existing Virtual Network fails if
	//     virtual network is in a different region.
	//   - Changing IP Address space of a subnet would fail if there are machines
	//     running in the Virtual Network.
	log.Info("Completed machine pre-create checks.")
	return nil
}
func (d *Driver) PreCreateCheck() (err error) {
	if d.CustomDataFile != "" {
		if _, err := os.Stat(d.CustomDataFile); os.IsNotExist(err) {
			return fmt.Errorf("custom-data file %s could not be found", d.CustomDataFile)
		}
	}

	c, err := d.newAzureClient()
	if err != nil {
		return err
	}

	// Register used resource providers with current Azure subscription.
	if err := c.RegisterResourceProviders(
		"Microsoft.Compute",
		"Microsoft.Network",
		"Microsoft.Storage"); err != nil {
		return err
	}

	// Validate if firewall rules can be read correctly
	d.ctx.FirewallRules, err = d.getSecurityRules(d.OpenPorts)
	if err != nil {
		return err
	}

	// Check if virtual machine exists. An existing virtual machine cannot be updated.
	log.Debug("Checking if Virtual Machine already exists.")
	if exists, err := c.VirtualMachineExists(d.ResourceGroup, d.naming().VM()); err != nil {
		return err
	} else if exists {
		return fmt.Errorf("Virtual Machine with name %s already exists in resource group %q", d.naming().VM(), d.ResourceGroup)
	}

	// NOTE(ahmetalpbalkan) we could have done more checks here but Azure often
	// returns meaningful error messages and it would be repeating the backend
	// logic on the client side. Some examples:
	//   - Deployment of a machine to an existing Virtual Network fails if
	//     virtual network is in a different region.
	//   - Changing IP Address space of a subnet would fail if there are machines
	//     running in the Virtual Network.
	log.Info("Completed machine pre-create checks.")
	return nil
}
func ( d * Driver ) PreCreateCheck ( ) ( err error ) { if d . CustomDataFile != " " { if _ , err := os . Stat ( d . CustomDataFile ) ; os . IsNotExist ( err ) { return fmt . Errorf ( " " , d . CustomDataFile ) } } c , err := d . newAzureClient ( ) if err != nil { return err } // Register used resource providers with current Azure subscription. if err := c . RegisterResourceProviders ( " " , " " , " " ) ; err != nil { return err } // Validate if firewall rules can be read correctly d . ctx . FirewallRules , err = d . getSecurityRules ( d . OpenPorts ) if err != nil { return err } // Check if virtual machine exists. An existing virtual machine cannot be updated. log . Debug ( " " ) if exists , err := c . VirtualMachineExists ( d . ResourceGroup , d . naming ( ) . VM ( ) ) ; err != nil { return err } else if exists { return fmt . Errorf ( " " , d . naming ( ) . VM ( ) , d . ResourceGroup ) } // NOTE(ahmetalpbalkan) we could have done more checks here but Azure often // returns meaningful error messages and it would be repeating the backend // logic on the client side. Some examples: //   - Deployment of a machine to an existing Virtual Network fails if //     virtual network is in a different region. //   - Changing IP Address space of a subnet would fail if there are machines //     running in the Virtual Network. log . Info ( " " ) return nil }
// PreCreateCheck validates if driver values are valid to create the machine.
PreCreateCheck validates if driver values are valid to create the machine .