github.com/paultyng/terraform@v0.6.11-0.20180227224804-66ff8f8bed40/configs/configload/source_addr.go (about)

     1  package configload
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/hashicorp/go-getter"
     7  
     8  	"github.com/hashicorp/terraform/registry/regsrc"
     9  )
    10  
    11  var localSourcePrefixes = []string{
    12  	"./",
    13  	"../",
    14  	".\\",
    15  	"..\\",
    16  }
    17  
    18  func isLocalSourceAddr(addr string) bool {
    19  	for _, prefix := range localSourcePrefixes {
    20  		if strings.HasPrefix(addr, prefix) {
    21  			return true
    22  		}
    23  	}
    24  	return false
    25  }
    26  
    27  func isRegistrySourceAddr(addr string) bool {
    28  	_, err := regsrc.ParseModuleSource(addr)
    29  	return err == nil
    30  }
    31  
    32  // splitAddrSubdir splits the given address (which is assumed to be a
    33  // registry address or go-getter-style address) into a package portion
    34  // and a sub-directory portion.
    35  //
    36  // The package portion defines what should be downloaded and then the
    37  // sub-directory portion, if present, specifies a sub-directory within
    38  // the downloaded object (an archive, VCS repository, etc) that contains
    39  // the module's configuration files.
    40  //
    41  // The subDir portion will be returned as empty if no subdir separator
    42  // ("//") is present in the address.
    43  func splitAddrSubdir(addr string) (packageAddr, subDir string) {
    44  	return getter.SourceDirSubdir(addr)
    45  }