Skip to content

Commit af2733c

Browse files
authored
Merge pull request #74 from rolandg/bugfix/trailing-slash
Bugfix: import with trailing slash
2 parents 7dbb9d2 + 7fb510f commit af2733c

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

restapi/resource_api_object.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,29 @@ func resourceRestApi() *schema.Resource {
105105
from the API */
106106
func resourceRestApiImport(d *schema.ResourceData, meta interface{}) (imported []*schema.ResourceData, err error) {
107107
input := d.Id()
108-
n := strings.LastIndex(input, "/")
108+
109+
hasTrailingSlash := strings.LastIndex(input, "/") == len(input)-1
110+
var n int
111+
if (hasTrailingSlash) {
112+
n = strings.LastIndex(input[0 : len(input) - 1], "/")
113+
} else {
114+
n = strings.LastIndex(input, "/")
115+
}
116+
109117
if n == -1 {
110118
return imported, fmt.Errorf("Invalid path to import api_object '%s'. Must be /<full path from server root>/<object id>", input)
111119
}
112120

113121
path := input[0:n]
114122
d.Set("path", path)
115123

116-
id := input[n+1 : len(input)]
124+
var id string
125+
if (hasTrailingSlash) {
126+
id = input[n + 1 : len(input) - 1]
127+
} else {
128+
id = input[n + 1 : len(input)]
129+
}
130+
117131
d.Set("data", fmt.Sprintf(`{ "id": "%s" }`, id))
118132
d.SetId(id)
119133

vendor/vendor.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"revisionTime": "2019-04-12T11:37:27Z"
1818
},
1919
{
20-
"checksumSHA1": "l/n8xKSFhL5eWDsVE52JwUDl78A=",
20+
"checksumSHA1": "Ffhtm8iHH7l2ynVVOIGJE3eiuLA=",
2121
"origin": "github.com/hashicorp/terraform/vendor/github.com/apparentlymart/go-textseg/textseg",
2222
"path": "github.com/apparentlymart/go-textseg/textseg",
2323
"revision": "1c95b21c6cfffc50cb6b3c3c23b2257d28b61a9c",
@@ -534,7 +534,7 @@
534534
"revisionTime": "2019-04-12T11:37:27Z"
535535
},
536536
{
537-
"checksumSHA1": "teZHH2MsmI96MNuuP9ieTnes4J8=",
537+
"checksumSHA1": "2ydZqQU4ao+N/unf12jVRCimKsQ=",
538538
"origin": "github.com/hashicorp/terraform/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax",
539539
"path": "github.com/hashicorp/hcl2/hcl/hclsyntax",
540540
"revision": "1c95b21c6cfffc50cb6b3c3c23b2257d28b61a9c",
@@ -1034,7 +1034,7 @@
10341034
"revisionTime": "2019-04-12T11:37:27Z"
10351035
},
10361036
{
1037-
"checksumSHA1": "IK8Sgkc7FuI8iTjDZ63Jh+ZS66Y=",
1037+
"checksumSHA1": "yeqdMHNrpUPwTUF7cKQ8B7SBT1w=",
10381038
"origin": "github.com/hashicorp/terraform/vendor/github.com/ulikunitz/xz",
10391039
"path": "github.com/ulikunitz/xz",
10401040
"revision": "1c95b21c6cfffc50cb6b3c3c23b2257d28b61a9c",
@@ -1244,7 +1244,7 @@
12441244
"revisionTime": "2019-04-12T11:37:27Z"
12451245
},
12461246
{
1247-
"checksumSHA1": "sEnY0M5iGRsoXHsjHqFVLPc+OQs=",
1247+
"checksumSHA1": "3IuYjR6Fs39lJcU4N9KJFvjJx2I=",
12481248
"origin": "github.com/hashicorp/terraform/vendor/golang.org/x/sys/unix",
12491249
"path": "golang.org/x/sys/unix",
12501250
"revision": "1c95b21c6cfffc50cb6b3c3c23b2257d28b61a9c",
@@ -1265,14 +1265,14 @@
12651265
"revisionTime": "2019-04-12T11:37:27Z"
12661266
},
12671267
{
1268-
"checksumSHA1": "UwLPI4qEs8cBU0CNw+/99/F1rN0=",
1268+
"checksumSHA1": "Qw4qdlZHCnBurAPPrSt+EKPIngM=",
12691269
"origin": "github.com/hashicorp/terraform/vendor/golang.org/x/text/unicode/bidi",
12701270
"path": "golang.org/x/text/unicode/bidi",
12711271
"revision": "1c95b21c6cfffc50cb6b3c3c23b2257d28b61a9c",
12721272
"revisionTime": "2019-04-12T11:37:27Z"
12731273
},
12741274
{
1275-
"checksumSHA1": "hLP6GY9wPeMoDoLado5xKAQtXDA=",
1275+
"checksumSHA1": "gra64bhQn4joYQMtrvihqTwqkM0=",
12761276
"origin": "github.com/hashicorp/terraform/vendor/golang.org/x/text/unicode/norm",
12771277
"path": "golang.org/x/text/unicode/norm",
12781278
"revision": "1c95b21c6cfffc50cb6b3c3c23b2257d28b61a9c",

0 commit comments

Comments
 (0)