Retrieve provider version and schema version

main
Elie 2021-06-09 17:28:40 +02:00 committed by sundowndev
parent 5790225f64
commit 35b511ef43
6 changed files with 27 additions and 13 deletions

View File

@ -24,7 +24,9 @@ func Init(version string, alerter *alerter.Alerter,
progress output.Progress,
resourceSchemaRepository *resource.SchemaRepository,
factory resource.ResourceFactory) error {
if version == "" {
version = "3.19.0"
}
provider, err := NewAWSTerraformProvider(version, progress)
if err != nil {
return err
@ -100,7 +102,10 @@ func Init(version string, alerter *alerter.Alerter,
supplierLibrary.AddSupplier(NewKMSAliasSupplier(provider, deserializer, kmsRepository))
supplierLibrary.AddSupplier(NewLambdaEventSourceMappingSupplier(provider, deserializer, lambdaRepository))
resourceSchemaRepository.Init(provider.Schema())
err = resourceSchemaRepository.Init(version, provider.Schema())
if err != nil {
return err
}
aws.InitResourcesMetadata(resourceSchemaRepository)
return nil

View File

@ -45,9 +45,6 @@ type AWSTerraformProvider struct {
func NewAWSTerraformProvider(version string, progress output.Progress) (*AWSTerraformProvider, error) {
p := &AWSTerraformProvider{}
providerKey := "aws"
if version == "" {
version = "3.19.0"
}
installer, err := tf.NewProviderInstaller(tf.ProviderConfig{
Key: providerKey,
Version: version,

View File

@ -22,7 +22,9 @@ func Init(version string, alerter *alerter.Alerter,
progress output.Progress,
resourceSchemaRepository *resource.SchemaRepository,
factory resource.ResourceFactory) error {
if version == "" {
version = "4.4.0"
}
provider, err := NewGithubTerraformProvider(version, progress)
if err != nil {
return err
@ -44,7 +46,10 @@ func Init(version string, alerter *alerter.Alerter,
supplierLibrary.AddSupplier(NewGithubTeamMembershipSupplier(provider, repository, deserializer))
supplierLibrary.AddSupplier(NewGithubBranchProtectionSupplier(provider, repository, deserializer))
resourceSchemaRepository.Init(provider.Schema())
err = resourceSchemaRepository.Init(version, provider.Schema())
if err != nil {
return err
}
github.InitResourcesMetadata(resourceSchemaRepository)
return nil

View File

@ -22,9 +22,6 @@ type githubConfig struct {
func NewGithubTerraformProvider(version string, progress output.Progress) (*GithubTerraformProvider, error) {
p := &GithubTerraformProvider{}
providerKey := "github"
if version == "" {
version = "4.4.0"
}
installer, err := tf.NewProviderInstaller(tf.ProviderConfig{
Key: providerKey,
Version: version,

View File

@ -3,6 +3,7 @@ package resource
import (
"strings"
"github.com/hashicorp/go-version"
"github.com/hashicorp/terraform/configs/configschema"
"github.com/hashicorp/terraform/providers"
"github.com/sirupsen/logrus"
@ -14,6 +15,8 @@ type AttributeSchema struct {
}
type Schema struct {
ProviderVersion *version.Version
SchemaVersion int64
Attributes map[string]AttributeSchema
NormalizeFunc func(res *AbstractResource)
HumanReadableAttributesFunc func(res *AbstractResource) map[string]string
@ -73,7 +76,11 @@ func (r *SchemaRepository) fetchNestedBlocks(root string, metadata map[string]At
}
}
func (r *SchemaRepository) Init(schema map[string]providers.Schema) {
func (r *SchemaRepository) Init(v string, schema map[string]providers.Schema) error {
providerVersion, err := version.NewVersion(v)
if err != nil {
return err
}
for typ, sch := range schema {
attributeMetas := map[string]AttributeSchema{}
for s, attribute := range sch.Block.Attributes {
@ -85,9 +92,12 @@ func (r *SchemaRepository) Init(schema map[string]providers.Schema) {
r.fetchNestedBlocks("", attributeMetas, sch.Block.BlockTypes)
r.schemas[typ] = &Schema{
Attributes: attributeMetas,
ProviderVersion: providerVersion,
SchemaVersion: sch.Version,
Attributes: attributeMetas,
}
}
return nil
}
func (r *SchemaRepository) UpdateSchema(typ string, schemasMutators map[string]func(attributeSchema *AttributeSchema)) {

View File

@ -63,6 +63,6 @@ func InitFakeSchemaRepository(provider, version string) resource.SchemaRepositor
}
schema = s
}
repo.Init(schema)
_ = repo.Init("1.0.0", schema)
return repo
}