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

[Dependency:] azurerm_cdn_frontdoor_* - update dependencies to use 2024-02-01 API #28233

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
if client.Bot, err = bot.NewClient(o); err != nil {
return fmt.Errorf("building clients for Bot: %+v", err)
}
client.Cdn = cdn.NewClient(o)
if client.Cdn, err = cdn.NewClient(o); err != nil {
return fmt.Errorf("building clients for Cdn: %+v", err)
}
if client.CodeSigning, err = codesigning.NewClient(o); err != nil {
return fmt.Errorf("building clients for Code Signing: %+v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ func resourceCdnFrontDoorCustomDomain() *pluginsdk.Resource {

if !features.FivePointOhBeta() {
resource.Schema["tls"].Elem.(*pluginsdk.Resource).Schema["minimum_tls_version"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdMinimumTLSVersionTLS12),
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdMinimumTLSVersionTLS12),
Deprecated: "As of March 1, 2025, support for 'TLS10' will be retired from Azure Front Door, therefore the 'TLS10' property value will be removed in v5.0 of the provider.",
ValidateFunc: validation.StringInSlice([]string{
string(cdn.AfdMinimumTLSVersionTLS12),
string(cdn.AfdMinimumTLSVersionTLS10),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Copy link
Member

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 to go-azure-sdk is to do all the d.Set() etc inside the nil check for he model, e.g.

	if model := result.Model; model != nil {
		if props := model.Properties; props != nil {
			// TODO all the `d.Set("props_thing", props.Thing)` stuff
		}
		// TODO - all the `d.Set("top_level_prop", model.Prop)`
	}

Comprehensive example from AKS here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.


if model.Sku == nil {
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", id)
}
Copy link
Member

Choose a reason for hiding this comment

The 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 nil, rather than returning an error, we should probably keep this the same? something like:

Suggested change
if model.Sku == nil {
return fmt.Errorf("retrieving %s: 'model.Sku' was nil", id)
}
if sku := model.Sku; sku != nil {
d.Set("sku_name", pointer.From(sku.Name))
}

(maybe in the appropriate place below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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
Expand Down
Loading
Loading