Skip to content

Commit

Permalink
implemented pr feedback to split CreateUpdate into create and update
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-mrm committed Feb 21, 2024
1 parent 44476ef commit 2c9bd6a
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

func resourceApiManagementPolicyFragment() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceApiManagementPolicyFragmentCreateUpdate,
Create: resourceApiManagementPolicyFragmentCreate,
Read: resourceApiManagementPolicyFragmentRead,
Update: resourceApiManagementPolicyFragmentCreateUpdate,
Update: resourceApiManagementPolicyFragmentUpdate,
Delete: resourceApiManagementPolicyFragmentDelete,
Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error {
_, err := policyfragment.ParsePolicyFragmentIDInsensitively(id)
Expand Down Expand Up @@ -93,7 +93,7 @@ func resourceApiManagementPolicyFragment() *pluginsdk.Resource {
}
}

func resourceApiManagementPolicyFragmentCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
func resourceApiManagementPolicyFragmentCreate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.PolicyFragmentClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
Expand Down Expand Up @@ -136,6 +136,38 @@ func resourceApiManagementPolicyFragmentCreateUpdate(d *pluginsdk.ResourceData,
return resourceApiManagementPolicyFragmentRead(d, meta)
}

func resourceApiManagementPolicyFragmentUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.PolicyFragmentClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := policyfragment.ParsePolicyFragmentIDInsensitively(d.Get("id").(string))
if err != nil {
return err
}

format := policyfragment.PolicyFragmentContentFormat(d.Get("format").(string))

description := d.Get("description").(string)
value := d.Get("value").(string)

parameters := policyfragment.PolicyFragmentContract{
Properties: &policyfragment.PolicyFragmentContractProperties{
Description: pointer.To(description),
Format: pointer.To(format),
Value: value,
},
}

if err := client.CreateOrUpdateThenPoll(ctx, pointer.From(id), parameters, policyfragment.CreateOrUpdateOperationOptions{}); err != nil {
return fmt.Errorf("creating/updating %s: %+v", id, err)
}

d.SetId(id.ID())

return resourceApiManagementPolicyFragmentRead(d, meta)
}

func resourceApiManagementPolicyFragmentRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.PolicyFragmentClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
Expand Down

0 comments on commit 2c9bd6a

Please sign in to comment.