From 2ea4a42fba7e081f65feabc7521784808c56894f Mon Sep 17 00:00:00 2001 From: Luiz Felipe Warmling Amadeu Date: Fri, 7 Oct 2022 13:39:12 +0000 Subject: [PATCH 1/2] [NEW]: Gitpod config for latest alterations --- .gitpod.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000000..44db613e03 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,9 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +tasks: + - init: go get && go build ./... && go test ./... && make + command: go run . + + From 65d28be9867110dea767ad229aa91ad30bc65e86 Mon Sep 17 00:00:00 2001 From: Luiz Felipe Warmling Amadeu Date: Fri, 7 Oct 2022 13:40:30 +0000 Subject: [PATCH 2/2] [FEAT]: Ignore data sources in imported state in ImportState steps && [FIX]: Compile isValidFieldName regex once --- helper/resource/testing_new_import_state.go | 23 ++++++++++++--------- helper/schema/schema.go | 6 ++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/helper/resource/testing_new_import_state.go b/helper/resource/testing_new_import_state.go index fc4ebc9cb0..279828e756 100644 --- a/helper/resource/testing_new_import_state.go +++ b/helper/resource/testing_new_import_state.go @@ -158,20 +158,23 @@ func testStepNewImportState(ctx context.Context, t testing.T, helper *plugintest if step.ImportStateVerify { logging.HelperResourceTrace(ctx, "Using TestStep ImportStateVerify") - newResources := importState.RootModule().Resources - oldResources := state.RootModule().Resources + newResources := make(map[string]*terraform.ResourceState) + for k, v := range importState.RootModule().Resources { + if !strings.HasPrefix(k, "data.") { + newResources[k] = v + } + } + oldResources := make(map[string]*terraform.ResourceState) + for k, v := range state.RootModule().Resources { + if !strings.HasPrefix(k, "data.") { + oldResources[k] = v + } + } for _, r := range newResources { // Find the existing resource var oldR *terraform.ResourceState - for r2Key, r2 := range oldResources { - // Ensure that we do not match against data sources as they - // cannot be imported and are not what we want to verify. - // Mode is not present in ResourceState so we use the - // stringified ResourceStateKey for comparison. - if strings.HasPrefix(r2Key, "data.") { - continue - } + for _, r2 := range oldResources { if r2.Primary != nil && r2.Primary.ID == r.Primary.ID && r2.Type == r.Type && r2.Provider == r.Provider { oldR = r2 diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 5b398fd160..71de3c0f60 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -1093,9 +1093,11 @@ func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap return nil } +var validFieldNameRe = regexp.MustCompile("^[a-z0-9_]+$") + func isValidFieldName(name string) bool { - re := regexp.MustCompile("^[a-z0-9_]+$") - return re.MatchString(name) + + return validFieldNameRe.MatchString(name) } // resourceDiffer is an interface that is used by the private diff functions.