jsonconfig: add implicitly created provider configs

This commit is contained in:
nozaq 2022-02-19 01:15:58 +09:00
parent 0ce040405c
commit 3c32f7a56c
No known key found for this signature in database
GPG Key ID: 99A56FF51B467245
12 changed files with 90 additions and 26 deletions

View File

@ -239,27 +239,29 @@ func marshalProviderConfigs(
m[key] = p m[key] = p
} }
// In child modules, providers defined in the parent module can be implicitly used. // Providers could be implicitly created or inherited from the parent module
// Such providers could have no requirements and configuration blocks defined. // when no requirements and configuration block defined.
if c.Parent != nil { for req := range reqs {
for req := range reqs { // Only default providers could implicitly exist,
// Implicit inheritance only applies to the default provider, // so the provider name must be same as the provider type.
// so the provider name must be same as the provider type. key := opaqueProviderKey(req.Type, c.Path.String())
key := opaqueProviderKey(req.Type, c.Path.String()) if _, exists := m[key]; exists {
if _, exists := m[key]; exists { continue
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
} }
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. // Must also visit our child modules, recursively.

View File

@ -130,6 +130,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"outputs": { "outputs": {
"test": { "test": {

View File

@ -96,6 +96,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"outputs": { "outputs": {
"test": { "test": {

View File

@ -141,6 +141,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"resources": [ "resources": [
{ {

View File

@ -43,6 +43,12 @@
} }
], ],
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"resources": [ "resources": [
{ {

View File

@ -293,6 +293,11 @@
"module_address": "module.module_test_foo", "module_address": "module.module_test_foo",
"name": "test", "name": "test",
"full_name": "registry.terraform.io/hashicorp/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"
} }
} }
} }

View File

@ -143,6 +143,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"resources": [ "resources": [
{ {

View File

@ -68,6 +68,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"resources": [ "resources": [
{ {

View File

@ -137,6 +137,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"outputs": { "outputs": {
"test": { "test": {

View File

@ -37,9 +37,7 @@
"name": "test", "name": "test",
"provider_name": "registry.terraform.io/hashicorp/test", "provider_name": "registry.terraform.io/hashicorp/test",
"change": { "change": {
"actions": [ "actions": ["create"],
"create"
],
"before": null, "before": null,
"after": { "after": {
"ami": "bar-var" "ami": "bar-var"
@ -53,6 +51,13 @@
} }
], ],
"configuration": { "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": { "root_module": {
"module_calls": { "module_calls": {
"my_module": { "my_module": {
@ -71,9 +76,7 @@
"provider_config_key": "module.my_module.module.more:test", "provider_config_key": "module.my_module.module.more:test",
"expressions": { "expressions": {
"ami": { "ami": {
"references": [ "references": ["var.test_var"]
"var.test_var"
]
} }
}, },
"schema_version": 0 "schema_version": 0

View File

@ -70,6 +70,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"resources": [ "resources": [
{ {

View File

@ -81,6 +81,12 @@
} }
}, },
"configuration": { "configuration": {
"provider_config": {
"test": {
"name": "test",
"full_name": "registry.terraform.io/hashicorp/test"
}
},
"root_module": { "root_module": {
"outputs": { "outputs": {
"test": { "test": {