From c37003694fff288f1d37f3e8634f11d75c809685 Mon Sep 17 00:00:00 2001 From: Elie Date: Wed, 10 Aug 2022 17:15:27 +0200 Subject: [PATCH] Fix acceptance tests - Fix default provider version not being set in the schema repository since now this is done on the enumeration side. - Fix once for all issues with GetInt that should be able to retrieve both float and int from resource attributes. --- enumeration/resource/resource.go | 14 +++++++++----- pkg/resource/schemas/repository.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/enumeration/resource/resource.go b/enumeration/resource/resource.go index e7279276a..3621171e2 100644 --- a/enumeration/resource/resource.go +++ b/enumeration/resource/resource.go @@ -188,14 +188,18 @@ func (a *Attributes) GetBool(path string) *bool { } func (a *Attributes) GetInt(path string) *int { - // This is a nonsense, if we want to retrieve an int this is gonna fail - // We were doing that because all numbers fields from cty are float64 but sometimes we want to retrieve an int - // TODO Change this to be compatible with both int and float64 underlying type - val := a.GetFloat64(path) + val, exist := (*a)[path] + if !exist { + return nil + } + if v, isInt := val.(int); isInt { + return &v + } + floatVal := a.GetFloat64(path) if val == nil { return nil } - v := int(*val) + v := int(*floatVal) return &v } diff --git a/pkg/resource/schemas/repository.go b/pkg/resource/schemas/repository.go index fe09f15b8..b1ad485aa 100644 --- a/pkg/resource/schemas/repository.go +++ b/pkg/resource/schemas/repository.go @@ -47,6 +47,22 @@ func (r *SchemaRepository) fetchNestedBlocks(root string, metadata map[string]re } func (r *SchemaRepository) Init(providerName, providerVersion string, schema map[string]providers.Schema) error { + + if providerVersion == "" { + switch providerName { + case "aws": + providerVersion = "3.19.0" + case "github": + providerVersion = "4.4.0" + case "google": + providerVersion = "3.78.0" + case "azurerm": + providerVersion = "2.71.0" + default: + return errors.Errorf("unsupported remote '%s'", providerName) + } + } + v, err := version.NewVersion(providerVersion) if err != nil { return err