github.com/terramate-io/tf@v0.0.0-20230830114523-fce866b4dfcd/addrs/move_endpoint_kind.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package addrs
     5  
     6  import "fmt"
     7  
     8  // MoveEndpointKind represents the different kinds of object that a movable
     9  // address can refer to.
    10  type MoveEndpointKind rune
    11  
    12  //go:generate go run golang.org/x/tools/cmd/stringer -type MoveEndpointKind
    13  
    14  const (
    15  	// MoveEndpointModule indicates that a move endpoint either refers to
    16  	// an individual module instance or to all instances of a particular
    17  	// module call.
    18  	MoveEndpointModule MoveEndpointKind = 'M'
    19  
    20  	// MoveEndpointResource indicates that a move endpoint either refers to
    21  	// an individual resource instance or to all instances of a particular
    22  	// resource.
    23  	MoveEndpointResource MoveEndpointKind = 'R'
    24  )
    25  
    26  func absMoveableEndpointKind(addr AbsMoveable) MoveEndpointKind {
    27  	switch addr := addr.(type) {
    28  	case ModuleInstance, AbsModuleCall:
    29  		return MoveEndpointModule
    30  	case AbsResourceInstance, AbsResource:
    31  		return MoveEndpointResource
    32  	default:
    33  		// The above should be exhaustive for all AbsMoveable types.
    34  		panic(fmt.Sprintf("unsupported address type %T", addr))
    35  	}
    36  }