Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_ip_group: parse and normalize firewall/policy id in read #24031

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions internal/services/network/ip_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,25 @@ func resourceIpGroupRead(d *pluginsdk.ResourceData, meta interface{}) error {
}
}

d.Set("firewall_ids", getIds(resp.Firewalls))
d.Set("firewall_policy_ids", getIds(resp.FirewallPolicies))
var firewallIDs []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this'll default to nil rather than []string fwiw, so we want to make this:

Suggested change
var firewallIDs []string
firewallIDs := make([]string, 0)

for _, idStr := range getIds(resp.Firewalls) {
firewallID, err := azurefirewalls.ParseAzureFirewallIDInsensitively(idStr)
if err != nil {
return fmt.Errorf("parsing Azure Firewall ID %q: %+v", idStr, err)
}
firewallIDs = append(firewallIDs, firewallID.ID())
}
d.Set("firewall_ids", firewallIDs)

var firewallPolicyIDs []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this'll default to nil rather than []string fwiw, so we want to make this:

Suggested change
var firewallPolicyIDs []string
firewallPolicyIDs := make([]string, 0)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated! I'm just wondering if the SDK treats nil and empty slices differently. Should we always provide a non-nil value when calling d.Set()?

for _, idStr := range getIds(resp.FirewallPolicies) {
policyID, err := firewallpolicies.ParseFirewallPolicyIDInsensitively(idStr)
if err != nil {
return fmt.Errorf("parsing Azure Firewall Policy ID %q: %+v", idStr, err)
}
firewallPolicyIDs = append(firewallPolicyIDs, policyID.ID())
}
d.Set("firewall_policy_ids", firewallPolicyIDs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue still exists however - particularly in the Delete but also if the validation is wrong in the Create/Update/if refresh is disabled:

  1. Update the Create function so that the Parse function raises an error when parsing fails
  2. Update the Update function so that the Parse function raises an error when parsing fails
  3. Update the Delete function so that the Parse function raises an error when parsing fails - but also to load the values from the Azure API, since we shouldn't be using d.Get in the Delete function.

As such, can we update this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and Updated!


return tags.FlattenAndSet(d, resp.Tags)
}
Expand Down
Loading