From d7673cd58294fac61ea2f8e7204b122a947d42d4 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 5 Dec 2024 01:39:04 -0700 Subject: [PATCH] First pass at deprecating legacy 2021-06-01 API from touched resources... --- .../cdn/cdn_frontdoor_profile_resource.go | 47 +--- .../cdn_frontdoor_security_policy_resource.go | 232 ++++++++++++------ ...frontdoor_security_policy_resource_test.go | 12 +- internal/services/cdn/client/client.go | 12 +- .../cdn_frontdoor_security_params.go | 120 --------- .../cdn/2024-02-01/securitypolicies/README.md | 99 ++++++++ .../cdn/2024-02-01/securitypolicies/client.go | 26 ++ .../2024-02-01/securitypolicies/constants.go | 145 +++++++++++ .../2024-02-01/securitypolicies/id_profile.go | 130 ++++++++++ .../securitypolicies/id_securitypolicy.go | 139 +++++++++++ .../securitypolicies/method_create.go | 76 ++++++ .../securitypolicies/method_delete.go | 71 ++++++ .../2024-02-01/securitypolicies/method_get.go | 53 ++++ .../securitypolicies/method_listbyprofile.go | 105 ++++++++ .../securitypolicies/method_patch.go | 75 ++++++ .../model_activatedresourcereference.go | 9 + .../model_resourcereference.go | 8 + .../securitypolicies/model_securitypolicy.go | 16 ++ .../model_securitypolicyproperties.go | 48 ++++ ...odel_securitypolicypropertiesparameters.go | 75 ++++++ .../model_securitypolicyupdateparameters.go | 8 + .../model_securitypolicyupdateproperties.go | 33 +++ ...policywebapplicationfirewallassociation.go | 9 + ...ypolicywebapplicationfirewallparameters.go | 51 ++++ .../2024-02-01/securitypolicies/predicates.go | 27 ++ .../2024-02-01/securitypolicies/version.go | 10 + vendor/modules.txt | 1 + 27 files changed, 1403 insertions(+), 234 deletions(-) delete mode 100644 internal/services/cdn/frontdoorsecurityparams/cdn_frontdoor_security_params.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_create.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_get.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicy.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/version.go diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource.go b/internal/services/cdn/cdn_frontdoor_profile_resource.go index 0d130adc2636..1f26f5c0afb8 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource.go @@ -15,7 +15,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "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/tf/validation" @@ -37,7 +36,7 @@ func resourceCdnFrontDoorProfile() *pluginsdk.Resource { }, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.FrontDoorProfileID(id) + _, err := profiles.ParseProfileID(id) return err }), @@ -86,15 +85,9 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewFrontDoorProfileID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := profiles.NewProfileID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - profileId := profiles.ProfileId{ - SubscriptionId: id.SubscriptionId, - ResourceGroupName: id.ResourceGroup, - ProfileName: id.ProfileName, - } - - existing, err := client.Get(ctx, profileId) + existing, err := client.Get(ctx, id) if err != nil { if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for existing %s: %+v", id, err) @@ -125,7 +118,7 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface props.Identity = i } - err = client.CreateThenPoll(ctx, profileId, props) + err = client.CreateThenPoll(ctx, id, props) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) } @@ -139,18 +132,12 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FrontDoorProfileID(d.Id()) + id, err := profiles.ParseProfileID(d.Id()) if err != nil { return err } - profileId := profiles.ProfileId{ - SubscriptionId: id.SubscriptionId, - ResourceGroupName: id.ResourceGroup, - ProfileName: id.ProfileName, - } - - resp, err := client.Get(ctx, profileId) + resp, err := client.Get(ctx, pointer.From(id)) if err != nil { if response.WasNotFound(resp.HttpResponse) { d.SetId("") @@ -160,7 +147,7 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} } d.Set("name", id.ProfileName) - d.Set("resource_group_name", id.ResourceGroup) + d.Set("resource_group_name", id.ResourceGroupName) model := resp.Model @@ -203,17 +190,11 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FrontDoorProfileID(d.Id()) + id, err := profiles.ParseProfileID(d.Id()) if err != nil { return err } - profileId := profiles.ProfileId{ - SubscriptionId: id.SubscriptionId, - ResourceGroupName: id.ResourceGroup, - ProfileName: id.ProfileName, - } - props := profiles.ProfileUpdateParameters{ Tags: expandNewFrontDoorTagsPointer(d.Get("tags").(map[string]interface{})), Properties: &profiles.ProfilePropertiesUpdateParameters{}, @@ -232,7 +213,7 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface props.Identity = i } - err = client.UpdateThenPoll(ctx, profileId, props) + err = client.UpdateThenPoll(ctx, pointer.From(id), props) if err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } @@ -245,18 +226,12 @@ func resourceCdnFrontDoorProfileDelete(d *pluginsdk.ResourceData, meta interface ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FrontDoorProfileID(d.Id()) + id, err := profiles.ParseProfileID(d.Id()) if err != nil { return err } - profileId := profiles.ProfileId{ - SubscriptionId: id.SubscriptionId, - ResourceGroupName: id.ResourceGroup, - ProfileName: id.ProfileName, - } - - err = client.DeleteThenPoll(ctx, profileId) + err = client.DeleteThenPoll(ctx, pointer.From(id)) if err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) } diff --git a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go index 5f8103e1582e..c3695c8100d5 100644 --- a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go +++ b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go @@ -8,12 +8,12 @@ import ( "strings" "time" - "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - cdnfrontdoorsecurityparams "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/frontdoorsecurityparams" "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" @@ -35,7 +35,7 @@ func resourceCdnFrontDoorSecurityPolicy() *pluginsdk.Resource { }, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.FrontDoorSecurityPolicyID(id) + _, err := securitypolicies.ParseSecurityPolicyID(id) return err }), @@ -145,35 +145,30 @@ func resourceCdnFrontdoorSecurityPolicyCreate(d *pluginsdk.ResourceData, meta in defer cancel() // NOTE: The profile id is used to retrieve properties from the related profile that must match in this security policy - profile, 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 } - profileId := profiles.ProfileId{ - SubscriptionId: profile.SubscriptionId, - ResourceGroupName: profile.ResourceGroup, - ProfileName: profile.ProfileName, - } - securityPolicyName := d.Get("name").(string) - id := parse.NewFrontDoorSecurityPolicyID(profile.SubscriptionId, profile.ResourceGroup, profile.ProfileName, securityPolicyName) - existing, err := client.Get(ctx, id.ResourceGroup, id.ProfileName, id.SecurityPolicyName) + id := securitypolicies.NewSecurityPolicyID(profileId.SubscriptionId, profileId.ResourceGroupName, profileId.ProfileName, securityPolicyName) + + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for existing %s: %+v", id, err) } } - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return tf.ImportAsExistsError("azurerm_cdn_frontdoor_security_policy", id.ID()) } profileClient := meta.(*clients.Client).Cdn.FrontDoorProfilesClient - resp, err := profileClient.Get(ctx, profileId) + resp, err := profileClient.Get(ctx, pointer.From(profileId)) if err != nil { - return fmt.Errorf("unable to retrieve the 'sku_name' from the CDN FrontDoor Profile(Name: %q)': %+v", profile.ProfileName, err) + return fmt.Errorf("unable to retrieve the 'sku_name' from the CDN FrontDoor Profile(Name: %q)': %+v", profileId.ProfileName, err) } profileModel := resp.Model @@ -192,26 +187,22 @@ func resourceCdnFrontdoorSecurityPolicyCreate(d *pluginsdk.ResourceData, meta in isStandardSku := strings.HasPrefix(strings.ToLower(string(pointer.From(profileModel.Sku.Name))), "standard") - params, err := cdnfrontdoorsecurityparams.ExpandCdnFrontdoorFirewallPolicyParameters(d.Get("security_policies").([]interface{}), isStandardSku) + params, err := expandCdnFrontdoorFirewallPolicyParameters(d.Get("security_policies").([]interface{}), isStandardSku) if err != nil { return fmt.Errorf("expanding 'security_policies': %+v", err) } - props := cdn.SecurityPolicy{ - SecurityPolicyProperties: &cdn.SecurityPolicyProperties{ + props := securitypolicies.SecurityPolicy{ + Properties: &securitypolicies.SecurityPolicyProperties{ Parameters: params, }, } - future, err := client.Create(ctx, id.ResourceGroup, id.ProfileName, id.SecurityPolicyName, props) + err = client.CreateThenPoll(ctx, id, props) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the creation of %s: %+v", id, err) - } - d.SetId(id.ID()) return resourceCdnFrontdoorSecurityPolicyRead(d, meta) } @@ -221,14 +212,14 @@ func resourceCdnFrontdoorSecurityPolicyRead(d *pluginsdk.ResourceData, meta inte ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FrontDoorSecurityPolicyID(d.Id()) + id, err := securitypolicies.ParseSecurityPolicyID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName, id.SecurityPolicyName) + resp, err := client.Get(ctx, pointer.From(id)) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { d.SetId("") return nil } @@ -236,55 +227,63 @@ func resourceCdnFrontdoorSecurityPolicyRead(d *pluginsdk.ResourceData, meta inte } d.Set("name", id.SecurityPolicyName) - 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.ResourceGroupName, id.ProfileName).ID()) - if props := resp.SecurityPolicyProperties; props != nil { - waf, ok := props.Parameters.AsSecurityPolicyWebApplicationFirewallParameters() - if !ok { - return fmt.Errorf("flattening %s: %s", id, "expected security policy web application firewall parameters") - } + model := resp.Model - // we know it's a firewall policy at this point, - // create the objects to hold the policy data - associations := make([]interface{}, 0) + if model == nil { + return fmt.Errorf("model is 'nil'") + } - wafPolicyId := "" - if waf.WafPolicy != nil && waf.WafPolicy.ID != nil { - parsedId, err := parse.FrontDoorFirewallPolicyIDInsensitively(*waf.WafPolicy.ID) - if err != nil { - return fmt.Errorf("flattening `cdn_frontdoor_firewall_policy_id`: %+v", err) - } - wafPolicyId = parsedId.ID() + if model.Properties == nil { + return fmt.Errorf("model.Properties is 'nil'") + } + + if model.Properties.Parameters.SecurityPolicyPropertiesParameters().Type != securitypolicies.SecurityPolicyTypeWebApplicationFirewall { + return fmt.Errorf("'model.Properties.Parameters.Type' of %q is unexpected, want security policy 'Type' of 'WebApplicationFirewall': %s", model.Properties.Parameters.SecurityPolicyPropertiesParameters().Type, id) + } + + // we know it's a firewall policy at this point, + // create the objects to hold the policy data + waf := model.Properties.Parameters.(securitypolicies.SecurityPolicyWebApplicationFirewallParameters) + associations := make([]interface{}, 0) + wafPolicyId := "" + + if waf.WafPolicy != nil && waf.WafPolicy.Id != nil { + parsedId, err := securitypolicies.ParseSecurityPolicyIDInsensitively(*waf.WafPolicy.Id) + if err != nil { + return fmt.Errorf("flattening `cdn_frontdoor_firewall_policy_id`: %+v", err) } + wafPolicyId = parsedId.ID() + } - if waf.Associations != nil { - for _, item := range *waf.Associations { - domain, err := cdnfrontdoorsecurityparams.FlattenSecurityPoliciesActivatedResourceReference(item.Domains) - if err != nil { - return fmt.Errorf("flattening `ActivatedResourceReference`: %+v", err) - } - - associations = append(associations, map[string]interface{}{ - "domain": domain, - "patterns_to_match": utils.FlattenStringSlice(item.PatternsToMatch), - }) + if waf.Associations != nil { + for _, item := range *waf.Associations { + domain, err := flattenSecurityPoliciesActivatedResourceReference(item.Domains) + if err != nil { + return fmt.Errorf("flattening `ActivatedResourceReference`: %+v", err) } + + associations = append(associations, map[string]interface{}{ + "domain": domain, + "patterns_to_match": utils.FlattenStringSlice(item.PatternsToMatch), + }) } + } - securityPolicy := []interface{}{ - map[string]interface{}{ - "firewall": []interface{}{ - map[string]interface{}{ - "association": associations, - "cdn_frontdoor_firewall_policy_id": wafPolicyId, - }, + securityPolicy := []interface{}{ + map[string]interface{}{ + "firewall": []interface{}{ + map[string]interface{}{ + "association": associations, + "cdn_frontdoor_firewall_policy_id": wafPolicyId, }, }, - } - - d.Set("security_policies", securityPolicy) + }, } + d.Set("security_policies", securityPolicy) + return nil } @@ -293,19 +292,114 @@ func resourceCdnFrontdoorSecurityPolicyDelete(d *pluginsdk.ResourceData, meta in ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FrontDoorSecurityPolicyID(d.Id()) + id, err := securitypolicies.ParseSecurityPolicyID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.ProfileName, id.SecurityPolicyName) + err = client.DeleteThenPoll(ctx, pointer.From(id)) if err != nil { return fmt.Errorf("deleting %s: %+v", *id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the deletion of %s: %+v", *id, err) + return nil +} + +func expandCdnFrontdoorFirewallPolicyParameters(input []interface{}, isStandardSku bool) (*securitypolicies.SecurityPolicyWebApplicationFirewallParameters, error) { + results := securitypolicies.SecurityPolicyWebApplicationFirewallParameters{} + if len(input) == 0 { + return &results, nil } - return nil + associations := make([]securitypolicies.SecurityPolicyWebApplicationFirewallAssociation, 0) + + // pull off only the firewall policy from the security_policies list + policyType := input[0].(map[string]interface{}) + firewallPolicy := policyType["firewall"].([]interface{}) + v := firewallPolicy[0].(map[string]interface{}) + + if id := v["cdn_frontdoor_firewall_policy_id"].(string); id != "" { + results.WafPolicy = &securitypolicies.ResourceReference{ + Id: utils.String(id), + } + } + + configAssociations := v["association"].([]interface{}) + + for _, item := range configAssociations { + v := item.(map[string]interface{}) + domains := expandSecurityPoliciesActivatedResourceReference(v["domain"].([]interface{})) + + if isStandardSku { + if len(*domains) > 100 { + return &results, fmt.Errorf("the 'Standard_AzureFrontDoor' sku is only allowed to have 100 or less domains associated with the firewall policy, got %d", len(*domains)) + } + } else { + if len(*domains) > 500 { + return &results, fmt.Errorf("the 'Premium_AzureFrontDoor' sku is only allowed to have 500 or less domains associated with the firewall policy, got %d", len(*domains)) + } + } + + association := securitypolicies.SecurityPolicyWebApplicationFirewallAssociation{ + Domains: domains, + PatternsToMatch: utils.ExpandStringSlice(v["patterns_to_match"].([]interface{})), + } + + associations = append(associations, association) + } + + results.Associations = &associations + + return &results, nil +} + +func expandSecurityPoliciesActivatedResourceReference(input []interface{}) *[]securitypolicies.ActivatedResourceReference { + results := make([]securitypolicies.ActivatedResourceReference, 0) + if len(input) == 0 { + return &results + } + + for _, item := range input { + v := item.(map[string]interface{}) + + if id := v["cdn_frontdoor_domain_id"].(string); id != "" { + results = append(results, securitypolicies.ActivatedResourceReference{ + Id: utils.String(id), + }) + } + } + + return &results +} + +func flattenSecurityPoliciesActivatedResourceReference(input *[]securitypolicies.ActivatedResourceReference) ([]interface{}, error) { + results := make([]interface{}, 0) + if input == nil { + return results, nil + } + + for _, item := range *input { + frontDoorDomainId := "" + if item.Id != nil { + if parsedFrontDoorCustomDomainId, frontDoorCustomDomainIdErr := parse.FrontDoorCustomDomainIDInsensitively(*item.Id); frontDoorCustomDomainIdErr == nil { + frontDoorDomainId = parsedFrontDoorCustomDomainId.ID() + } else if parsedFrontDoorEndpointId, frontDoorEndpointIdErr := parse.FrontDoorEndpointIDInsensitively(*item.Id); frontDoorEndpointIdErr == nil { + frontDoorDomainId = parsedFrontDoorEndpointId.ID() + } else { + return nil, fmt.Errorf("flattening `cdn_frontdoor_domain_id`: %+v; %+v", frontDoorCustomDomainIdErr, frontDoorEndpointIdErr) + } + } + + active := false + if item.IsActive != nil { + active = *item.IsActive + } + + results = append(results, map[string]interface{}{ + "active": active, + "cdn_frontdoor_domain_id": frontDoorDomainId, + }) + } + + return results, nil } diff --git a/internal/services/cdn/cdn_frontdoor_security_policy_resource_test.go b/internal/services/cdn/cdn_frontdoor_security_policy_resource_test.go index 92f8198889d3..613d7ece54b2 100644 --- a/internal/services/cdn/cdn_frontdoor_security_policy_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_security_policy_resource_test.go @@ -8,10 +8,12 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "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/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -103,18 +105,18 @@ func TestAccCdnFrontDoorSecurityPolicy_completeEndpoint(t *testing.T) { } func (r CdnFrontDoorSecurityPolicyResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.FrontDoorSecurityPolicyID(state.ID) + id, err := securitypolicies.ParseSecurityPolicyID(state.ID) if err != nil { return nil, err } client := clients.Cdn.FrontDoorSecurityPoliciesClient - resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName, id.SecurityPolicyName) + resp, err := client.Get(ctx, pointer.From(id)) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return utils.Bool(false), nil } - return nil, fmt.Errorf("retrieving %s: %+v", id, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } return utils.Bool(true), nil diff --git a/internal/services/cdn/client/client.go b/internal/services/cdn/client/client.go index fb8823fe4c82..10465b4f59ec 100644 --- a/internal/services/cdn/client/client.go +++ b/internal/services/cdn/client/client.go @@ -10,6 +10,7 @@ import ( cdnFrontDoorSdk "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck "github.com/Azure/azure-sdk-for-go/services/frontdoor/mgmt/2020-11-01/frontdoor" // nolint: staticcheck "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" + "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -18,7 +19,7 @@ type Client struct { FrontDoorOriginGroupsClient *cdnFrontDoorSdk.AFDOriginGroupsClient FrontDoorOriginsClient *cdnFrontDoorSdk.AFDOriginsClient FrontDoorCustomDomainsClient *cdnFrontDoorSdk.AFDCustomDomainsClient - FrontDoorSecurityPoliciesClient *cdnFrontDoorSdk.SecurityPoliciesClient + FrontDoorSecurityPoliciesClient *securitypolicies.SecurityPoliciesClient FrontDoorRoutesClient *cdnFrontDoorSdk.RoutesClient FrontDoorRulesClient *cdnFrontDoorSdk.RulesClient FrontDoorProfilesClient *profiles.ProfilesClient @@ -49,8 +50,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) { frontDoorCustomDomainsClient := cdnFrontDoorSdk.NewAFDCustomDomainsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&frontDoorCustomDomainsClient.Client, o.ResourceManagerAuthorizer) - frontDoorPolicySecurityPoliciesClient := cdnFrontDoorSdk.NewSecurityPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&frontDoorPolicySecurityPoliciesClient.Client, o.ResourceManagerAuthorizer) + frontDoorSecurityPoliciesClient, err := securitypolicies.NewSecurityPoliciesClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building SecurityPoliciesClient: %+v", err) + } + o.Configure(frontDoorSecurityPoliciesClient.Client, o.Authorizers.ResourceManager) frontDoorLegacyFirewallPoliciesClient := frontdoor.NewPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&frontDoorLegacyFirewallPoliciesClient.Client, o.ResourceManagerAuthorizer) @@ -81,7 +85,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { FrontDoorOriginGroupsClient: &frontDoorOriginGroupsClient, FrontDoorOriginsClient: &frontDoorOriginsClient, FrontDoorCustomDomainsClient: &frontDoorCustomDomainsClient, - FrontDoorSecurityPoliciesClient: &frontDoorPolicySecurityPoliciesClient, + FrontDoorSecurityPoliciesClient: frontDoorSecurityPoliciesClient, FrontDoorRoutesClient: &frontDoorRoutesClient, FrontDoorRulesClient: &frontDoorRulesClient, FrontDoorProfilesClient: frontDoorProfilesClient, diff --git a/internal/services/cdn/frontdoorsecurityparams/cdn_frontdoor_security_params.go b/internal/services/cdn/frontdoorsecurityparams/cdn_frontdoor_security_params.go deleted file mode 100644 index 56ee0910881e..000000000000 --- a/internal/services/cdn/frontdoorsecurityparams/cdn_frontdoor_security_params.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package cdnfrontdoorsecurityparams - -import ( - "fmt" - - "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck - "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse" - "github.com/hashicorp/terraform-provider-azurerm/utils" -) - -type CdnFrontdoorSecurityParameters struct { - TypeName cdn.Type - ConfigName string -} - -type CdnFrontdoorSecurityMappings struct { - Firewall CdnFrontdoorSecurityParameters -} - -func ExpandCdnFrontdoorFirewallPolicyParameters(input []interface{}, isStandardSku bool) (*cdn.SecurityPolicyWebApplicationFirewallParameters, error) { - results := cdn.SecurityPolicyWebApplicationFirewallParameters{} - if len(input) == 0 { - return &results, nil - } - - associations := make([]cdn.SecurityPolicyWebApplicationFirewallAssociation, 0) - - // pull off only the firewall policy from the security_policies list - policyType := input[0].(map[string]interface{}) - firewallPolicy := policyType["firewall"].([]interface{}) - v := firewallPolicy[0].(map[string]interface{}) - - if id := v["cdn_frontdoor_firewall_policy_id"].(string); id != "" { - results.WafPolicy = &cdn.ResourceReference{ - ID: utils.String(id), - } - } - - configAssociations := v["association"].([]interface{}) - - for _, item := range configAssociations { - v := item.(map[string]interface{}) - domains := expandSecurityPoliciesActivatedResourceReference(v["domain"].([]interface{})) - - if isStandardSku { - if len(*domains) > 100 { - return &results, fmt.Errorf("the 'Standard_AzureFrontDoor' sku is only allowed to have 100 or less domains associated with the firewall policy, got %d", len(*domains)) - } - } else { - if len(*domains) > 500 { - return &results, fmt.Errorf("the 'Premium_AzureFrontDoor' sku is only allowed to have 500 or less domains associated with the firewall policy, got %d", len(*domains)) - } - } - - association := cdn.SecurityPolicyWebApplicationFirewallAssociation{ - Domains: domains, - PatternsToMatch: utils.ExpandStringSlice(v["patterns_to_match"].([]interface{})), - } - - associations = append(associations, association) - } - - results.Associations = &associations - - return &results, nil -} - -func expandSecurityPoliciesActivatedResourceReference(input []interface{}) *[]cdn.ActivatedResourceReference { - results := make([]cdn.ActivatedResourceReference, 0) - if len(input) == 0 { - return &results - } - - for _, item := range input { - v := item.(map[string]interface{}) - - if id := v["cdn_frontdoor_domain_id"].(string); id != "" { - results = append(results, cdn.ActivatedResourceReference{ - ID: utils.String(id), - }) - } - } - - return &results -} - -func FlattenSecurityPoliciesActivatedResourceReference(input *[]cdn.ActivatedResourceReference) ([]interface{}, error) { - results := make([]interface{}, 0) - if input == nil { - return results, nil - } - - for _, item := range *input { - frontDoorDomainId := "" - if item.ID != nil { - if parsedFrontDoorCustomDomainId, frontDoorCustomDomainIdErr := parse.FrontDoorCustomDomainIDInsensitively(*item.ID); frontDoorCustomDomainIdErr == nil { - frontDoorDomainId = parsedFrontDoorCustomDomainId.ID() - } else if parsedFrontDoorEndpointId, frontDoorEndpointIdErr := parse.FrontDoorEndpointIDInsensitively(*item.ID); frontDoorEndpointIdErr == nil { - frontDoorDomainId = parsedFrontDoorEndpointId.ID() - } else { - return nil, fmt.Errorf("flattening `cdn_frontdoor_domain_id`: %+v; %+v", frontDoorCustomDomainIdErr, frontDoorEndpointIdErr) - } - } - - active := false - if item.IsActive != nil { - active = *item.IsActive - } - - results = append(results, map[string]interface{}{ - "active": active, - "cdn_frontdoor_domain_id": frontDoorDomainId, - }) - } - - return results, nil -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/README.md new file mode 100644 index 000000000000..f1231501df96 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/README.md @@ -0,0 +1,99 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies` Documentation + +The `securitypolicies` SDK allows for interaction with Azure Resource Manager `cdn` (API Version `2024-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies" +``` + + +### Client Initialization + +```go +client := securitypolicies.NewSecurityPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `SecurityPoliciesClient.Create` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName", "securityPolicyName") + +payload := securitypolicies.SecurityPolicy{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecurityPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName", "securityPolicyName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `SecurityPoliciesClient.Get` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName", "securityPolicyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `SecurityPoliciesClient.ListByProfile` + +```go +ctx := context.TODO() +id := securitypolicies.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +// alternatively `client.ListByProfile(ctx, id)` can be used to do batched pagination +items, err := client.ListByProfileComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `SecurityPoliciesClient.Patch` + +```go +ctx := context.TODO() +id := securitypolicies.NewSecurityPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName", "securityPolicyName") + +payload := securitypolicies.SecurityPolicyUpdateParameters{ + // ... +} + + +if err := client.PatchThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/client.go new file mode 100644 index 000000000000..55cc8c476cb4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/client.go @@ -0,0 +1,26 @@ +package securitypolicies + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewSecurityPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*SecurityPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "securitypolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating SecurityPoliciesClient: %+v", err) + } + + return &SecurityPoliciesClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/constants.go new file mode 100644 index 000000000000..7354c2cb3267 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/constants.go @@ -0,0 +1,145 @@ +package securitypolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AfdProvisioningState string + +const ( + AfdProvisioningStateCreating AfdProvisioningState = "Creating" + AfdProvisioningStateDeleting AfdProvisioningState = "Deleting" + AfdProvisioningStateFailed AfdProvisioningState = "Failed" + AfdProvisioningStateSucceeded AfdProvisioningState = "Succeeded" + AfdProvisioningStateUpdating AfdProvisioningState = "Updating" +) + +func PossibleValuesForAfdProvisioningState() []string { + return []string{ + string(AfdProvisioningStateCreating), + string(AfdProvisioningStateDeleting), + string(AfdProvisioningStateFailed), + string(AfdProvisioningStateSucceeded), + string(AfdProvisioningStateUpdating), + } +} + +func (s *AfdProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseAfdProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseAfdProvisioningState(input string) (*AfdProvisioningState, error) { + vals := map[string]AfdProvisioningState{ + "creating": AfdProvisioningStateCreating, + "deleting": AfdProvisioningStateDeleting, + "failed": AfdProvisioningStateFailed, + "succeeded": AfdProvisioningStateSucceeded, + "updating": AfdProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AfdProvisioningState(input) + return &out, nil +} + +type DeploymentStatus string + +const ( + DeploymentStatusFailed DeploymentStatus = "Failed" + DeploymentStatusInProgress DeploymentStatus = "InProgress" + DeploymentStatusNotStarted DeploymentStatus = "NotStarted" + DeploymentStatusSucceeded DeploymentStatus = "Succeeded" +) + +func PossibleValuesForDeploymentStatus() []string { + return []string{ + string(DeploymentStatusFailed), + string(DeploymentStatusInProgress), + string(DeploymentStatusNotStarted), + string(DeploymentStatusSucceeded), + } +} + +func (s *DeploymentStatus) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseDeploymentStatus(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseDeploymentStatus(input string) (*DeploymentStatus, error) { + vals := map[string]DeploymentStatus{ + "failed": DeploymentStatusFailed, + "inprogress": DeploymentStatusInProgress, + "notstarted": DeploymentStatusNotStarted, + "succeeded": DeploymentStatusSucceeded, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := DeploymentStatus(input) + return &out, nil +} + +type SecurityPolicyType string + +const ( + SecurityPolicyTypeWebApplicationFirewall SecurityPolicyType = "WebApplicationFirewall" +) + +func PossibleValuesForSecurityPolicyType() []string { + return []string{ + string(SecurityPolicyTypeWebApplicationFirewall), + } +} + +func (s *SecurityPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSecurityPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSecurityPolicyType(input string) (*SecurityPolicyType, error) { + vals := map[string]SecurityPolicyType{ + "webapplicationfirewall": SecurityPolicyTypeWebApplicationFirewall, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SecurityPolicyType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go new file mode 100644 index 000000000000..0b3e853a5865 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_profile.go @@ -0,0 +1,130 @@ +package securitypolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ProfileId{}) +} + +var _ resourceids.ResourceId = &ProfileId{} + +// ProfileId is a struct representing the Resource ID for a Profile +type ProfileId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string +} + +// NewProfileID returns a new ProfileId struct +func NewProfileID(subscriptionId string, resourceGroupName string, profileName string) ProfileId { + return ProfileId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + } +} + +// ParseProfileID parses 'input' into a ProfileId +func ParseProfileID(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseProfileIDInsensitively parses 'input' case-insensitively into a ProfileId +// note: this method should only be used for API response data and not user input +func ParseProfileIDInsensitively(input string) (*ProfileId, error) { + parser := resourceids.NewParserFromResourceIdType(&ProfileId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ProfileId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ProfileId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + return nil +} + +// ValidateProfileID checks that 'input' can be parsed as a Profile ID +func ValidateProfileID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseProfileID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Profile ID +func (id ProfileId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Profile ID +func (id ProfileId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileName"), + } +} + +// String returns a human-readable description of this Profile ID +func (id ProfileId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + } + return fmt.Sprintf("Profile (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy.go new file mode 100644 index 000000000000..f1972a729555 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/id_securitypolicy.go @@ -0,0 +1,139 @@ +package securitypolicies + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&SecurityPolicyId{}) +} + +var _ resourceids.ResourceId = &SecurityPolicyId{} + +// SecurityPolicyId is a struct representing the Resource ID for a Security Policy +type SecurityPolicyId struct { + SubscriptionId string + ResourceGroupName string + ProfileName string + SecurityPolicyName string +} + +// NewSecurityPolicyID returns a new SecurityPolicyId struct +func NewSecurityPolicyID(subscriptionId string, resourceGroupName string, profileName string, securityPolicyName string) SecurityPolicyId { + return SecurityPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ProfileName: profileName, + SecurityPolicyName: securityPolicyName, + } +} + +// ParseSecurityPolicyID parses 'input' into a SecurityPolicyId +func ParseSecurityPolicyID(input string) (*SecurityPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseSecurityPolicyIDInsensitively parses 'input' case-insensitively into a SecurityPolicyId +// note: this method should only be used for API response data and not user input +func ParseSecurityPolicyIDInsensitively(input string) (*SecurityPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&SecurityPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := SecurityPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *SecurityPolicyId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ProfileName, ok = input.Parsed["profileName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "profileName", input) + } + + if id.SecurityPolicyName, ok = input.Parsed["securityPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "securityPolicyName", input) + } + + return nil +} + +// ValidateSecurityPolicyID checks that 'input' can be parsed as a Security Policy ID +func ValidateSecurityPolicyID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseSecurityPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Security Policy ID +func (id SecurityPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CDN/profiles/%s/securityPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ProfileName, id.SecurityPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Security Policy ID +func (id SecurityPolicyId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftCDN", "Microsoft.CDN", "Microsoft.CDN"), + resourceids.StaticSegment("staticProfiles", "profiles", "profiles"), + resourceids.UserSpecifiedSegment("profileName", "profileName"), + resourceids.StaticSegment("staticSecurityPolicies", "securityPolicies", "securityPolicies"), + resourceids.UserSpecifiedSegment("securityPolicyName", "securityPolicyName"), + } +} + +// String returns a human-readable description of this Security Policy ID +func (id SecurityPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Profile Name: %q", id.ProfileName), + fmt.Sprintf("Security Policy Name: %q", id.SecurityPolicyName), + } + return fmt.Sprintf("Security Policy (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_create.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_create.go new file mode 100644 index 000000000000..a95ec9d76fdd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_create.go @@ -0,0 +1,76 @@ +package securitypolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Create ... +func (c SecurityPoliciesClient) Create(ctx context.Context, id SecurityPolicyId, input SecurityPolicy) (result CreateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateThenPoll performs Create then polls until it's completed +func (c SecurityPoliciesClient) CreateThenPoll(ctx context.Context, id SecurityPolicyId, input SecurityPolicy) error { + result, err := c.Create(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Create: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Create: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go new file mode 100644 index 000000000000..9367d103c071 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_delete.go @@ -0,0 +1,71 @@ +package securitypolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c SecurityPoliciesClient) Delete(ctx context.Context, id SecurityPolicyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c SecurityPoliciesClient) DeleteThenPoll(ctx context.Context, id SecurityPolicyId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_get.go new file mode 100644 index 000000000000..c6e380485b20 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_get.go @@ -0,0 +1,53 @@ +package securitypolicies + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Get ... +func (c SecurityPoliciesClient) Get(ctx context.Context, id SecurityPolicyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model SecurityPolicy + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go new file mode 100644 index 000000000000..322dbf96b304 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_listbyprofile.go @@ -0,0 +1,105 @@ +package securitypolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByProfileOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]SecurityPolicy +} + +type ListByProfileCompleteResult struct { + LatestHttpResponse *http.Response + Items []SecurityPolicy +} + +type ListByProfileCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByProfileCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByProfile ... +func (c SecurityPoliciesClient) ListByProfile(ctx context.Context, id ProfileId) (result ListByProfileOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByProfileCustomPager{}, + Path: fmt.Sprintf("%s/securityPolicies", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]SecurityPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByProfileComplete retrieves all the results into a single object +func (c SecurityPoliciesClient) ListByProfileComplete(ctx context.Context, id ProfileId) (ListByProfileCompleteResult, error) { + return c.ListByProfileCompleteMatchingPredicate(ctx, id, SecurityPolicyOperationPredicate{}) +} + +// ListByProfileCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c SecurityPoliciesClient) ListByProfileCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate SecurityPolicyOperationPredicate) (result ListByProfileCompleteResult, err error) { + items := make([]SecurityPolicy, 0) + + resp, err := c.ListByProfile(ctx, id) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByProfileCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go new file mode 100644 index 000000000000..c0f9a10b2033 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/method_patch.go @@ -0,0 +1,75 @@ +package securitypolicies + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PatchOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *SecurityPolicy +} + +// Patch ... +func (c SecurityPoliciesClient) Patch(ctx context.Context, id SecurityPolicyId, input SecurityPolicyUpdateParameters) (result PatchOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPatch, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// PatchThenPoll performs Patch then polls until it's completed +func (c SecurityPoliciesClient) PatchThenPoll(ctx context.Context, id SecurityPolicyId, input SecurityPolicyUpdateParameters) error { + result, err := c.Patch(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Patch: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Patch: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go new file mode 100644 index 000000000000..98cdc9bedc95 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_activatedresourcereference.go @@ -0,0 +1,9 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ActivatedResourceReference struct { + Id *string `json:"id,omitempty"` + IsActive *bool `json:"isActive,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go new file mode 100644 index 000000000000..d51464823938 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_resourcereference.go @@ -0,0 +1,8 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceReference struct { + Id *string `json:"id,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicy.go new file mode 100644 index 000000000000..798a87168df7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicy.go @@ -0,0 +1,16 @@ +package securitypolicies + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicy struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *SecurityPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go new file mode 100644 index 000000000000..44b1c010941c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyproperties.go @@ -0,0 +1,48 @@ +package securitypolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyProperties struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + Parameters SecurityPolicyPropertiesParameters `json:"parameters"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` +} + +var _ json.Unmarshaler = &SecurityPolicyProperties{} + +func (s *SecurityPolicyProperties) UnmarshalJSON(bytes []byte) error { + var decoded struct { + DeploymentStatus *DeploymentStatus `json:"deploymentStatus,omitempty"` + ProfileName *string `json:"profileName,omitempty"` + ProvisioningState *AfdProvisioningState `json:"provisioningState,omitempty"` + } + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + + s.DeploymentStatus = decoded.DeploymentStatus + s.ProfileName = decoded.ProfileName + s.ProvisioningState = decoded.ProvisioningState + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SecurityPolicyProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["parameters"]; ok { + impl, err := UnmarshalSecurityPolicyPropertiesParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Parameters' for 'SecurityPolicyProperties': %+v", err) + } + s.Parameters = impl + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go new file mode 100644 index 000000000000..05ae120b4d48 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicypropertiesparameters.go @@ -0,0 +1,75 @@ +package securitypolicies + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyPropertiesParameters interface { + SecurityPolicyPropertiesParameters() BaseSecurityPolicyPropertiesParametersImpl +} + +var _ SecurityPolicyPropertiesParameters = BaseSecurityPolicyPropertiesParametersImpl{} + +type BaseSecurityPolicyPropertiesParametersImpl struct { + Type SecurityPolicyType `json:"type"` +} + +func (s BaseSecurityPolicyPropertiesParametersImpl) SecurityPolicyPropertiesParameters() BaseSecurityPolicyPropertiesParametersImpl { + return s +} + +var _ SecurityPolicyPropertiesParameters = RawSecurityPolicyPropertiesParametersImpl{} + +// RawSecurityPolicyPropertiesParametersImpl is returned when the Discriminated Value doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawSecurityPolicyPropertiesParametersImpl struct { + securityPolicyPropertiesParameters BaseSecurityPolicyPropertiesParametersImpl + Type string + Values map[string]interface{} +} + +func (s RawSecurityPolicyPropertiesParametersImpl) SecurityPolicyPropertiesParameters() BaseSecurityPolicyPropertiesParametersImpl { + return s.securityPolicyPropertiesParameters +} + +func UnmarshalSecurityPolicyPropertiesParametersImplementation(input []byte) (SecurityPolicyPropertiesParameters, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityPolicyPropertiesParameters into map[string]interface: %+v", err) + } + + var value string + if v, ok := temp["type"]; ok { + value = fmt.Sprintf("%v", v) + } + + if strings.EqualFold(value, "WebApplicationFirewall") { + var out SecurityPolicyWebApplicationFirewallParameters + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + return out, nil + } + + var parent BaseSecurityPolicyPropertiesParametersImpl + if err := json.Unmarshal(input, &parent); err != nil { + return nil, fmt.Errorf("unmarshaling into BaseSecurityPolicyPropertiesParametersImpl: %+v", err) + } + + return RawSecurityPolicyPropertiesParametersImpl{ + securityPolicyPropertiesParameters: parent, + Type: value, + Values: temp, + }, nil + +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go new file mode 100644 index 000000000000..c9ee59519599 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateparameters.go @@ -0,0 +1,8 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyUpdateParameters struct { + Properties *SecurityPolicyUpdateProperties `json:"properties,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go new file mode 100644 index 000000000000..231a621fb7a0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicyupdateproperties.go @@ -0,0 +1,33 @@ +package securitypolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyUpdateProperties struct { + Parameters SecurityPolicyPropertiesParameters `json:"parameters"` +} + +var _ json.Unmarshaler = &SecurityPolicyUpdateProperties{} + +func (s *SecurityPolicyUpdateProperties) UnmarshalJSON(bytes []byte) error { + + var temp map[string]json.RawMessage + if err := json.Unmarshal(bytes, &temp); err != nil { + return fmt.Errorf("unmarshaling SecurityPolicyUpdateProperties into map[string]json.RawMessage: %+v", err) + } + + if v, ok := temp["parameters"]; ok { + impl, err := UnmarshalSecurityPolicyPropertiesParametersImplementation(v) + if err != nil { + return fmt.Errorf("unmarshaling field 'Parameters' for 'SecurityPolicyUpdateProperties': %+v", err) + } + s.Parameters = impl + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go new file mode 100644 index 000000000000..78cfbe4a2598 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallassociation.go @@ -0,0 +1,9 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyWebApplicationFirewallAssociation struct { + Domains *[]ActivatedResourceReference `json:"domains,omitempty"` + PatternsToMatch *[]string `json:"patternsToMatch,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go new file mode 100644 index 000000000000..26581196cc87 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/model_securitypolicywebapplicationfirewallparameters.go @@ -0,0 +1,51 @@ +package securitypolicies + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ SecurityPolicyPropertiesParameters = SecurityPolicyWebApplicationFirewallParameters{} + +type SecurityPolicyWebApplicationFirewallParameters struct { + Associations *[]SecurityPolicyWebApplicationFirewallAssociation `json:"associations,omitempty"` + WafPolicy *ResourceReference `json:"wafPolicy,omitempty"` + + // Fields inherited from SecurityPolicyPropertiesParameters + + Type SecurityPolicyType `json:"type"` +} + +func (s SecurityPolicyWebApplicationFirewallParameters) SecurityPolicyPropertiesParameters() BaseSecurityPolicyPropertiesParametersImpl { + return BaseSecurityPolicyPropertiesParametersImpl{ + Type: s.Type, + } +} + +var _ json.Marshaler = SecurityPolicyWebApplicationFirewallParameters{} + +func (s SecurityPolicyWebApplicationFirewallParameters) MarshalJSON() ([]byte, error) { + type wrapper SecurityPolicyWebApplicationFirewallParameters + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + + var decoded map[string]interface{} + if err = json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + + decoded["type"] = "WebApplicationFirewall" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling SecurityPolicyWebApplicationFirewallParameters: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go new file mode 100644 index 000000000000..4b70b7eef24c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/predicates.go @@ -0,0 +1,27 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SecurityPolicyOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p SecurityPolicyOperationPredicate) Matches(input SecurityPolicy) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/version.go new file mode 100644 index 000000000000..16b6141b4c07 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies/version.go @@ -0,0 +1,10 @@ +package securitypolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-02-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/securitypolicies/2024-02-01" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index a6b0c01ffff3..941ebd3f5e50 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -310,6 +310,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/blueprints/2018-11-01-preview github.com/hashicorp/go-azure-sdk/resource-manager/blueprints/2018-11-01-preview/publishedblueprint github.com/hashicorp/go-azure-sdk/resource-manager/botservice/2022-09-15/channel github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles +github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/securitypolicies github.com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01 github.com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01/capabilities github.com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01/capabilitytypes