From 119c80d5e23c3778f05bda48f865958770208f29 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 4 May 2018 13:22:02 -0700 Subject: [PATCH] addrs: ModuleInstance methods for building AbsProviderConfig These helpers, similar to other such methods on ModuleInstance, are useful for programmatically constructing provider config addresses, particularly in tests where this is more straightforward than parsing from strings. --- addrs/provider_config.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/addrs/provider_config.go b/addrs/provider_config.go index e10090569..2b03a35ef 100644 --- a/addrs/provider_config.go +++ b/addrs/provider_config.go @@ -174,6 +174,29 @@ func ParseAbsProviderConfig(traversal hcl.Traversal) (AbsProviderConfig, tfdiags return ret, diags } +// ProviderConfigDefault returns the address of the default provider config +// of the given type inside the recieving module instance. +func (m ModuleInstance) ProviderConfigDefault(name string) AbsProviderConfig { + return AbsProviderConfig{ + Module: m, + ProviderConfig: ProviderConfig{ + Type: name, + }, + } +} + +// ProviderConfigAliased returns the address of an aliased provider config +// of with given type and alias inside the recieving module instance. +func (m ModuleInstance) ProviderConfigAliased(name, alias string) AbsProviderConfig { + return AbsProviderConfig{ + Module: m, + ProviderConfig: ProviderConfig{ + Type: name, + Alias: alias, + }, + } +} + // Inherited returns an address that the receiving configuration address might // inherit from in a parent module. The second bool return value indicates if // such inheritance is possible, and thus whether the returned address is valid.