コード例 #1
0
// expandHealthCheckConfig expands the Check block.
func expandHealthCheckConfig(data interface{}) (*spotinst.HealthCheckConfig, error) {
	if list := data.(*schema.Set).List(); len(list) != 1 {
		return nil, fmt.Errorf("Only a single check block is expected")
	} else {
		m := list[0].(map[string]interface{})
		check := &spotinst.HealthCheckConfig{}

		if v, ok := m["protocol"].(string); ok && v != "" {
			check.Protocol = spotinst.String(v)
		}

		if v, ok := m["endpoint"].(string); ok && v != "" {
			check.Endpoint = spotinst.String(v)
		}

		if v, ok := m["port"].(int); ok && v >= 0 {
			check.Port = spotinst.Int(v)
		}

		if v, ok := m["interval"].(int); ok && v >= 0 {
			check.Interval = spotinst.Int(v)
		}

		if v, ok := m["timeout"].(int); ok && v >= 0 {
			check.Timeout = spotinst.Int(v)
		}

		log.Printf("[DEBUG] HealthCheck check configuration: %#v\n", check)
		return check, nil
	}
}
コード例 #2
0
// expandHealthCheckThreshold expands the Threshold block.
func expandHealthCheckThreshold(data interface{}) (*spotinst.HealthCheckThreshold, error) {
	if list := data.(*schema.Set).List(); len(list) != 1 {
		return nil, fmt.Errorf("Only a single threshold block is expected")
	} else {
		m := list[0].(map[string]interface{})
		threshold := &spotinst.HealthCheckThreshold{}

		if v, ok := m["healthy"].(int); ok && v >= 0 {
			threshold.Healthy = spotinst.Int(v)
		}

		if v, ok := m["unhealthy"].(int); ok && v >= 0 {
			threshold.Unhealthy = spotinst.Int(v)
		}

		log.Printf("[DEBUG] HealthCheck threshold configuration: %#v\n", threshold)
		return threshold, nil
	}
}
コード例 #3
0
// expandHealthCheckProxy expands the Proxy block.
func expandHealthCheckProxy(data interface{}) (*spotinst.HealthCheckProxy, error) {
	if list := data.(*schema.Set).List(); len(list) != 1 {
		return nil, fmt.Errorf("Only a single proxy block is expected")
	} else {
		m := list[0].(map[string]interface{})
		proxy := &spotinst.HealthCheckProxy{}

		if v, ok := m["addr"].(string); ok && v != "" {
			proxy.Addr = spotinst.String(v)
		}

		if v, ok := m["port"].(int); ok && v > 0 {
			proxy.Port = spotinst.Int(v)
		}

		log.Printf("[DEBUG] HealthCheck proxy configuration: %#v\n", proxy)
		return proxy, nil
	}
}