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 . + + 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.