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

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package addrs
     5  
     6  import (
     7  	tfaddr "github.com/hashicorp/terraform-registry-address"
     8  )
     9  
    10  // A ModulePackage represents a physical location where Terraform can retrieve
    11  // a module package, which is an archive, repository, or other similar
    12  // container which delivers the source code for one or more Terraform modules.
    13  //
    14  // A ModulePackage is a string in go-getter's address syntax. By convention,
    15  // we use ModulePackage-typed values only for the result of successfully
    16  // running the go-getter "detectors", which produces an address string which
    17  // includes an explicit installation method prefix along with an address
    18  // string in the format expected by that installation method.
    19  //
    20  // Note that although the "detector" phase of go-getter does do some simple
    21  // normalization in certain cases, it isn't generally possible to compare
    22  // two ModulePackage values to decide if they refer to the same package. Two
    23  // equal ModulePackage values represent the same package, but there might be
    24  // other non-equal ModulePackage values that also refer to that package, and
    25  // there is no reliable way to determine that.
    26  //
    27  // Don't convert a user-provided string directly to ModulePackage. Instead,
    28  // use ParseModuleSource with a remote module address and then access the
    29  // ModulePackage value from the result, making sure to also handle the
    30  // selected subdirectory if any. You should convert directly to ModulePackage
    31  // only for a string that is hard-coded into the program (e.g. in a unit test)
    32  // where you've ensured that it's already in the expected syntax.
    33  type ModulePackage string
    34  
    35  func (p ModulePackage) String() string {
    36  	return string(p)
    37  }
    38  
    39  // A ModuleRegistryPackage is an extra indirection over a ModulePackage where
    40  // we use a module registry to translate a more symbolic address (and
    41  // associated version constraint given out of band) into a physical source
    42  // location.
    43  //
    44  // ModuleRegistryPackage is distinct from ModulePackage because they have
    45  // disjoint use-cases: registry package addresses are only used to query a
    46  // registry in order to find a real module package address. These being
    47  // distinct is intended to help future maintainers more easily follow the
    48  // series of steps in the module installer, with the help of the type checker.
    49  type ModuleRegistryPackage = tfaddr.ModulePackage