@@ -109,17 +109,10 @@ func resourcePolicy() *schema.Resource {
109
109
110
110
func resourcePolicyCreate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
111
111
var mutation struct {
112
- CreatePolicy structs.Policy `graphql:"policyCreate(name : $name, body: $body, type: $type, labels: $labels, space: $space, description: $description )"`
112
+ CreatePolicy structs.Policy `graphql:"policyCreatev2(input : $input )"`
113
113
}
114
114
115
- variables := map [string ]interface {}{
116
- "name" : toString (d .Get ("name" )),
117
- "body" : toString (d .Get ("body" )),
118
- "type" : structs .PolicyType (d .Get ("type" ).(string )),
119
- "labels" : (* []graphql.String )(nil ),
120
- "space" : (* graphql .ID )(nil ),
121
- "description" : toString (d .Get ("description" )),
122
- }
115
+ input := structs .NewPolicyCreateInput (toString (d .Get ("name" )), toString (d .Get ("body" )), structs .PolicyType (d .Get ("type" ).(string )))
123
116
124
117
if labelSet , ok := d .Get ("labels" ).(* schema.Set ); ok {
125
118
var labels []graphql.String
@@ -128,14 +121,20 @@ func resourcePolicyCreate(ctx context.Context, d *schema.ResourceData, meta inte
128
121
labels = append (labels , graphql .String (label .(string )))
129
122
}
130
123
131
- variables [ "labels" ] = & labels
124
+ input . Labels = & labels
132
125
}
133
126
134
127
if spaceID , ok := d .GetOk ("space_id" ); ok {
135
- variables [ "space" ] = graphql .NewID (spaceID )
128
+ input . Space = graphql .NewID (spaceID )
136
129
}
137
130
138
- if err := meta .(* internal.Client ).Mutate (ctx , "PolicyCreate" , & mutation , variables ); err != nil {
131
+ if description , ok := d .GetOk ("description" ); ok {
132
+ input .Description = toOptionalString (description )
133
+ }
134
+
135
+ variables := map [string ]interface {}{"input" : input }
136
+
137
+ if err := meta .(* internal.Client ).Mutate (ctx , "PolicyCreateV2" , & mutation , variables ); err != nil {
139
138
return diag .Errorf ("could not create policy %v: %v" , toString (d .Get ("name" )), internal .FromSpaceliftError (err ))
140
139
}
141
140
@@ -184,20 +183,13 @@ func resourcePolicyRead(ctx context.Context, d *schema.ResourceData, meta interf
184
183
185
184
func resourcePolicyUpdate (ctx context.Context , d * schema.ResourceData , meta interface {}) diag.Diagnostics {
186
185
var mutation struct {
187
- UpdatePolicy structs.Policy `graphql:"policyUpdate (id: $id, name : $name, body: $body, labels: $labels, space: $space, description: $description )"`
186
+ UpdatePolicy structs.Policy `graphql:"policyUpdatev2 (id: $id, input : $input )"`
188
187
}
189
188
190
- variables := map [string ]interface {}{
191
- "id" : toID (d .Id ()),
192
- "name" : toString (d .Get ("name" )),
193
- "description" : (* graphql .String )(nil ),
194
- "body" : toString (d .Get ("body" )),
195
- "labels" : (* []graphql.String )(nil ),
196
- "space" : (* graphql .ID )(nil ),
197
- }
189
+ input := structs .NewPolicyUpdateInput (toString (d .Get ("name" )), toString (d .Get ("body" )))
198
190
199
191
if desc , ok := d .GetOk ("description" ); ok {
200
- variables [ "description" ] = graphql . String (desc .( string ) )
192
+ input . Description = toOptionalString (desc )
201
193
}
202
194
203
195
if labelSet , ok := d .Get ("labels" ).(* schema.Set ); ok {
@@ -207,16 +199,20 @@ func resourcePolicyUpdate(ctx context.Context, d *schema.ResourceData, meta inte
207
199
labels = append (labels , graphql .String (label .(string )))
208
200
}
209
201
210
- variables [ "labels" ] = & labels
202
+ input . Labels = & labels
211
203
}
212
204
213
205
if spaceID , ok := d .GetOk ("space_id" ); ok {
214
- variables [ "space" ] = graphql .NewID (spaceID )
206
+ input . Space = graphql .NewID (spaceID )
215
207
}
216
208
217
209
var ret diag.Diagnostics
210
+ variables := map [string ]interface {}{
211
+ "id" : toID (d .Id ()),
212
+ "input" : input ,
213
+ }
218
214
219
- if err := meta .(* internal.Client ).Mutate (ctx , "PolicyUpdate " , & mutation , variables ); err != nil {
215
+ if err := meta .(* internal.Client ).Mutate (ctx , "PolicyUpdateV2 " , & mutation , variables ); err != nil {
220
216
ret = diag .Errorf ("could not update policy: %v" , internal .FromSpaceliftError (err ))
221
217
}
222
218
0 commit comments