plugin/discovery: Parse warnings from TF Registry
Terraform Registry (and other registry implementations) can now return an array of warnings with the versions response. These warnings are now displayed to the user during a `terraform init`.
This commit is contained in:
parent
24e13d8ec1
commit
e6316c9de6
|
@ -197,7 +197,7 @@ func (i *mockProviderInstaller) PurgeUnused(map[string]discovery.PluginMeta) (di
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type callbackPluginInstaller func(provider string, req discovery.Constraints) (discovery.PluginMeta, error)
|
type callbackPluginInstaller func(provider string, req discovery.Constraints) (discovery.PluginMeta, tfdiags.Diagnostics, error)
|
||||||
|
|
||||||
func (cb callbackPluginInstaller) Get(provider string, req discovery.Constraints) (discovery.PluginMeta, tfdiags.Diagnostics, error) {
|
func (cb callbackPluginInstaller) Get(provider string, req discovery.Constraints) (discovery.PluginMeta, tfdiags.Diagnostics, error) {
|
||||||
return cb(provider, req)
|
return cb(provider, req)
|
||||||
|
|
|
@ -136,6 +136,17 @@ func (i *ProviderInstaller) Get(provider string, req Constraints) (PluginMeta, t
|
||||||
}
|
}
|
||||||
return PluginMeta{}, diags, ErrorNoSuchProvider
|
return PluginMeta{}, diags, ErrorNoSuchProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add any warnings from the response to diags
|
||||||
|
for _, warning := range allVersions.Warnings {
|
||||||
|
hostname, err := i.hostname()
|
||||||
|
if err != nil {
|
||||||
|
return PluginMeta{}, diags, err
|
||||||
|
}
|
||||||
|
diag := tfdiags.SimpleWarning(fmt.Sprintf("%s: %s", hostname, warning))
|
||||||
|
diags = diags.Append(diag)
|
||||||
|
}
|
||||||
|
|
||||||
if len(allVersions.Versions) == 0 {
|
if len(allVersions.Versions) == 0 {
|
||||||
return PluginMeta{}, diags, ErrorNoSuitableVersion
|
return PluginMeta{}, diags, ErrorNoSuitableVersion
|
||||||
}
|
}
|
||||||
|
@ -423,6 +434,16 @@ func (i *ProviderInstaller) getProviderChecksum(urls *response.TerraformProvider
|
||||||
return checksumForFile(shasums, urls.Filename), nil
|
return checksumForFile(shasums, urls.Filename), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *ProviderInstaller) hostname() (string, error) {
|
||||||
|
provider := regsrc.NewTerraformProvider("", i.OS, i.Arch)
|
||||||
|
svchost, err := provider.SvcHost()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return svchost.ForDisplay(), nil
|
||||||
|
}
|
||||||
|
|
||||||
// list all versions available for the named provider
|
// list all versions available for the named provider
|
||||||
func (i *ProviderInstaller) listProviderVersions(name string) (*response.TerraformProviderVersions, error) {
|
func (i *ProviderInstaller) listProviderVersions(name string) (*response.TerraformProviderVersions, error) {
|
||||||
provider := regsrc.NewTerraformProvider(name, i.OS, i.Arch)
|
provider := regsrc.NewTerraformProvider(name, i.OS, i.Arch)
|
||||||
|
|
|
@ -32,6 +32,7 @@ type TerraformProviderVersion struct {
|
||||||
type TerraformProviderVersions struct {
|
type TerraformProviderVersions struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Versions []*TerraformProviderVersion `json:"versions"`
|
Versions []*TerraformProviderVersion `json:"versions"`
|
||||||
|
Warnings []string `json:"warnings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TerraformProviderPlatform is the Terraform-specific response structure for a
|
// TerraformProviderPlatform is the Terraform-specific response structure for a
|
||||||
|
|
Loading…
Reference in New Issue