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

network - update resources and data sources to use hashicorp/go-azure-sdk #25971

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 19 additions & 0 deletions internal/services/network/edge_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ func flattenEdgeZoneModel(input *edgezones.Model) string {
}
return edgezones.Normalize(input.Name)
}

// These will be renamed to expandEdgeZone when all calls to the former expandEdgeZone have been removed
func expandEdgeZoneNew(input string) *edgezones.Model {
normalized := edgezones.Normalize(input)
if normalized == "" {
return nil
}

return &edgezones.Model{
Name: normalized,
}
}

func flattenEdgeZoneNew(input *edgezones.Model) string {
if input == nil || input.Name == "" {
return ""
}
return edgezones.Normalize(input.Name)
}
43 changes: 22 additions & 21 deletions internal/services/network/network_security_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-09-01/networksecuritygroups"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceNetworkSecurityGroup() *pluginsdk.Resource {
Expand Down Expand Up @@ -135,43 +135,44 @@ func dataSourceNetworkSecurityGroup() *pluginsdk.Resource {
},
},

"tags": tags.SchemaDataSource(),
"tags": commonschema.TagsDataSource(),
},
}
}

func dataSourceNetworkSecurityGroupRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Network.SecurityGroupClient
client := meta.(*clients.Client).Network.NetworkSecurityGroups
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewNetworkSecurityGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := networksecuritygroups.NewNetworkSecurityGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))

resp, err := client.Get(ctx, id.ResourceGroup, id.Name, "")
resp, err := client.Get(ctx, id, networksecuritygroups.DefaultGetOperationOptions())
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("making Read request on %s: %+v", id, err)
return fmt.Errorf("retrieving %s: %+v", id, err)
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("reading request on %s: %+v", id, err)
if resp.Model == nil {
return fmt.Errorf("retrieving %s: %+v", id, err)
}
d.SetId(id.ID())

d.Set("name", resp.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.NetworkSecurityGroupName)
d.Set("resource_group_name", id.ResourceGroupName)

d.Set("location", location.NormalizeNilable(resp.Location))

if props := resp.SecurityGroupPropertiesFormat; props != nil {
flattenedRules := flattenNetworkSecurityRules(props.SecurityRules)
if err := d.Set("security_rule", flattenedRules); err != nil {
return fmt.Errorf("setting `security_rule`: %+v", err)
if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))
if props := model.Properties; props != nil {
flattenedRules := flattenNetworkSecurityRules(props.SecurityRules)
if err := d.Set("security_rule", flattenedRules); err != nil {
return fmt.Errorf("setting `security_rule`: %+v", err)
}
}
return tags.FlattenAndSet(d, model.Tags)
}

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