github.com/nevins-b/terraform@v0.3.8-0.20170215184714-bbae22007d5a/config/config_terraform.go (about)

     1  package config
     2  
     3  import (
     4  	"github.com/mitchellh/hashstructure"
     5  )
     6  
     7  // Terraform is the Terraform meta-configuration that can be present
     8  // in configuration files for configuring Terraform itself.
     9  type Terraform struct {
    10  	RequiredVersion string   `hcl:"required_version"` // Required Terraform version (constraint)
    11  	Backend         *Backend // See Backend struct docs
    12  }
    13  
    14  // Backend is the configuration for the "backend" to use with Terraform.
    15  // A backend is responsible for all major behavior of Terraform's core.
    16  // The abstraction layer above the core (the "backend") allows for behavior
    17  // such as remote operation.
    18  type Backend struct {
    19  	Type      string
    20  	RawConfig *RawConfig
    21  
    22  	// Hash is a unique hash code representing the original configuration
    23  	// of the backend. This won't be recomputed unless Rehash is called.
    24  	Hash uint64
    25  }
    26  
    27  // Hash returns a unique content hash for this backend's configuration
    28  // as a uint64 value.
    29  func (b *Backend) Rehash() uint64 {
    30  	// If we have no backend, the value is zero
    31  	if b == nil {
    32  		return 0
    33  	}
    34  
    35  	// Use hashstructure to hash only our type with the config.
    36  	code, err := hashstructure.Hash(map[string]interface{}{
    37  		"type":   b.Type,
    38  		"config": b.RawConfig.Raw,
    39  	}, nil)
    40  
    41  	// This should never happen since we have just some basic primitives
    42  	// so panic if there is an error.
    43  	if err != nil {
    44  		panic(err)
    45  	}
    46  
    47  	return code
    48  }