terraform init should pick up action providers

pull/37368/head
Daniel Schmidt 10 months ago
parent 11f00e584b
commit c6c8be3e79

@ -483,6 +483,15 @@ func (c *Config) addProviderRequirements(reqs providerreqs.Requirements, recurse
reqs[fqn] = nil
}
for _, rc := range c.Module.Actions {
fqn := rc.Provider
if _, exists := reqs[fqn]; exists {
// Explicit dependency already present
continue
}
reqs[fqn] = nil
}
// Import blocks that are generating config may have a custom provider
// meta-argument. Like the provider meta-argument used in resource blocks,
// we use this opportunity to load any implicit providers.
@ -1022,6 +1031,9 @@ func (c *Config) EffectiveRequiredProviderConfigs() addrs.Map[addrs.RootProvider
for _, rc := range c.Module.DataResources {
maybePutLocal(rc.ProviderConfigAddr(), false)
}
for _, rc := range c.Module.Actions {
maybePutLocal(rc.ProviderConfigAddr(), false)
}
for _, ic := range c.Module.Import {
if ic.ProviderConfigRef != nil {
maybePutLocal(addrs.LocalProviderConfig{

@ -29,14 +29,16 @@ func TestConfigProviderTypes(t *testing.T) {
t.Fatal("expected empty result from empty config")
}
cfg, diags := testModuleConfigFromFile("testdata/valid-files/providers-explicit-implied.tf")
cfg, diags := testModuleFromFileWithExperiments("testdata/valid-files/providers-explicit-implied.tf")
if diags.HasErrors() {
t.Fatal(diags.Error())
}
got = cfg.ProviderTypes()
want := []addrs.Provider{
addrs.NewDefaultProvider("aws"),
addrs.NewDefaultProvider("external"),
addrs.NewDefaultProvider("local"),
addrs.NewDefaultProvider("null"),
addrs.NewDefaultProvider("template"),

@ -52,6 +52,18 @@ func testModuleConfigFromFile(filename string) (*Config, hcl.Diagnostics) {
return cfg, append(diags, moreDiags...)
}
// testModuleFromFileWithExperiments File reads a single file from the given path as a
// module and returns its configuration. This is a helper for use in unit tests.
func testModuleFromFileWithExperiments(filename string) (*Config, hcl.Diagnostics) {
parser := NewParser(nil)
parser.AllowLanguageExperiments(true)
f, diags := parser.LoadConfigFile(filename)
mod, modDiags := NewModule([]*File{f}, nil)
diags = append(diags, modDiags...)
cfg, moreDiags := BuildConfig(mod, nil, nil)
return cfg, append(diags, moreDiags...)
}
// testModuleFromDir reads configuration from the given directory path as
// a module and returns it. This is a helper for use in unit tests.
func testModuleFromDir(path string) (*Module, hcl.Diagnostics) {

@ -14,6 +14,9 @@ resource "null_resource" "foo" {
}
action "external_test" "foo" {
}
import {
id = "directory/filename"
to = local_file.foo

Loading…
Cancel
Save