-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,513 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Packages for Terraform Language | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package addrs | ||
|
||
// CountAttr is the address of an attribute of the "count" object in | ||
// the interpolation scope, like "count.index". | ||
type CountAttr struct { | ||
referenceable | ||
Name string | ||
} | ||
|
||
func (ca CountAttr) String() string { | ||
return "count." + ca.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package addrs | ||
|
||
// TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package addrs | ||
|
||
// ForEachAttr is the address of an attribute referencing the current "for_each" object in | ||
// the interpolation scope, addressed using the "each" keyword, ex. "each.key" and "each.value" | ||
type ForEachAttr struct { | ||
referenceable | ||
Name string | ||
} | ||
|
||
func (f ForEachAttr) String() string { | ||
return "each." + f.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package addrs | ||
|
||
// InputVariable is the address of an input variable. | ||
type InputVariable struct { | ||
referenceable | ||
Name string | ||
} | ||
|
||
func (v InputVariable) String() string { | ||
return "var." + v.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package addrs | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/zclconf/go-cty/cty" | ||
"github.com/zclconf/go-cty/cty/gocty" | ||
) | ||
|
||
// InstanceKey represents the key of an instance within an object that | ||
// contains multiple instances due to using "count" or "for_each" arguments | ||
// in configuration. | ||
// | ||
// IntKey and StringKey are the two implementations of this type. No other | ||
// implementations are allowed. The single instance of an object that _isn't_ | ||
// using "count" or "for_each" is represented by NoKey, which is a nil | ||
// InstanceKey. | ||
type InstanceKey interface { | ||
instanceKeySigil() | ||
String() string | ||
|
||
// Value returns the cty.Value of the appropriate type for the InstanceKey | ||
// value. | ||
Value() cty.Value | ||
} | ||
|
||
// ParseInstanceKey returns the instance key corresponding to the given value, | ||
// which must be known and non-null. | ||
// | ||
// If an unknown or null value is provided then this function will panic. This | ||
// function is intended to deal with the values that would naturally be found | ||
// in a hcl.TraverseIndex, which (when parsed from source, at least) can never | ||
// contain unknown or null values. | ||
func ParseInstanceKey(key cty.Value) (InstanceKey, error) { | ||
switch key.Type() { | ||
case cty.String: | ||
return StringKey(key.AsString()), nil | ||
case cty.Number: | ||
var idx int | ||
err := gocty.FromCtyValue(key, &idx) | ||
return IntKey(idx), err | ||
default: | ||
return NoKey, fmt.Errorf("either a string or an integer is required") | ||
} | ||
} | ||
|
||
// NoKey represents the absense of an InstanceKey, for the single instance | ||
// of a configuration object that does not use "count" or "for_each" at all. | ||
var NoKey InstanceKey | ||
|
||
// IntKey is the InstanceKey representation representing integer indices, as | ||
// used when the "count" argument is specified or if for_each is used with | ||
// a sequence type. | ||
type IntKey int | ||
|
||
func (k IntKey) instanceKeySigil() { | ||
} | ||
|
||
func (k IntKey) String() string { | ||
return fmt.Sprintf("[%d]", int(k)) | ||
} | ||
|
||
func (k IntKey) Value() cty.Value { | ||
return cty.NumberIntVal(int64(k)) | ||
} | ||
|
||
// StringKey is the InstanceKey representation representing string indices, as | ||
// used when the "for_each" argument is specified with a map or object type. | ||
type StringKey string | ||
|
||
func (k StringKey) instanceKeySigil() { | ||
} | ||
|
||
func (k StringKey) String() string { | ||
// FIXME: This isn't _quite_ right because Go's quoted string syntax is | ||
// slightly different than HCL's, but we'll accept it for now. | ||
return fmt.Sprintf("[%q]", string(k)) | ||
} | ||
|
||
func (k StringKey) Value() cty.Value { | ||
return cty.StringVal(string(k)) | ||
} | ||
|
||
// InstanceKeyType represents the different types of instance key that are | ||
// supported. Usually it is sufficient to simply type-assert an InstanceKey | ||
// value to either IntKey or StringKey, but this type and its values can be | ||
// used to represent the types themselves, rather than specific values | ||
// of those types. | ||
type InstanceKeyType rune | ||
|
||
const ( | ||
NoKeyType InstanceKeyType = 0 | ||
IntKeyType InstanceKeyType = 'I' | ||
StringKeyType InstanceKeyType = 'S' | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package addrs | ||
|
||
// LocalValue is the address of a local value. | ||
type LocalValue struct { | ||
referenceable | ||
Name string | ||
} | ||
|
||
func (v LocalValue) String() string { | ||
return "local." + v.Name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package addrs | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// ModuleCall is the address of a call from the current module to a child | ||
// module. | ||
type ModuleCall struct { | ||
referenceable | ||
Name string | ||
} | ||
|
||
func (c ModuleCall) String() string { | ||
return "module." + c.Name | ||
} | ||
|
||
// ModuleCallInstance is the address of one instance of a module created from | ||
// a module call, which might create multiple instances using "count" or | ||
// "for_each" arguments. | ||
type ModuleCallInstance struct { | ||
referenceable | ||
Call ModuleCall | ||
Key InstanceKey | ||
} | ||
|
||
func (c ModuleCallInstance) String() string { | ||
if c.Key == NoKey { | ||
return c.Call.String() | ||
} | ||
return fmt.Sprintf("module.%s%s", c.Call.Name, c.Key) | ||
} | ||
|
||
// ModuleCallInstanceOutput is the address of a particular named output produced by | ||
// an instance of a module call. | ||
type ModuleCallInstanceOutput struct { | ||
referenceable | ||
Call ModuleCallInstance | ||
Name string | ||
} | ||
|
||
func (co ModuleCallInstanceOutput) String() string { | ||
return fmt.Sprintf("%s.%s", co.Call.String(), co.Name) | ||
} |
Oops, something went wrong.