Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_vpn_server_configuration_policy_group - split create and update
Browse files Browse the repository at this point in the history
mbfrahry committed Jun 3, 2024

Verified

This commit was signed with the committer’s verified signature.
dhruvkb Dhruv Bhanushali
1 parent 64a989a commit d3083b8
Showing 1 changed file with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@ import (

func resourceVPNServerConfigurationPolicyGroup() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceVPNServerConfigurationPolicyGroupCreateUpdate,
Create: resourceVPNServerConfigurationPolicyGroupCreate,
Read: resourceVPNServerConfigurationPolicyGroupRead,
Update: resourceVPNServerConfigurationPolicyGroupCreateUpdate,
Update: resourceVPNServerConfigurationPolicyGroupUpdate,
Delete: resourceVPNServerConfigurationPolicyGroupDelete,

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
@@ -101,10 +101,10 @@ func resourceVPNServerConfigurationPolicyGroup() *pluginsdk.Resource {
}
}

func resourceVPNServerConfigurationPolicyGroupCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
func resourceVPNServerConfigurationPolicyGroupCreate(d *pluginsdk.ResourceData, meta interface{}) error {
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
client := meta.(*clients.Client).Network.VirtualWANs
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

vpnServerConfigurationId, err := virtualwans.ParseVpnServerConfigurationID(d.Get("vpn_server_configuration_id").(string))
@@ -117,17 +117,15 @@ func resourceVPNServerConfigurationPolicyGroupCreateUpdate(d *pluginsdk.Resource

id := virtualwans.NewConfigurationPolicyGroupID(subscriptionId, vpnServerConfigurationId.ResourceGroupName, vpnServerConfigurationId.VpnServerConfigurationName, d.Get("name").(string))

if d.IsNewResource() {
existing, err := client.ConfigurationPolicyGroupsGet(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for existing %s: %+v", id, err)
}
}
existing, err := client.ConfigurationPolicyGroupsGet(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_vpn_server_configuration_policy_group", id.ID())
return fmt.Errorf("checking for existing %s: %+v", id, err)
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_vpn_server_configuration_policy_group", id.ID())
}

payload := virtualwans.VpnServerConfigurationPolicyGroup{
Properties: &virtualwans.VpnServerConfigurationPolicyGroupProperties{
@@ -138,7 +136,7 @@ func resourceVPNServerConfigurationPolicyGroupCreateUpdate(d *pluginsdk.Resource
}

if err := client.ConfigurationPolicyGroupsCreateOrUpdateThenPoll(ctx, id, payload); err != nil {
return fmt.Errorf("creating/updating %s: %+v", id, err)
return fmt.Errorf("creating %s: %+v", id, err)
}

d.SetId(id.ID())
@@ -184,6 +182,49 @@ func resourceVPNServerConfigurationPolicyGroupRead(d *pluginsdk.ResourceData, me
return nil
}

func resourceVPNServerConfigurationPolicyGroupUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Network.VirtualWANs
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := virtualwans.ParseConfigurationPolicyGroupID(d.Id())
if err != nil {
return err
}

vpnServerConfigurationId := virtualwans.NewVpnServerConfigurationID(id.SubscriptionId, id.ResourceGroupName, id.VpnServerConfigurationName)

locks.ByID(vpnServerConfigurationId.ID())
defer locks.UnlockByID(vpnServerConfigurationId.ID())

existing, err := client.ConfigurationPolicyGroupsGet(ctx, *id)

Check failure on line 200 in internal/services/network/vpn_server_configuration_policy_group_resource.go

GitHub Actions / golint

ineffectual assignment to err (ineffassign)

if existing.Model == nil {
return fmt.Errorf("retrieving %s: `model` was nil", id)
}

if existing.Model.Properties == nil {
return fmt.Errorf("retrieving %s: `properties` was nil", id)
}

payload := existing.Model

if d.HasChange("policy") {
payload.Properties.PolicyMembers = expandVPNServerConfigurationPolicyGroupPolicyMembers(d.Get("policy").(*pluginsdk.Set).List())
}

if d.HasChange("priority") {
payload.Properties.Priority = pointer.To(int64(d.Get("priority").(int)))
}

if err := client.ConfigurationPolicyGroupsCreateOrUpdateThenPoll(ctx, *id, *payload); err != nil {
return fmt.Errorf("updating %s: %+v", id, err)
}

d.SetId(id.ID())
return resourceVPNServerConfigurationPolicyGroupRead(d, meta)
}

func resourceVPNServerConfigurationPolicyGroupDelete(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Network.VirtualWANs
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)

0 comments on commit d3083b8

Please sign in to comment.