2018-04-04 03:11:28 +02:00
|
|
|
package lang
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
|
|
"github.com/hashicorp/terraform/tfdiags"
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
|
|
|
)
|
|
|
|
|
|
|
|
type dataForTests struct {
|
2019-09-19 15:13:47 +02:00
|
|
|
CountAttrs map[string]cty.Value
|
|
|
|
ForEachAttrs map[string]cty.Value
|
|
|
|
Resources map[string]cty.Value
|
|
|
|
LocalValues map[string]cty.Value
|
|
|
|
Modules map[string]cty.Value
|
|
|
|
PathAttrs map[string]cty.Value
|
|
|
|
TerraformAttrs map[string]cty.Value
|
|
|
|
InputVariables map[string]cty.Value
|
2018-04-04 03:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ Data = &dataForTests{}
|
|
|
|
|
2018-11-21 02:25:05 +01:00
|
|
|
func (d *dataForTests) StaticValidateReferences(refs []*addrs.Reference, self addrs.Referenceable) tfdiags.Diagnostics {
|
|
|
|
return nil // does nothing in this stub implementation
|
|
|
|
}
|
|
|
|
|
2018-04-04 03:11:28 +02:00
|
|
|
func (d *dataForTests) GetCountAttr(addr addrs.CountAttr, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.CountAttrs[addr.Name], nil
|
|
|
|
}
|
|
|
|
|
2019-06-12 17:07:32 +02:00
|
|
|
func (d *dataForTests) GetForEachAttr(addr addrs.ForEachAttr, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.ForEachAttrs[addr.Name], nil
|
|
|
|
}
|
|
|
|
|
2019-09-19 15:13:47 +02:00
|
|
|
func (d *dataForTests) GetResource(addr addrs.Resource, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.Resources[addr.String()], nil
|
2018-04-04 03:11:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataForTests) GetInputVariable(addr addrs.InputVariable, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.InputVariables[addr.Name], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataForTests) GetLocalValue(addr addrs.LocalValue, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.LocalValues[addr.Name], nil
|
|
|
|
}
|
|
|
|
|
2020-04-12 16:43:41 +02:00
|
|
|
func (d *dataForTests) GetModule(addr addrs.ModuleCall, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
2018-04-04 03:11:28 +02:00
|
|
|
return d.Modules[addr.String()], nil
|
|
|
|
}
|
|
|
|
|
2020-03-20 17:18:48 +01:00
|
|
|
func (d *dataForTests) GetModuleInstanceOutput(addr addrs.AbsModuleCallOutput, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
2018-04-04 03:11:28 +02:00
|
|
|
// This will panic if the module object does not have the requested attribute
|
|
|
|
obj := d.Modules[addr.Call.String()]
|
|
|
|
return obj.GetAttr(addr.Name), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataForTests) GetPathAttr(addr addrs.PathAttr, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.PathAttrs[addr.Name], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dataForTests) GetTerraformAttr(addr addrs.TerraformAttr, rng tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics) {
|
|
|
|
return d.TerraformAttrs[addr.Name], nil
|
|
|
|
}
|