mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 07:26:26 -06:00
terraform: ResourceConfig
This commit is contained in:
parent
fd39728cbb
commit
7e421dd89b
@ -8,7 +8,7 @@ type ResourceProvider interface {
|
||||
// given. This is useful for setting things like access keys.
|
||||
//
|
||||
// Configure returns an error if it occurred.
|
||||
Configure(config map[string]interface{}) error
|
||||
Configure(*ResourceConfig) error
|
||||
|
||||
// Resources returns all the available resource types that this provider
|
||||
// knows how to manage.
|
||||
@ -25,7 +25,14 @@ type ResourceProvider interface {
|
||||
// a diff.
|
||||
Diff(
|
||||
*ResourceState,
|
||||
map[string]interface{}) (*ResourceDiff, error)
|
||||
*ResourceConfig) (*ResourceDiff, error)
|
||||
}
|
||||
|
||||
// ResourceConfig holds the configuration given for a resource. This is
|
||||
// done instead of a raw `map[string]interface{}` type so that rich
|
||||
// methods can be added to it to make dealing with it easier.
|
||||
type ResourceConfig struct {
|
||||
Raw map[string]interface{}
|
||||
}
|
||||
|
||||
// ResourceType is a type of resource that a resource provider can manage.
|
||||
|
@ -7,19 +7,19 @@ type MockResourceProvider struct {
|
||||
Meta interface{}
|
||||
|
||||
ConfigureCalled bool
|
||||
ConfigureConfig map[string]interface{}
|
||||
ConfigureConfig *ResourceConfig
|
||||
ConfigureReturnError error
|
||||
DiffCalled bool
|
||||
DiffState *ResourceState
|
||||
DiffDesired map[string]interface{}
|
||||
DiffFn func(*ResourceState, map[string]interface{}) (*ResourceDiff, error)
|
||||
DiffDesired *ResourceConfig
|
||||
DiffFn func(*ResourceState, *ResourceConfig) (*ResourceDiff, error)
|
||||
DiffReturn *ResourceDiff
|
||||
DiffReturnError error
|
||||
ResourcesCalled bool
|
||||
ResourcesReturn []ResourceType
|
||||
}
|
||||
|
||||
func (p *MockResourceProvider) Configure(c map[string]interface{}) error {
|
||||
func (p *MockResourceProvider) Configure(c *ResourceConfig) error {
|
||||
p.ConfigureCalled = true
|
||||
p.ConfigureConfig = c
|
||||
return p.ConfigureReturnError
|
||||
@ -27,7 +27,7 @@ func (p *MockResourceProvider) Configure(c map[string]interface{}) error {
|
||||
|
||||
func (p *MockResourceProvider) Diff(
|
||||
state *ResourceState,
|
||||
desired map[string]interface{}) (*ResourceDiff, error) {
|
||||
desired *ResourceConfig) (*ResourceDiff, error) {
|
||||
p.DiffCalled = true
|
||||
p.DiffState = state
|
||||
p.DiffDesired = desired
|
||||
|
@ -150,7 +150,9 @@ func (t *Terraform) diffWalkFn(
|
||||
}
|
||||
l.RUnlock()
|
||||
|
||||
diff, err := p.Provider.Diff(rs, r.RawConfig.Config())
|
||||
diff, err := p.Provider.Diff(rs, &ResourceConfig{
|
||||
Raw: r.RawConfig.Config(),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -188,7 +190,9 @@ func (t *terraformProvider) init(vars map[string]string) (err error) {
|
||||
c = t.Config.RawConfig.Config()
|
||||
}
|
||||
|
||||
err = t.Provider.Configure(c)
|
||||
err = t.Provider.Configure(&ResourceConfig{
|
||||
Raw: c,
|
||||
})
|
||||
})
|
||||
|
||||
return
|
||||
|
@ -248,7 +248,7 @@ func TestTerraformDiff_providerInit(t *testing.T) {
|
||||
if !p.ConfigureCalled {
|
||||
t.Fatal("configure should be called")
|
||||
}
|
||||
if p.ConfigureConfig["foo"].(string) != "2" {
|
||||
if p.ConfigureConfig.Raw["foo"].(string) != "2" {
|
||||
t.Fatalf("bad: %#v", p.ConfigureConfig)
|
||||
}
|
||||
}
|
||||
@ -273,10 +273,10 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory {
|
||||
return func() (ResourceProvider, error) {
|
||||
diffFn := func(
|
||||
_ *ResourceState,
|
||||
c map[string]interface{}) (*ResourceDiff, error) {
|
||||
c *ResourceConfig) (*ResourceDiff, error) {
|
||||
var diff ResourceDiff
|
||||
diff.Attributes = make(map[string]*ResourceAttrDiff)
|
||||
for k, v := range c {
|
||||
for k, v := range c.Raw {
|
||||
if _, ok := v.(string); !ok {
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user