func resourceCloudStackHost()

in cloudstack/resource_cloudstack_host.go [34:152]


func resourceCloudStackHost() *schema.Resource {
	return &schema.Resource{
		Read:   resourceCloudStackHostRead,
		Update: resourceCloudStackHostUpdate,
		Create: resourceCloudStackHostCreate,
		Delete: resourceCloudStackHostDelete,
		Schema: map[string]*schema.Schema{
			"hypervisor": {
				Type:     schema.TypeString,
				Required: true,
				ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
					validHypervisors := []string{"xenserver", "kvm", "vmware", "baremetal", "simulator"}

					sort.Strings(validHypervisors)

					if sort.SearchStrings(validHypervisors, v.(string)) >= len(validHypervisors) {
						errors = append(errors, fmt.Errorf("%q must be one of %v", k, validHypervisors))
					}
					return
				},
				ForceNew: true,
			},
			"pod_id": {
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"url": {
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"zone_id": {
				Type:     schema.TypeString,
				Required: true,
				ForceNew: true,
			},
			"cluster_id": {
				Type:     schema.TypeString,
				Optional: true,
				ForceNew: true,
				ConflictsWith: []string{
					"cluster_name",
				},
			},
			"cluster_name": {
				Type:     schema.TypeString,
				Optional: true,
				ForceNew: true,
				ConflictsWith: []string{
					"cluster_id",
				},
			},
			"host_tags": {
				Type:     schema.TypeList,
				Optional: true,
				Elem: &schema.Schema{
					Type: schema.TypeString,
				},
			},
			"username": {
				Type:     schema.TypeString,
				Optional: true,
			},
			"password": {
				Type:      schema.TypeString,
				Optional:  true,
				Sensitive: true,
			},
			"prevent_destroy": {
				Type:        schema.TypeBool,
				Description: "Prevent the host from being destroyed. This is useful when you want to avoid destroy the host in any change.",
				Optional:    true,
				Default:     false,
			},
			"force_destroy": {
				Type:        schema.TypeBool,
				Description: "Force the host to be destroyed.",
				Optional:    true,
				Default:     false,
			},
			"allocation_state": {
				Type:     schema.TypeString,
				Optional: true,
				Default:  "Enabled",
			},
			"state": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"resource_state": {
				Type:     schema.TypeString,
				Computed: true,
			},
			"name": {
				Type:     schema.TypeString,
				Computed: true,
			},
			// Creating a host can fail if the instance is still being created and Cloudsack
			// user is created during cloud-init. This timeout is used to wait for the host
			// to be created and Cloudstack user to be available.
			"create_timeout": {
				Type:        schema.TypeInt,
				Description: "Timeout in seconds to wait for the host to be created.",
				Optional:    true,
				Default:     300,
			},
			// Destroying a host will put it in Maintenance mode first. If the VMs are still
			// being migrated, the host will be in state PrepareForMaintenance. This timeout
			// is used to wait for the host to be in Maintenance state.
			"destroy_timeout": {
				Type:        schema.TypeInt,
				Description: "Timeout in seconds to wait for the host to be destroyed.",
				Optional:    true,
				Default:     300,
			},
		},
	}
}