diff --git a/internal/command/jsonconfig/config.go b/internal/command/jsonconfig/config.go index 4727bc0982..f744c91086 100644 --- a/internal/command/jsonconfig/config.go +++ b/internal/command/jsonconfig/config.go @@ -239,27 +239,29 @@ func marshalProviderConfigs( m[key] = p } - // In child modules, providers defined in the parent module can be implicitly used. - // Such providers could have no requirements and configuration blocks defined. - if c.Parent != nil { - for req := range reqs { - // Implicit inheritance only applies to the default provider, - // so the provider name must be same as the provider type. - key := opaqueProviderKey(req.Type, c.Path.String()) - if _, exists := m[key]; exists { - continue - } - - parentKey := opaqueProviderKey(req.Type, c.Parent.Path.String()) - p := providerConfig{ - Name: req.Type, - FullName: req.String(), - ModuleAddress: c.Path.String(), - parentKey: findSourceProviderKey(parentKey, req.String(), m), - } - - m[key] = p + // Providers could be implicitly created or inherited from the parent module + // when no requirements and configuration block defined. + for req := range reqs { + // Only default providers could implicitly exist, + // so the provider name must be same as the provider type. + key := opaqueProviderKey(req.Type, c.Path.String()) + if _, exists := m[key]; exists { + continue } + + p := providerConfig{ + Name: req.Type, + FullName: req.String(), + ModuleAddress: c.Path.String(), + } + + // In child modules, providers defined in the parent module can be implicitly used. + if c.Parent != nil { + parentKey := opaqueProviderKey(req.Type, c.Parent.Path.String()) + p.parentKey = findSourceProviderKey(parentKey, p.FullName, m) + } + + m[key] = p } // Must also visit our child modules, recursively. diff --git a/internal/command/testdata/show-json/basic-delete/output.json b/internal/command/testdata/show-json/basic-delete/output.json index e1779c04cc..4b10cc283a 100644 --- a/internal/command/testdata/show-json/basic-delete/output.json +++ b/internal/command/testdata/show-json/basic-delete/output.json @@ -130,6 +130,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "outputs": { "test": { diff --git a/internal/command/testdata/show-json/basic-update/output.json b/internal/command/testdata/show-json/basic-update/output.json index e4b4731426..a81cc2b5d1 100644 --- a/internal/command/testdata/show-json/basic-update/output.json +++ b/internal/command/testdata/show-json/basic-update/output.json @@ -96,6 +96,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "outputs": { "test": { diff --git a/internal/command/testdata/show-json/drift/output.json b/internal/command/testdata/show-json/drift/output.json index 2d5c071b43..08029bf37e 100644 --- a/internal/command/testdata/show-json/drift/output.json +++ b/internal/command/testdata/show-json/drift/output.json @@ -141,6 +141,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "resources": [ { diff --git a/internal/command/testdata/show-json/module-depends-on/output.json b/internal/command/testdata/show-json/module-depends-on/output.json index d02efaa22f..c76c762659 100644 --- a/internal/command/testdata/show-json/module-depends-on/output.json +++ b/internal/command/testdata/show-json/module-depends-on/output.json @@ -43,6 +43,12 @@ } ], "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "resources": [ { diff --git a/internal/command/testdata/show-json/modules/output.json b/internal/command/testdata/show-json/modules/output.json index 1728282592..e4ef8deb18 100644 --- a/internal/command/testdata/show-json/modules/output.json +++ b/internal/command/testdata/show-json/modules/output.json @@ -293,6 +293,11 @@ "module_address": "module.module_test_foo", "name": "test", "full_name": "registry.terraform.io/hashicorp/test" + }, + "module.module_test_bar:test": { + "module_address": "module.module_test_bar", + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" } } } diff --git a/internal/command/testdata/show-json/moved-drift/output.json b/internal/command/testdata/show-json/moved-drift/output.json index ad6b056413..db3ac21c25 100644 --- a/internal/command/testdata/show-json/moved-drift/output.json +++ b/internal/command/testdata/show-json/moved-drift/output.json @@ -143,6 +143,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "resources": [ { diff --git a/internal/command/testdata/show-json/moved/output.json b/internal/command/testdata/show-json/moved/output.json index 3e74a4ddb4..d8b9f2a245 100644 --- a/internal/command/testdata/show-json/moved/output.json +++ b/internal/command/testdata/show-json/moved/output.json @@ -68,6 +68,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "resources": [ { diff --git a/internal/command/testdata/show-json/multi-resource-update/output.json b/internal/command/testdata/show-json/multi-resource-update/output.json index 6da29965e2..279a8d5593 100644 --- a/internal/command/testdata/show-json/multi-resource-update/output.json +++ b/internal/command/testdata/show-json/multi-resource-update/output.json @@ -137,6 +137,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "outputs": { "test": { diff --git a/internal/command/testdata/show-json/nested-modules/output.json b/internal/command/testdata/show-json/nested-modules/output.json index 6d0af8a146..cf1ab978c9 100644 --- a/internal/command/testdata/show-json/nested-modules/output.json +++ b/internal/command/testdata/show-json/nested-modules/output.json @@ -37,9 +37,7 @@ "name": "test", "provider_name": "registry.terraform.io/hashicorp/test", "change": { - "actions": [ - "create" - ], + "actions": ["create"], "before": null, "after": { "ami": "bar-var" @@ -53,6 +51,13 @@ } ], "configuration": { + "provider_config": { + "module.my_module.module.more:test": { + "module_address": "module.my_module.module.more", + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "module_calls": { "my_module": { @@ -71,9 +76,7 @@ "provider_config_key": "module.my_module.module.more:test", "expressions": { "ami": { - "references": [ - "var.test_var" - ] + "references": ["var.test_var"] } }, "schema_version": 0 diff --git a/internal/command/testdata/show-json/requires-replace/output.json b/internal/command/testdata/show-json/requires-replace/output.json index e71df784f4..1eb37ea1cf 100644 --- a/internal/command/testdata/show-json/requires-replace/output.json +++ b/internal/command/testdata/show-json/requires-replace/output.json @@ -70,6 +70,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "resources": [ { diff --git a/internal/command/testdata/show-json/sensitive-values/output.json b/internal/command/testdata/show-json/sensitive-values/output.json index d7e4719c71..0047c0b600 100644 --- a/internal/command/testdata/show-json/sensitive-values/output.json +++ b/internal/command/testdata/show-json/sensitive-values/output.json @@ -81,6 +81,12 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "full_name": "registry.terraform.io/hashicorp/test" + } + }, "root_module": { "outputs": { "test": {