From f8e3456867d16816be2aa9b51ef9ddb800bcf232 Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Tue, 14 Jul 2020 15:28:31 -0400 Subject: [PATCH] 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. --- command/jsonconfig/config.go | 3 +-- command/show_test.go | 5 +++++ command/testdata/providers-schema/basic/output.json | 13 +++++++++++++ command/testdata/show-json/basic-create/main.tf | 5 +++++ command/testdata/show-json/basic-create/output.json | 10 ++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/command/jsonconfig/config.go b/command/jsonconfig/config.go index 1911bfa22..5d402089b 100644 --- a/command/jsonconfig/config.go +++ b/command/jsonconfig/config.go @@ -139,8 +139,7 @@ func marshalProviderConfigs( } for k, pc := range c.Module.ProviderConfigs { - // FIXME: lookup providerFqn from config - providerFqn := addrs.NewLegacyProvider(pc.Name) + providerFqn := c.ProviderForConfigAddr(addrs.LocalProviderConfig{LocalName: pc.Name}) schema := schemas.ProviderConfig(providerFqn) p := providerConfig{ Name: pc.Name, diff --git a/command/show_test.go b/command/show_test.go index bc2f36bfa..1f28294c7 100644 --- a/command/show_test.go +++ b/command/show_test.go @@ -411,6 +411,11 @@ func TestShow_json_output_state(t *testing.T) { // named "test". func showFixtureSchema() *terraform.ProviderSchema { return &terraform.ProviderSchema{ + Provider: &configschema.Block{ + Attributes: map[string]*configschema.Attribute{ + "region": {Type: cty.String, Optional: true}, + }, + }, ResourceTypes: map[string]*configschema.Block{ "test_instance": { Attributes: map[string]*configschema.Attribute{ diff --git a/command/testdata/providers-schema/basic/output.json b/command/testdata/providers-schema/basic/output.json index ebb06f9d9..ba58e2f3c 100644 --- a/command/testdata/providers-schema/basic/output.json +++ b/command/testdata/providers-schema/basic/output.json @@ -2,6 +2,19 @@ "format_version": "0.1", "provider_schemas": { "registry.terraform.io/hashicorp/test": { + "provider": { + "version": 0, + "block": { + "attributes": { + "region": { + "description_kind": "plain", + "optional": true, + "type": "string" + } + }, + "description_kind": "plain" + } + }, "resource_schemas": { "test_instance": { "version": 0, diff --git a/command/testdata/show-json/basic-create/main.tf b/command/testdata/show-json/basic-create/main.tf index d9e282763..2f41f5304 100644 --- a/command/testdata/show-json/basic-create/main.tf +++ b/command/testdata/show-json/basic-create/main.tf @@ -1,6 +1,11 @@ +provider "test" { + region = "somewhere" +} + variable "test_var" { default = "bar" } + resource "test_instance" "test" { ami = var.test_var count = 3 diff --git a/command/testdata/show-json/basic-create/output.json b/command/testdata/show-json/basic-create/output.json index 0aef81763..ff83de3fe 100644 --- a/command/testdata/show-json/basic-create/output.json +++ b/command/testdata/show-json/basic-create/output.json @@ -138,6 +138,16 @@ } }, "configuration": { + "provider_config": { + "test": { + "name": "test", + "expressions": { + "region": { + "constant_value": "somewhere" + } + } + } + }, "root_module": { "outputs": { "test": {