2020-12-09 15:31:34 +00:00
|
|
|
package supplier
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/iac/terraform/state/backend"
|
2021-01-15 11:44:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-12-09 15:31:34 +00:00
|
|
|
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/iac/config"
|
|
|
|
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/iac/terraform/state"
|
|
|
|
|
|
|
|
"github.com/cloudskiff/driftctl/pkg/resource"
|
|
|
|
)
|
|
|
|
|
|
|
|
var supportedSuppliers = []string{
|
|
|
|
state.TerraformStateReaderSupplier,
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsSupplierSupported(supplierKey string) bool {
|
|
|
|
for _, s := range supportedSuppliers {
|
|
|
|
if s == supplierKey {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-01-15 11:44:13 +00:00
|
|
|
func GetIACSupplier(configs []config.SupplierConfig) (resource.Supplier, error) {
|
|
|
|
chainSupplier := resource.NewChainSupplier()
|
|
|
|
for _, config := range configs {
|
|
|
|
if !IsSupplierSupported(config.Key) {
|
|
|
|
return nil, fmt.Errorf("Unsupported supplier '%s'", config.Key)
|
|
|
|
}
|
|
|
|
|
|
|
|
var supplier resource.Supplier
|
|
|
|
var err error
|
|
|
|
switch config.Key {
|
|
|
|
case state.TerraformStateReaderSupplier:
|
|
|
|
supplier, err = state.NewReader(config)
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("Unsupported supplier '%s'", config.Key)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"supplier": config.Key,
|
|
|
|
"backend": config.Backend,
|
|
|
|
"path": config.Path,
|
|
|
|
}).Debug("Found IAC supplier")
|
2020-12-09 15:31:34 +00:00
|
|
|
|
2021-01-15 11:44:13 +00:00
|
|
|
chainSupplier.AddSupplier(supplier)
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
2021-01-15 11:44:13 +00:00
|
|
|
return chainSupplier, nil
|
2020-12-09 15:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetSupportedSuppliers() []string {
|
|
|
|
return supportedSuppliers
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetSupportedSchemes() []string {
|
|
|
|
schemes := []string{
|
|
|
|
"tfstate://",
|
|
|
|
}
|
|
|
|
for _, supplier := range supportedSuppliers {
|
|
|
|
for _, backend := range backend.GetSupportedBackends() {
|
|
|
|
schemes = append(schemes, fmt.Sprintf("%s+%s://", supplier, backend))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return schemes
|
|
|
|
}
|