Skip to content

Commit

Permalink
dependencies - frontdoor - partial update to use 2024-02-01 API (h…
Browse files Browse the repository at this point in the history
…ashicorp#28233)

* Initial Check-in...

* Fix lint errors...

* Address PR comments...

* Include 2024-09-01/rules API for SslProtocol type definition...

* Add webapplicationfirewallpolicies import to security policy resource...

* Remove resource id for deprecated resource...

* Address latest PR comments...
  • Loading branch information
WodansSon authored Dec 13, 2024
1 parent 65fd4ea commit e751874
Show file tree
Hide file tree
Showing 191 changed files with 12,642 additions and 1,123 deletions.
4 changes: 3 additions & 1 deletion internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,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
14 changes: 8 additions & 6 deletions internal/services/cdn/cdn_frontdoor_custom_domain_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles"
dnsValidate "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/zones"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -120,9 +121,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 All @@ -138,12 +140,12 @@ func resourceCdnFrontDoorCustomDomainCreate(d *pluginsdk.ResourceData, meta inte
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

profileId, err := parse.FrontDoorProfileID(d.Get("cdn_frontdoor_profile_id").(string))
profileId, err := profiles.ParseProfileID(d.Get("cdn_frontdoor_profile_id").(string))
if err != nil {
return err
}

id := parse.NewFrontDoorCustomDomainID(profileId.SubscriptionId, profileId.ResourceGroup, profileId.ProfileName, d.Get("name").(string))
id := parse.NewFrontDoorCustomDomainID(profileId.SubscriptionId, profileId.ResourceGroupName, profileId.ProfileName, d.Get("name").(string))

existing, err := client.Get(ctx, id.ResourceGroup, id.ProfileName, id.CustomDomainName)
if err != nil {
Expand Down Expand Up @@ -211,7 +213,7 @@ func resourceCdnFrontDoorCustomDomainRead(d *pluginsdk.ResourceData, meta interf
}

d.Set("name", id.CustomDomainName)
d.Set("cdn_frontdoor_profile_id", parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName).ID())
d.Set("cdn_frontdoor_profile_id", profiles.NewProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName).ID())

if props := resp.AFDDomainProperties; props != nil {
d.Set("host_name", props.HostName)
Expand Down
49 changes: 26 additions & 23 deletions internal/services/cdn/cdn_frontdoor_firewall_policy_data_source.go
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,41 +66,44 @@ 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)
}

skuName := ""
if sku := resp.Sku; sku != nil {
skuName = string(sku.Name)
}

d.SetId(id.ID())
d.Set("name", id.FrontDoorWebApplicationFirewallPolicyName)
d.Set("resource_group_name", id.ResourceGroup)
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 model := result.Model; model != nil {
d.Set("name", id.FrontDoorWebApplicationFirewallPolicyName)
d.Set("resource_group_name", id.ResourceGroupName)
if sku := model.Sku; sku != nil {
d.Set("sku_name", string(pointer.From(sku.Name)))
}

if err := d.Set("frontend_endpoint_ids", flattenFrontendEndpointLinkSlice(properties.FrontendEndpointLinks)); err != nil {
return fmt.Errorf("flattening 'frontend_endpoint_ids': %+v", err)
if props := model.Properties; props != nil {
if err := d.Set("frontend_endpoint_ids", flattenFrontendEndpointLinkSlice(props.FrontendEndpointLinks)); err != nil {
return fmt.Errorf("flattening 'frontend_endpoint_ids': %+v", err)
}

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)
}
}
}

Expand Down
Loading

0 comments on commit e751874

Please sign in to comment.