-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Dependency:] azurerm_cdn_frontdoor_*
- update dependencies to use 2024-02-01
API
#28233
Changes from 2 commits
c1d5995
9e457b0
3d5f220
bbff7bd
39d4fd1
2b75a3d
10953b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,14 +7,14 @@ import ( | |||||||||||||
"fmt" | ||||||||||||||
"time" | ||||||||||||||
|
||||||||||||||
"github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2020-11-01/frontdoor" // nolint: staticcheck | ||||||||||||||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||||||||||||||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||||||||||||||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||||||||||||||
waf "github.com/hashicorp/go-azure-sdk/resource-manager/frontdoor/2024-02-01/webapplicationfirewallpolicies" | ||||||||||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||||||||||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse" | ||||||||||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/validate" | ||||||||||||||
"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 dataSourceCdnFrontDoorFirewallPolicy() *pluginsdk.Resource { | ||||||||||||||
|
@@ -66,42 +66,59 @@ func dataSourceCdnFrontDoorFirewallPolicy() *pluginsdk.Resource { | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
func dataSourceCdnFrontDoorFirewallPolicyRead(d *pluginsdk.ResourceData, meta interface{}) error { | ||||||||||||||
client := meta.(*clients.Client).Cdn.FrontDoorLegacyFirewallPoliciesClient | ||||||||||||||
client := meta.(*clients.Client).Cdn.FrontDoorFirewallPoliciesClient | ||||||||||||||
subscriptionId := meta.(*clients.Client).Account.SubscriptionId | ||||||||||||||
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) | ||||||||||||||
defer cancel() | ||||||||||||||
|
||||||||||||||
id := parse.NewFrontDoorFirewallPolicyID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) | ||||||||||||||
name := d.Get("name").(string) | ||||||||||||||
resourceGroup := d.Get("resource_group_name").(string) | ||||||||||||||
|
||||||||||||||
resp, err := client.Get(ctx, id.ResourceGroup, id.FrontDoorWebApplicationFirewallPolicyName) | ||||||||||||||
id := waf.NewFrontDoorWebApplicationFirewallPolicyID(subscriptionId, resourceGroup, name) | ||||||||||||||
|
||||||||||||||
result, err := client.PoliciesGet(ctx, id) | ||||||||||||||
if err != nil { | ||||||||||||||
if utils.ResponseWasNotFound(resp.Response) { | ||||||||||||||
if !response.WasNotFound(result.HttpResponse) { | ||||||||||||||
return fmt.Errorf("%s was not found", id) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return fmt.Errorf("retrieving %s: %+v", id, err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
model := result.Model | ||||||||||||||
|
||||||||||||||
if model == nil { | ||||||||||||||
return fmt.Errorf("retrieving %s: 'model' was nil", id) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if model.Sku == nil { | ||||||||||||||
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", id) | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a behavioural change? lines 86-87 below just set this if it's not
Suggested change
(maybe in the appropriate place below) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||||||||||||
|
||||||||||||||
if model.Properties == nil { | ||||||||||||||
return fmt.Errorf("retrieving %s: 'model.Properties' was nil", id) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
props := model.Properties | ||||||||||||||
|
||||||||||||||
skuName := "" | ||||||||||||||
if sku := resp.Sku; sku != nil { | ||||||||||||||
skuName = string(sku.Name) | ||||||||||||||
if sku := model.Sku; sku != nil { | ||||||||||||||
skuName = string(pointer.From(model.Sku.Name)) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
d.SetId(id.ID()) | ||||||||||||||
d.Set("name", id.FrontDoorWebApplicationFirewallPolicyName) | ||||||||||||||
d.Set("resource_group_name", id.ResourceGroup) | ||||||||||||||
d.Set("resource_group_name", id.ResourceGroupName) | ||||||||||||||
d.Set("sku_name", skuName) | ||||||||||||||
|
||||||||||||||
if properties := resp.WebApplicationFirewallPolicyProperties; properties != nil { | ||||||||||||||
if policy := properties.PolicySettings; policy != nil { | ||||||||||||||
d.Set("enabled", policy.EnabledState == frontdoor.PolicyEnabledStateEnabled) | ||||||||||||||
d.Set("mode", string(policy.Mode)) | ||||||||||||||
d.Set("redirect_url", policy.RedirectURL) | ||||||||||||||
} | ||||||||||||||
if policy := props.PolicySettings; policy != nil { | ||||||||||||||
d.Set("enabled", pointer.From(policy.EnabledState) == waf.PolicyEnabledStateEnabled) | ||||||||||||||
d.Set("mode", pointer.From(policy.Mode)) | ||||||||||||||
d.Set("redirect_url", policy.RedirectURL) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if err := d.Set("frontend_endpoint_ids", flattenFrontendEndpointLinkSlice(properties.FrontendEndpointLinks)); err != nil { | ||||||||||||||
return fmt.Errorf("flattening 'frontend_endpoint_ids': %+v", err) | ||||||||||||||
} | ||||||||||||||
if err := d.Set("frontend_endpoint_ids", flattenFrontendEndpointLinkSlice(props.FrontendEndpointLinks)); err != nil { | ||||||||||||||
return fmt.Errorf("flattening 'frontend_endpoint_ids': %+v", err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return nil | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern we've been adopting for
Read
when migrating togo-azure-sdk
is to do all thed.Set()
etc inside the nil check for he model, e.g.Comprehensive example from AKS here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.