From fca07d1a618276c7268b4c1d5e713c6e42d4bb00 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 6 Apr 2018 18:45:16 -0700 Subject: [PATCH] addrs: AbsProviderConfig type Fitting with the usual naming scheme, this is the combination of a module instance address and a provider config. --- addrs/provider_config.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/addrs/provider_config.go b/addrs/provider_config.go index dfca8c9b1..57d4db6e1 100644 --- a/addrs/provider_config.go +++ b/addrs/provider_config.go @@ -1,5 +1,9 @@ package addrs +import ( + "fmt" +) + // ProviderConfig is the address of a provider configuration. type ProviderConfig struct { Type string @@ -8,3 +12,31 @@ type ProviderConfig struct { // configuration this address refers to. Alias string } + +// Absolute returns an AbsProviderConfig from the receiver and the given module +// instance address. +func (pc ProviderConfig) Absolute(module ModuleInstance) AbsProviderConfig { + return AbsProviderConfig{ + Module: module, + ProviderConfig: pc, + } +} + +func (pc ProviderConfig) String() string { + if pc.Alias != "" { + return fmt.Sprintf("provider.%s.%s", pc.Type, pc.Alias) + } + + return "provider." + pc.Type +} + +// AbsProviderConfig is the absolute address of a provider configuration +// within a particular module instance. +type AbsProviderConfig struct { + Module ModuleInstance + ProviderConfig ProviderConfig +} + +func (pc AbsProviderConfig) String() string { + return fmt.Sprintf("%s.%s", pc.Module.String(), pc.ProviderConfig.String()) +}