mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-16 19:52:49 -06:00
a43f141f9e
* tools/terraform-bundle: refactor to use new provider installer and provider directory layouts terraform-bundle now supports a "source" attribute for providers, uses the new provider installer, and the archive it creates preserves the new (required) directory hierarchy for providers, under a "plugins" directory. This is a breaking change in many ways: source is required for any non-HashiCorp provider, locally-installed providers must be given a source (can be arbitrary, see docs) and placed in the expected directory hierarchy, and the unzipped archive is no longer flat; there is a new "plugins" directory created with providers in the new directory layout. This PR also extends the existing test to check the contents of the zip file. TODO: Re-enable e2e tests (currently suppressed with a t.Skip) This commit includes an update to our travis configuration, so the terraform-bundle e2e tests run. It also turns off the e2e tests, which will fail until we have a terraform 0.13.* release under releases.hashicorp.com. We decided it was better to merge this now instead of waiting when we started seeing issues opened from users who built terraform-bundle from 0.13 and found it didn't work with 0.12 - better that they get an immediate error message from the binary directing them to build from the appropriate release.
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
|
|
"github.com/hashicorp/hcl"
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/internal/getproviders"
|
|
"github.com/hashicorp/terraform/plugin/discovery"
|
|
)
|
|
|
|
var zeroThirteen = discovery.ConstraintStr(">= 0.13.0").MustParse()
|
|
|
|
type Config struct {
|
|
Terraform TerraformConfig `hcl:"terraform"`
|
|
Providers map[string]ProviderConfig `hcl:"providers"`
|
|
}
|
|
|
|
type TerraformConfig struct {
|
|
Version discovery.VersionStr `hcl:"version"`
|
|
}
|
|
|
|
type ProviderConfig struct {
|
|
Versions []string `hcl:"versions"`
|
|
Source string `hcl:"source"`
|
|
}
|
|
|
|
func LoadConfig(src []byte, filename string) (*Config, error) {
|
|
config := &Config{}
|
|
err := hcl.Decode(config, string(src))
|
|
if err != nil {
|
|
return config, err
|
|
}
|
|
|
|
err = config.validate()
|
|
return config, err
|
|
}
|
|
|
|
func LoadConfigFile(filename string) (*Config, error) {
|
|
src, err := ioutil.ReadFile(filename)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return LoadConfig(src, filename)
|
|
}
|
|
|
|
func (c *Config) validate() error {
|
|
if c.Terraform.Version == "" {
|
|
return fmt.Errorf("terraform.version is required")
|
|
}
|
|
|
|
var v discovery.Version
|
|
var err error
|
|
if v, err = c.Terraform.Version.Parse(); err != nil {
|
|
return fmt.Errorf("terraform.version: %s", err)
|
|
}
|
|
if !zeroThirteen.Allows(v) {
|
|
return fmt.Errorf("this version of terraform-bundle can only build bundles for Terraform v0.13 and later; build terraform-bundle from a release tag (such as v0.12.*) to construct bundles for earlier versions")
|
|
}
|
|
|
|
if c.Providers == nil {
|
|
c.Providers = map[string]ProviderConfig{}
|
|
}
|
|
|
|
for k, cs := range c.Providers {
|
|
if cs.Source != "" {
|
|
_, diags := addrs.ParseProviderSourceString(cs.Source)
|
|
if diags.HasErrors() {
|
|
return fmt.Errorf("providers.%s: %s", k, diags.Err().Error())
|
|
}
|
|
}
|
|
for _, c := range cs.Versions {
|
|
if _, err := getproviders.ParseVersionConstraints(c); err != nil {
|
|
return fmt.Errorf("providers.%s: %s", k, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|