github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/metric_cluster.go (about)

     1  package circonus
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/circonus-labs/circonus-gometrics/api"
     7  	"github.com/hashicorp/errwrap"
     8  )
     9  
    10  type circonusMetricCluster struct {
    11  	api.MetricCluster
    12  }
    13  
    14  func newMetricCluster() circonusMetricCluster {
    15  	return circonusMetricCluster{
    16  		MetricCluster: api.MetricCluster{},
    17  	}
    18  }
    19  
    20  func loadMetricCluster(ctxt *providerContext, cid api.CIDType) (circonusMetricCluster, error) {
    21  	var mc circonusMetricCluster
    22  	cmc, err := ctxt.client.FetchMetricCluster(cid, "")
    23  	if err != nil {
    24  		return circonusMetricCluster{}, err
    25  	}
    26  	mc.MetricCluster = *cmc
    27  
    28  	return mc, nil
    29  }
    30  
    31  func (mc *circonusMetricCluster) Create(ctxt *providerContext) error {
    32  	cmc, err := ctxt.client.CreateMetricCluster(&mc.MetricCluster)
    33  	if err != nil {
    34  		return err
    35  	}
    36  
    37  	mc.CID = cmc.CID
    38  
    39  	return nil
    40  }
    41  
    42  func (mc *circonusMetricCluster) Update(ctxt *providerContext) error {
    43  	_, err := ctxt.client.UpdateMetricCluster(&mc.MetricCluster)
    44  	if err != nil {
    45  		return errwrap.Wrapf(fmt.Sprintf("Unable to update stream group %s: {{err}}", mc.CID), err)
    46  	}
    47  
    48  	return nil
    49  }
    50  
    51  func (mc *circonusMetricCluster) Validate() error {
    52  	if len(mc.Queries) < 1 {
    53  		return fmt.Errorf("there must be at least one stream group query present")
    54  	}
    55  
    56  	return nil
    57  }