Skip to content

Commit 807121a

Browse files
committed
Finish code
1 parent 3e8e653 commit 807121a

File tree

2 files changed

+51
-16
lines changed

2 files changed

+51
-16
lines changed

internal/services/storageactions/registration.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func (r Registration) DataSources() []sdk.DataSource {
3232
}
3333

3434
func (r Registration) Resources() []sdk.Resource {
35-
return []sdk.Resource{}
35+
return []sdk.Resource{
36+
StorageActionsStorageTaskResource{},
37+
}
3638
}
3739

3840
func (r Registration) Actions() []func() action.Action {

internal/services/storageactions/storage_task_resource.go

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1212
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
1313
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
14-
"github.com/hashicorp/go-azure-sdk/resource-manager/storageactions/2023-01-01/storageactions"
1514
"github.com/hashicorp/go-azure-sdk/resource-manager/storageactions/2023-01-01/storagetasks"
1615
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
1716
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
@@ -40,11 +39,11 @@ type StorageActionsStorageTaskActionModel struct {
4039

4140
type StorageActionsStorageTaskActionIfModel struct {
4241
Condition string `tfschema:"condition"`
43-
Operations []StorageActionsStorageTaskOperationModel `tfschema:"operations"`
42+
Operations []StorageActionsStorageTaskOperationModel `tfschema:"operation"`
4443
}
4544

4645
type StorageActionsStorageTaskActionElseModel struct {
47-
Operations []StorageActionsStorageTaskOperationModel `tfschema:"operations"`
46+
Operations []StorageActionsStorageTaskOperationModel `tfschema:"operation"`
4847
}
4948

5049
type StorageActionsStorageTaskOperationModel struct {
@@ -83,7 +82,7 @@ func (r StorageActionsStorageTaskResource) Arguments() map[string]*pluginsdk.Sch
8382
Required: true,
8483
ValidateFunc: validation.StringIsNotEmpty,
8584
},
86-
"operations": {
85+
"operation": {
8786
Type: pluginsdk.TypeList,
8887
Required: true,
8988
MinItems: 1,
@@ -109,7 +108,7 @@ func (r StorageActionsStorageTaskResource) Arguments() map[string]*pluginsdk.Sch
109108
Optional: true,
110109
Elem: &pluginsdk.Resource{
111110
Schema: map[string]*pluginsdk.Schema{
112-
"operations": {
111+
"operation": {
113112
Type: pluginsdk.TypeList,
114113
Required: true,
115114
MinItems: 1,
@@ -155,7 +154,7 @@ func (r StorageActionsStorageTaskResource) ResourceType() string {
155154
return "azurerm_storage_task"
156155
}
157156

158-
func (r StorageActionsStorageTaskResource) ModelObject() interface{} {
157+
func (r StorageActionsStorageTaskResource) ModelObject() any {
159158
return &StorageActionsStorageTaskModel{}
160159
}
161160

@@ -188,7 +187,7 @@ func (r StorageActionsStorageTaskResource) Create() sdk.ResourceFunc {
188187

189188
identityModel, err := identity.ExpandLegacySystemAndUserAssignedMapFromModel(model.Identity)
190189
if err != nil {
191-
return fmt.Errorf("expanding the system and user assigned identity: %v", err)
190+
return fmt.Errorf("expanding the `identity`: %v", err)
192191
}
193192

194193
params := storagetasks.StorageTask{
@@ -231,12 +230,28 @@ func (r StorageActionsStorageTaskResource) Read() sdk.ResourceFunc {
231230
return fmt.Errorf("retrieving %s: %+v", id, err)
232231
}
233232

234-
model := StorageActionsStorageTaskModel{}
233+
model := StorageActionsStorageTaskModel{
234+
Name: id.StorageTaskName,
235+
ResourceGroup: id.ResourceGroupName,
236+
}
235237

236238
if respModel := resp.Model; respModel != nil {
239+
model.Location = location.Normalize(respModel.Location)
240+
241+
identity, err := identity.FlattenLegacySystemAndUserAssignedMapToModel(&respModel.Identity)
242+
if err != nil {
243+
return fmt.Errorf("flattening `identity`: %v", err)
244+
}
245+
model.Identity = identity
246+
237247
if tags := respModel.Tags; tags != nil {
238248
model.Tags = *respModel.Tags
239249
}
250+
251+
props := respModel.Properties
252+
model.Action = r.flattenAction(&props.Action)
253+
model.Description = props.Description
254+
model.Enabled = props.Enabled
240255
}
241256

242257
return metadata.Encode(&model)
@@ -270,11 +285,29 @@ func (r StorageActionsStorageTaskResource) Update() sdk.ResourceFunc {
270285

271286
params := *existing.Model
272287

273-
// TODO: update the params
274-
// if props := params.Properties; props != nil {
275-
// if metadata.ResourceData.HasChange("xxx") {
276-
// props.Xxx = plan.Xxx
277-
// }
288+
if metadata.ResourceData.HasChange("identity") {
289+
identityModel, err := identity.ExpandLegacySystemAndUserAssignedMapFromModel(model.Identity)
290+
if err != nil {
291+
return fmt.Errorf("expanding the `identity`: %v", err)
292+
}
293+
params.Identity = *identityModel
294+
}
295+
296+
if metadata.ResourceData.HasChange("action") {
297+
params.Properties.Action = r.expandAction(model.Action)
298+
}
299+
300+
if metadata.ResourceData.HasChange("enabled") {
301+
params.Properties.Enabled = model.Enabled
302+
}
303+
304+
if metadata.ResourceData.HasChange("description") {
305+
params.Properties.Description = model.Description
306+
}
307+
308+
if metadata.ResourceData.HasChange("tags") {
309+
params.Tags = &model.Tags
310+
}
278311

279312
if err := client.CreateThenPoll(ctx, *id, params); err != nil {
280313
return fmt.Errorf("updating %s: %+v", id, err)
@@ -395,10 +428,10 @@ func (r StorageActionsStorageTaskResource) expandAction(input []StorageActionsSt
395428

396429
// This is guaranteed by the schema definition, but added here anyway to avoid panic.
397430
if ifCondition == nil {
398-
return nil
431+
return storagetasks.StorageTaskAction{}
399432
}
400433

401-
return &storagetasks.StorageTaskAction{
434+
return storagetasks.StorageTaskAction{
402435
If: *ifCondition,
403436
Else: r.expandElse(model.Else),
404437
}

0 commit comments

Comments
 (0)