@@ -22,6 +22,7 @@ import (
22
22
"log"
23
23
"net/http"
24
24
"reflect"
25
+ "strings"
25
26
"time"
26
27
27
28
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -30,6 +31,11 @@ import (
30
31
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
31
32
)
32
33
34
+ func folderPrefixSuppress (_ , old , new string , d * schema.ResourceData ) bool {
35
+ prefix := "folders/"
36
+ return prefix + old == new || prefix + new == old
37
+ }
38
+
33
39
func ResourceKMSAutokeyConfig () * schema.Resource {
34
40
return & schema.Resource {
35
41
Create : resourceKMSAutokeyConfigCreate ,
@@ -49,10 +55,11 @@ func ResourceKMSAutokeyConfig() *schema.Resource {
49
55
50
56
Schema : map [string ]* schema.Schema {
51
57
"folder" : {
52
- Type : schema .TypeString ,
53
- Required : true ,
54
- ForceNew : true ,
55
- Description : `The folder for which to retrieve config.` ,
58
+ Type : schema .TypeString ,
59
+ Required : true ,
60
+ ForceNew : true ,
61
+ DiffSuppressFunc : folderPrefixSuppress ,
62
+ Description : `The folder for which to retrieve config.` ,
56
63
},
57
64
"key_project" : {
58
65
Type : schema .TypeString ,
@@ -95,6 +102,10 @@ func resourceKMSAutokeyConfigCreate(d *schema.ResourceData, meta interface{}) er
95
102
}
96
103
97
104
headers := make (http.Header )
105
+ url = strings .Replace (url , "folders/folders/" , "folders/" , 1 )
106
+ folderValue := d .Get ("folder" ).(string )
107
+ folderValue = strings .Replace (folderValue , "folders/" , "" , 1 )
108
+ d .Set ("folder" , folderValue )
98
109
res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
99
110
Config : config ,
100
111
Method : "PATCH" ,
@@ -141,6 +152,7 @@ func resourceKMSAutokeyConfigRead(d *schema.ResourceData, meta interface{}) erro
141
152
}
142
153
143
154
headers := make (http.Header )
155
+ url = strings .Replace (url , "folders/folders/" , "folders/" , 1 )
144
156
res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
145
157
Config : config ,
146
158
Method : "GET" ,
@@ -184,6 +196,7 @@ func resourceKMSAutokeyConfigUpdate(d *schema.ResourceData, meta interface{}) er
184
196
185
197
log .Printf ("[DEBUG] Updating AutokeyConfig %q: %#v" , d .Id (), obj )
186
198
headers := make (http.Header )
199
+ url = strings .Replace (url , "folders/folders/" , "folders/" , 1 )
187
200
188
201
// err == nil indicates that the billing_project value was found
189
202
if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
@@ -232,6 +245,7 @@ func resourceKMSAutokeyConfigDelete(d *schema.ResourceData, meta interface{}) er
232
245
}
233
246
234
247
headers := make (http.Header )
248
+ url = strings .Replace (url , "folders/folders/" , "folders/" , 1 )
235
249
236
250
log .Printf ("[DEBUG] Deleting AutokeyConfig %q" , d .Id ())
237
251
res , err := transport_tpg .SendRequest (transport_tpg.SendRequestOptions {
0 commit comments