github.com/jdextraze/terraform@v0.6.17-0.20160511153921-e33847c8a8af/command/state_meta.go (about)

     1  package command
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  // StateMeta is the meta struct that should be embedded in state subcommands.
    10  type StateMeta struct{}
    11  
    12  // filterInstance filters a single instance out of filter results.
    13  func (c *StateMeta) filterInstance(rs []*terraform.StateFilterResult) (*terraform.StateFilterResult, error) {
    14  	var result *terraform.StateFilterResult
    15  	for _, r := range rs {
    16  		if _, ok := r.Value.(*terraform.InstanceState); !ok {
    17  			continue
    18  		}
    19  
    20  		if result != nil {
    21  			return nil, errors.New(errStateMultiple)
    22  		}
    23  
    24  		result = r
    25  	}
    26  
    27  	return result, nil
    28  }
    29  
    30  const errStateMultiple = `Multiple instances found for the given pattern!
    31  
    32  This command requires that the pattern match exactly one instance
    33  of a resource. To view the matched instances, use "terraform state list".
    34  Please modify the pattern to match only a single instance.`