Skip to content

Commit

Permalink
Wait for firewall rule provisioning state when creating or updating r…
Browse files Browse the repository at this point in the history
…esource

Signed-off-by: Owen Farrell <[email protected]>
  • Loading branch information
owenfarrell committed Sep 28, 2021
1 parent 51a3d9d commit 66e7456
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions internal/services/synapse/synapse_firewall_rule_resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package synapse

import (
"context"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -105,9 +106,17 @@ func resourceSynapseFirewallRuleCreateUpdate(d *pluginsdk.ResourceData, meta int
return fmt.Errorf("waiting for creation/update of %s: %+v", id, err)
}

_, err = client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.Name)
if err != nil {
return fmt.Errorf("retrieving %s: %+v", id, err)
timeout, _ := ctx.Deadline()

stateConf := &pluginsdk.StateChangeConf{
Pending: []string{string(synapse.ProvisioningStateProvisioning)},
Target: []string{string(synapse.ProvisioningStateSucceeded)},
Refresh: firewallRuleProvisioningStateRefreshFunc(ctx, client, id),
MinTimeout: 1 * time.Minute,
Timeout: time.Until(timeout),
}
if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for provisioning state of %s: %+v", id, err)
}

d.SetId(id.ID())
Expand Down Expand Up @@ -169,3 +178,18 @@ func resourceSynapseFirewallRuleDelete(d *pluginsdk.ResourceData, meta interface

return nil
}

func firewallRuleProvisioningStateRefreshFunc(ctx context.Context, client *synapse.IPFirewallRulesClient, id parse.FirewallRuleId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := client.Get(ctx, id.ResourceGroup, id.WorkspaceName, id.Name)
if err != nil {
return nil, "", fmt.Errorf("polling for %s: %+v", id, err)
}

if resp.IPFirewallRuleProperties == nil {
return resp, "", fmt.Errorf("nil IPFirewallRuleProperties returned for %s", id)
}

return resp, string(resp.IPFirewallRuleProperties.ProvisioningState), nil
}
}

0 comments on commit 66e7456

Please sign in to comment.