-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsonconfig: Improve provider configuration output
When rendering configuration as JSON, we have a single map of provider configurations at the top level, since these are globally applicable. Each resource has an opaque key into this map which points at the configuration data for the provider. This commit fixes two bugs in this implementation: - Resources in non-root modules had an invalid provider config key, which meant that there was never a valid reference to the provider config block. These keys were prefixed with the local module name instead of the path to the module. This is now corrected. - Modules with passed provider configs would point to either an empty provider config block or one which is not present at all. This has been fixed so that these resources point to the provider config block from the calling module (or wherever up the module tree it was originally defined). We also add a "full_name" key-value pair to the provider config block, with the entire fully-qualified provider name including hostname and namespace.
- Loading branch information
Showing
12 changed files
with
768 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
internal/command/testdata/show-json/provider-aliasing/child/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
terraform { | ||
required_providers { | ||
test = { | ||
source = "hashicorp/test" | ||
configuration_aliases = [test, test.second] | ||
} | ||
} | ||
} | ||
|
||
resource "test_instance" "test_primary" { | ||
ami = "primary" | ||
provider = test | ||
} | ||
|
||
resource "test_instance" "test_secondary" { | ||
ami = "secondary" | ||
provider = test.second | ||
} | ||
|
||
module "grandchild" { | ||
source = "./nested" | ||
providers = { | ||
test = test | ||
test.alt = test.second | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
internal/command/testdata/show-json/provider-aliasing/child/nested/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
terraform { | ||
required_providers { | ||
test = { | ||
source = "hashicorp/test" | ||
configuration_aliases = [test, test.alt] | ||
} | ||
} | ||
} | ||
|
||
resource "test_instance" "test_main" { | ||
ami = "main" | ||
provider = test | ||
} | ||
|
||
resource "test_instance" "test_alternate" { | ||
ami = "secondary" | ||
provider = test.alt | ||
} |
34 changes: 34 additions & 0 deletions
34
internal/command/testdata/show-json/provider-aliasing/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
provider "test" { | ||
region = "somewhere" | ||
} | ||
|
||
provider "test" { | ||
alias = "backup" | ||
region = "elsewhere" | ||
} | ||
|
||
resource "test_instance" "test" { | ||
ami = "foo" | ||
provider = test | ||
} | ||
|
||
resource "test_instance" "test_backup" { | ||
ami = "foo-backup" | ||
provider = test.backup | ||
} | ||
|
||
module "child" { | ||
source = "./child" | ||
providers = { | ||
test = test | ||
test.second = test.backup | ||
} | ||
} | ||
|
||
module "sibling" { | ||
source = "./child" | ||
providers = { | ||
test = test | ||
test.second = test | ||
} | ||
} |
Oops, something went wrong.