From 2d31d50bf2c7fb6bad0b116a3f390ecc04bf6549 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Wed, 17 Jul 2019 18:24:09 +0000 Subject: [PATCH] Add check on import name split length Signed-off-by: Modular Magician --- google-beta/resource_access_context_manager_access_level.go | 3 +++ .../resource_access_context_manager_service_perimeter.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/google-beta/resource_access_context_manager_access_level.go b/google-beta/resource_access_context_manager_access_level.go index 83430a6fc4..b9ca4bffa3 100644 --- a/google-beta/resource_access_context_manager_access_level.go +++ b/google-beta/resource_access_context_manager_access_level.go @@ -365,6 +365,9 @@ func resourceAccessContextManagerAccessLevelImport(d *schema.ResourceData, meta return nil, err } stringParts := strings.Split(d.Get("name").(string), "/") + if len(stringParts) < 2 { + return nil, fmt.Errorf("Error parsing parent name. Should be in form accessPolicies/{{policy_id}}/accessLevel/{{short_name}}") + } d.Set("parent", fmt.Sprintf("%s/%s", stringParts[0], stringParts[1])) return []*schema.ResourceData{d}, nil } diff --git a/google-beta/resource_access_context_manager_service_perimeter.go b/google-beta/resource_access_context_manager_service_perimeter.go index 73b91f13e2..a3d0472365 100644 --- a/google-beta/resource_access_context_manager_service_perimeter.go +++ b/google-beta/resource_access_context_manager_service_perimeter.go @@ -332,6 +332,9 @@ func resourceAccessContextManagerServicePerimeterImport(d *schema.ResourceData, return nil, err } stringParts := strings.Split(d.Get("name").(string), "/") + if len(stringParts) < 2 { + return nil, fmt.Errorf("Error parsing parent name. Should be in form accessPolicies/{{policy_id}}/servicePerimeter/{{short_name}}") + } d.Set("parent", fmt.Sprintf("%s/%s", stringParts[0], stringParts[1])) return []*schema.ResourceData{d}, nil }