Skip to content

Commit

Permalink
network - update resources and data sources to use `hashicorp/go-az…
Browse files Browse the repository at this point in the history
…ure-sdk` (hashicorp#25971)

* update public ip resources/data sources to use go-azure-sdk

* update virtual wan and vpn gateway nat rule resources to use go-azure-sdk

* remove outdated test, update vpn gateway nat rule docs by removing deprecated properties and add false positive exception to run gradually deprecated check

* terrafmt

* update id parser in import
  • Loading branch information
stephybun authored May 16, 2024
1 parent 01c781d commit aef3bf1
Show file tree
Hide file tree
Showing 18 changed files with 623 additions and 707 deletions.
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

0 comments on commit aef3bf1

Please sign in to comment.