command/show: fix bug displaying provider config in json output of tf plan (#25577)
A lingering FIXME caused missing configuration from provider config blocks in the json output of terraform plan. This fixes the regression and adds a test. For the sake of testing, I added an optional attribute to the show test provider, which resulted in the providers schema test getting an update - not a bad addition, but we can always add a test-specific provider schema as needed.
This commit is contained in:
parent
bcec7f5576
commit
f8e3456867
|
@ -139,8 +139,7 @@ func marshalProviderConfigs(
|
||||||
}
|
}
|
||||||
|
|
||||||
for k, pc := range c.Module.ProviderConfigs {
|
for k, pc := range c.Module.ProviderConfigs {
|
||||||
// FIXME: lookup providerFqn from config
|
providerFqn := c.ProviderForConfigAddr(addrs.LocalProviderConfig{LocalName: pc.Name})
|
||||||
providerFqn := addrs.NewLegacyProvider(pc.Name)
|
|
||||||
schema := schemas.ProviderConfig(providerFqn)
|
schema := schemas.ProviderConfig(providerFqn)
|
||||||
p := providerConfig{
|
p := providerConfig{
|
||||||
Name: pc.Name,
|
Name: pc.Name,
|
||||||
|
|
|
@ -411,6 +411,11 @@ func TestShow_json_output_state(t *testing.T) {
|
||||||
// named "test".
|
// named "test".
|
||||||
func showFixtureSchema() *terraform.ProviderSchema {
|
func showFixtureSchema() *terraform.ProviderSchema {
|
||||||
return &terraform.ProviderSchema{
|
return &terraform.ProviderSchema{
|
||||||
|
Provider: &configschema.Block{
|
||||||
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
"region": {Type: cty.String, Optional: true},
|
||||||
|
},
|
||||||
|
},
|
||||||
ResourceTypes: map[string]*configschema.Block{
|
ResourceTypes: map[string]*configschema.Block{
|
||||||
"test_instance": {
|
"test_instance": {
|
||||||
Attributes: map[string]*configschema.Attribute{
|
Attributes: map[string]*configschema.Attribute{
|
||||||
|
|
|
@ -2,6 +2,19 @@
|
||||||
"format_version": "0.1",
|
"format_version": "0.1",
|
||||||
"provider_schemas": {
|
"provider_schemas": {
|
||||||
"registry.terraform.io/hashicorp/test": {
|
"registry.terraform.io/hashicorp/test": {
|
||||||
|
"provider": {
|
||||||
|
"version": 0,
|
||||||
|
"block": {
|
||||||
|
"attributes": {
|
||||||
|
"region": {
|
||||||
|
"description_kind": "plain",
|
||||||
|
"optional": true,
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description_kind": "plain"
|
||||||
|
}
|
||||||
|
},
|
||||||
"resource_schemas": {
|
"resource_schemas": {
|
||||||
"test_instance": {
|
"test_instance": {
|
||||||
"version": 0,
|
"version": 0,
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
|
provider "test" {
|
||||||
|
region = "somewhere"
|
||||||
|
}
|
||||||
|
|
||||||
variable "test_var" {
|
variable "test_var" {
|
||||||
default = "bar"
|
default = "bar"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "test_instance" "test" {
|
resource "test_instance" "test" {
|
||||||
ami = var.test_var
|
ami = var.test_var
|
||||||
count = 3
|
count = 3
|
||||||
|
|
|
@ -138,6 +138,16 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"configuration": {
|
"configuration": {
|
||||||
|
"provider_config": {
|
||||||
|
"test": {
|
||||||
|
"name": "test",
|
||||||
|
"expressions": {
|
||||||
|
"region": {
|
||||||
|
"constant_value": "somewhere"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"root_module": {
|
"root_module": {
|
||||||
"outputs": {
|
"outputs": {
|
||||||
"test": {
|
"test": {
|
||||||
|
|
Loading…
Reference in New Issue