From 755ef72abb4ff7ff210bc9be90f74391a2df8b5f Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Tue, 19 Nov 2024 01:10:50 -0700 Subject: [PATCH 01/10] Initial check-in to upgrade the AFD Profile API to 2024-02-01... --- internal/clients/client.go | 4 +- .../services/cdn/cdn_frontdoor_helpers.go | 33 ++ .../cdn/cdn_frontdoor_origin_resource.go | 66 ++- .../cdn/cdn_frontdoor_profile_data_source.go | 46 +- .../cdn/cdn_frontdoor_profile_resource.go | 103 ++-- .../cdn_frontdoor_profile_resource_test.go | 12 +- .../cdn/cdn_frontdoor_rule_resource.go | 2 +- .../cdn_frontdoor_security_policy_resource.go | 26 +- internal/services/cdn/client/client.go | 22 +- .../cdn/2024-02-01/profiles/README.md | 212 ++++++++ .../cdn/2024-02-01/profiles/client.go | 26 + .../cdn/2024-02-01/profiles/constants.go | 489 ++++++++++++++++++ .../cdn/2024-02-01/profiles/id_profile.go | 130 +++++ .../2024-02-01/profiles/method_canmigrate.go | 76 +++ .../cdn/2024-02-01/profiles/method_create.go | 76 +++ .../cdn/2024-02-01/profiles/method_delete.go | 71 +++ .../profiles/method_generatessouri.go | 54 ++ .../cdn/2024-02-01/profiles/method_get.go | 53 ++ .../cdn/2024-02-01/profiles/method_list.go | 106 ++++ .../profiles/method_listbyresourcegroup.go | 106 ++++ .../profiles/method_listresourceusage.go | 105 ++++ .../method_listsupportedoptimizationtypes.go | 54 ++ .../cdn/2024-02-01/profiles/method_migrate.go | 76 +++ .../profiles/method_migrationcommit.go | 70 +++ .../cdn/2024-02-01/profiles/method_update.go | 75 +++ .../profiles/model_canmigrateparameters.go | 8 + .../profiles/model_canmigrateproperties.go | 10 + .../profiles/model_canmigrateresult.go | 10 + .../profiles/model_migrateresult.go | 10 + .../profiles/model_migrateresultproperties.go | 8 + .../profiles/model_migrationerrortype.go | 11 + .../profiles/model_migrationparameters.go | 11 + ..._migrationwebapplicationfirewallmapping.go | 9 + .../cdn/2024-02-01/profiles/model_profile.go | 22 + .../profiles/model_profilelogscrubbing.go | 9 + .../profiles/model_profileproperties.go | 13 + ...model_profilepropertiesupdateparameters.go | 9 + .../profiles/model_profilescrubbingrules.go | 11 + .../profiles/model_profileupdateparameters.go | 14 + .../profiles/model_resourcereference.go | 8 + .../profiles/model_resourceusage.go | 11 + .../cdn/2024-02-01/profiles/model_sku.go | 8 + .../cdn/2024-02-01/profiles/model_ssouri.go | 8 + ...el_supportedoptimizationtypeslistresult.go | 8 + .../cdn/2024-02-01/profiles/predicates.go | 60 +++ .../cdn/2024-02-01/profiles/version.go | 10 + vendor/modules.txt | 1 + 47 files changed, 2276 insertions(+), 86 deletions(-) create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/id_profile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_canmigrate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_create.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_delete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_generatessouri.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_get.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_list.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_update.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profile.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourceusage.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_sku.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/version.go diff --git a/internal/clients/client.go b/internal/clients/client.go index 2cc0295a7ec6..e70defbfa1da 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -354,7 +354,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) } diff --git a/internal/services/cdn/cdn_frontdoor_helpers.go b/internal/services/cdn/cdn_frontdoor_helpers.go index dc554f51efe8..6d3d304a2297 100644 --- a/internal/services/cdn/cdn_frontdoor_helpers.go +++ b/internal/services/cdn/cdn_frontdoor_helpers.go @@ -9,6 +9,7 @@ import ( "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-helpers/lang/pointer" dnsValidate "github.com/hashicorp/go-azure-sdk/resource-manager/dns/2018-05-01/zones" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/features" @@ -109,6 +110,38 @@ func flattenHttpsRedirectToBool(input cdn.HTTPSRedirect) bool { return input == cdn.HTTPSRedirectEnabled } +func expandNewFrontDoorTagsPointer(tagMap map[string]interface{}) *map[string]string { + t := make(map[string]string) + + if tagMap != nil { + for k, v := range tagMap { + tagKey := k + tagValue := v + t[tagKey] = tagValue.(string) + } + } + + return pointer.To(t) +} + +func flattenNewFrontDoorTags(tagMap *map[string]string) map[string]interface{} { + if tagMap == nil { + return make(map[string]interface{}, 0) + } + + t := make(map[string]interface{}, len(*tagMap)) + + for k, v := range *tagMap { + if v == "" { + continue + } + + t[k] = v + } + + return t +} + func expandFrontDoorTags(tagMap *map[string]string) map[string]*string { t := make(map[string]*string) diff --git a/internal/services/cdn/cdn_frontdoor_origin_resource.go b/internal/services/cdn/cdn_frontdoor_origin_resource.go index 5a0086f66a40..592f3420042d 100644 --- a/internal/services/cdn/cdn_frontdoor_origin_resource.go +++ b/internal/services/cdn/cdn_frontdoor_origin_resource.go @@ -8,8 +8,11 @@ import ( "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-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + cdnProfile "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-11-01/privatelinkservices" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -202,21 +205,37 @@ func resourceCdnFrontDoorOriginCreate(d *pluginsdk.ResourceData, meta interface{ // I need to get the profile SKU so I know if it is valid or not to define a private link as // private links are only allowed in the premium sku... - profileId := parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName) + profile := parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName) - profile, err := profileClient.Get(ctx, profileId.ResourceGroup, profileId.ProfileName) + profileId := cdnProfile.ProfileId{ + SubscriptionId: profile.SubscriptionId, + ResourceGroupName: profile.ResourceGroup, + ProfileName: profile.ProfileName, + } + + profileResp, err := profileClient.Get(ctx, profileId) if err != nil { - if utils.ResponseWasNotFound(profile.Response) { + if response.WasNotFound(profileResp.HttpResponse) { return fmt.Errorf("retrieving parent %s: not found", profileId) } return fmt.Errorf("retrieving parent %s: %+v", profileId, err) } - if profile.Sku == nil { - return fmt.Errorf("retrieving parent %s: 'sku' was nil", profileId) + profileModel := profileResp.Model + + if profileModel == nil { + return fmt.Errorf("profileModel is 'nil'") + } + + if profileModel.Properties == nil { + return fmt.Errorf("profileModel.Properties is 'nil'") + } + + if profileModel.Sku.Name == nil { + return fmt.Errorf("profileModel.Sku.Name' is 'nil'") } - skuName := profile.Sku.Name + skuName := string(pointer.From(profileModel.Sku.Name)) var enabled bool if !features.FourPointOhBeta() { @@ -241,7 +260,7 @@ func resourceCdnFrontDoorOriginCreate(d *pluginsdk.ResourceData, meta interface{ props.OriginHostHeader = utils.String(originHostHeader) } - expanded, err := expandPrivateLinkSettings(d.Get("private_link").([]interface{}), skuName, enableCertNameCheck) + expanded, err := expandPrivateLinkSettings(d.Get("private_link").([]interface{}), cdn.SkuName(skuName), enableCertNameCheck) if err != nil { return err } @@ -357,21 +376,38 @@ func resourceCdnFrontDoorOriginUpdate(d *pluginsdk.ResourceData, meta interface{ if d.HasChange("private_link") { // I need to get the profile SKU so I know if it is valid or not to define a private link as // private links are only allowed in the premium sku... - profileId := parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName) - profile, err := profileClient.Get(ctx, profileId.ResourceGroup, profileId.ProfileName) + profile := parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName) + + profileId := cdnProfile.ProfileId{ + SubscriptionId: profile.SubscriptionId, + ResourceGroupName: profile.ResourceGroup, + ProfileName: profile.ProfileName, + } + + profileResp, err := profileClient.Get(ctx, profileId) if err != nil { - if utils.ResponseWasNotFound(profile.Response) { - return fmt.Errorf("retrieving parent %s: not found", profileId) + if response.WasNotFound(profileResp.HttpResponse) { + d.SetId("") + return nil } + return fmt.Errorf("retrieving %s: %+v", profile, err) + } + + profileModel := profileResp.Model + + if profileModel == nil { + return fmt.Errorf("profileModel is 'nil'") + } - return fmt.Errorf("retrieving parent %s: %+v", profileId, err) + if profileModel.Properties == nil { + return fmt.Errorf("profileModel.Properties is 'nil'") } - if profile.Sku == nil { - return fmt.Errorf("retrieving parent %s: 'sku' was nil", profileId) + if profileModel.Sku.Name == nil { + return fmt.Errorf("retrieving parent %s: 'profileModel.Sku.Name' was 'nil'", profile) } - skuName := profile.Sku.Name + skuName := cdn.SkuName(pointer.From(profileModel.Sku.Name)) enableCertNameCheck := d.Get("certificate_name_check_enabled").(bool) privateLinkSettings, err := expandPrivateLinkSettings(d.Get("private_link").([]interface{}), skuName, enableCertNameCheck) diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source.go b/internal/services/cdn/cdn_frontdoor_profile_data_source.go index 2cbf7fb91055..f787b9e7586e 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source.go @@ -7,14 +7,15 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + cdn "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func dataSourceCdnFrontDoorProfile() *pluginsdk.Resource { @@ -61,35 +62,48 @@ func dataSourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface defer cancel() id := parse.NewFrontDoorProfileID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName) + + profileId := cdn.ProfileId{ + SubscriptionId: id.SubscriptionId, + ResourceGroupName: id.ResourceGroup, + ProfileName: id.ProfileName, + } + + resp, err := client.Get(ctx, profileId) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return fmt.Errorf("%s was not found", id) } return fmt.Errorf("retrieving %s: %+v", id, err) } + model := resp.Model + + if model == nil { + return fmt.Errorf("model is 'nil'") + } + + if model.Properties == nil { + return fmt.Errorf("model.Properties is 'nil'") + } + d.SetId(id.ID()) d.Set("name", id.ProfileName) d.Set("resource_group_name", id.ResourceGroup) - if props := resp.ProfileProperties; props != nil { - d.Set("response_timeout_seconds", props.OriginResponseTimeoutSeconds) + d.Set("response_timeout_seconds", int(pointer.From(model.Properties.OriginResponseTimeoutSeconds))) - // whilst this is returned in the API as FrontDoorID other resources refer to - // this as the Resource GUID, so we will for consistency - d.Set("resource_guid", props.FrontDoorID) - } + // whilst this is returned in the API as FrontDoorID other resources refer to + // this as the Resource GUID, so we will for consistency + d.Set("resource_guid", string(pointer.From(model.Properties.FrontDoorId))) skuName := "" - if resp.Sku != nil { - skuName = string(resp.Sku.Name) + if model.Sku.Name != nil { + skuName = string(pointer.From(model.Sku.Name)) } - d.Set("sku_name", skuName) - if err := tags.FlattenAndSet(d, resp.Tags); err != nil { - return err - } + d.Set("sku_name", skuName) + d.Set("tags", flattenNewFrontDoorTags(model.Tags)) return nil } diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource.go b/internal/services/cdn/cdn_frontdoor_profile_resource.go index 9d95ea1a49e2..41f910aeb151 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource.go @@ -7,18 +7,18 @@ import ( "fmt" "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-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + cdn "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/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceCdnFrontDoorProfile() *pluginsdk.Resource { @@ -84,37 +84,40 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface defer cancel() id := parse.NewFrontDoorProfileID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - existing, err := client.Get(ctx, id.ResourceGroup, id.ProfileName) + + profileId := cdn.ProfileId{ + SubscriptionId: id.SubscriptionId, + ResourceGroupName: id.ResourceGroup, + ProfileName: id.ProfileName, + } + + existing, err := client.Get(ctx, profileId) 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_profile", id.ID()) } props := cdn.Profile{ - Location: utils.String(location.Normalize("global")), - ProfileProperties: &cdn.ProfileProperties{ - OriginResponseTimeoutSeconds: utils.Int32(int32(d.Get("response_timeout_seconds").(int))), + Location: location.Normalize("global"), + Properties: &cdn.ProfileProperties{ + OriginResponseTimeoutSeconds: pointer.To(int64(d.Get("response_timeout_seconds").(int))), }, - Sku: &cdn.Sku{ - Name: cdn.SkuName(d.Get("sku_name").(string)), + Sku: cdn.Sku{ + Name: pointer.To(cdn.SkuName(d.Get("sku_name").(string))), }, - Tags: tags.Expand(d.Get("tags").(map[string]interface{})), + Tags: expandNewFrontDoorTagsPointer(d.Get("tags").(map[string]interface{})), } - future, err := client.Create(ctx, id.ResourceGroup, id.ProfileName, props) + err = client.CreateThenPoll(ctx, profileId, 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 resourceCdnFrontDoorProfileRead(d, meta) } @@ -129,9 +132,15 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName) + profileId := cdn.ProfileId{ + SubscriptionId: id.SubscriptionId, + ResourceGroupName: id.ResourceGroup, + ProfileName: id.ProfileName, + } + + resp, err := client.Get(ctx, profileId) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { d.SetId("") return nil } @@ -141,21 +150,31 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} d.Set("name", id.ProfileName) d.Set("resource_group_name", id.ResourceGroup) - if props := resp.ProfileProperties; props != nil { - d.Set("response_timeout_seconds", props.OriginResponseTimeoutSeconds) + model := resp.Model + + if model == nil { + return fmt.Errorf("model is 'nil'") + } - // whilst this is returned in the API as FrontDoorID other resources refer to - // this as the Resource GUID, so we will for consistency - d.Set("resource_guid", props.FrontDoorID) + if model.Properties == nil { + return fmt.Errorf("model.Properties is 'nil'") } + d.Set("response_timeout_seconds", int(pointer.From(model.Properties.OriginResponseTimeoutSeconds))) + + // whilst this is returned in the API as FrontDoorID other resources refer to + // this as the Resource GUID, so we will for consistency + d.Set("resource_guid", string(pointer.From(model.Properties.FrontDoorId))) + skuName := "" - if resp.Sku != nil { - skuName = string(resp.Sku.Name) + if model.Sku.Name != nil { + skuName = string(pointer.From(model.Sku.Name)) } + d.Set("sku_name", skuName) + d.Set("tags", flattenNewFrontDoorTags(model.Tags)) - return tags.FlattenAndSet(d, resp.Tags) + return nil } func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -168,24 +187,26 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface return err } + profileId := cdn.ProfileId{ + SubscriptionId: id.SubscriptionId, + ResourceGroupName: id.ResourceGroup, + ProfileName: id.ProfileName, + } + props := cdn.ProfileUpdateParameters{ - Tags: tags.Expand(d.Get("tags").(map[string]interface{})), - ProfilePropertiesUpdateParameters: &cdn.ProfilePropertiesUpdateParameters{}, + Tags: expandNewFrontDoorTagsPointer(d.Get("tags").(map[string]interface{})), + Properties: &cdn.ProfilePropertiesUpdateParameters{}, } if d.HasChange("response_timeout_seconds") { - props.OriginResponseTimeoutSeconds = utils.Int32(int32(d.Get("response_timeout_seconds").(int))) + props.Properties.OriginResponseTimeoutSeconds = pointer.To(int64(d.Get("response_timeout_seconds").(int))) } - future, err := client.Update(ctx, id.ResourceGroup, id.ProfileName, props) + err = client.UpdateThenPoll(ctx, profileId, props) if err != nil { return fmt.Errorf("updating %s: %+v", *id, err) } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the update of %s: %+v", *id, err) - } - return resourceCdnFrontDoorProfileRead(d, meta) } @@ -199,13 +220,15 @@ func resourceCdnFrontDoorProfileDelete(d *pluginsdk.ResourceData, meta interface return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.ProfileName) - if err != nil { - return fmt.Errorf("deleting %s: %+v", *id, err) + profileId := cdn.ProfileId{ + SubscriptionId: id.SubscriptionId, + ResourceGroupName: id.ResourceGroup, + ProfileName: id.ProfileName, } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the deletion of %s: %+v", *id, err) + err = client.DeleteThenPoll(ctx, profileId) + if err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) } return nil diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go index 1c4a0aab09cc..fcb479cb00e3 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go @@ -8,6 +8,8 @@ import ( "fmt" "testing" + "github.com/hashicorp/go-azure-helpers/lang/response" + cdn "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "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" @@ -89,10 +91,16 @@ func (r CdnFrontDoorProfileResource) Exists(ctx context.Context, clients *client return nil, err } + profileId := cdn.ProfileId{ + SubscriptionId: id.SubscriptionId, + ResourceGroupName: id.ResourceGroup, + ProfileName: id.ProfileName, + } + client := clients.Cdn.FrontDoorProfileClient - resp, err := client.Get(ctx, id.ResourceGroup, id.ProfileName) + resp, err := client.Get(ctx, profileId) 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) diff --git a/internal/services/cdn/cdn_frontdoor_rule_resource.go b/internal/services/cdn/cdn_frontdoor_rule_resource.go index c2e2f2965c7b..5a72326abd7c 100644 --- a/internal/services/cdn/cdn_frontdoor_rule_resource.go +++ b/internal/services/cdn/cdn_frontdoor_rule_resource.go @@ -7,7 +7,7 @@ import ( "fmt" "time" - cdn "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck + "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" cdnFrontDoorRuleActions "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/frontdoorruleactions" diff --git a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go index 5120921f182c..8cfb2fba4def 100644 --- a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go +++ b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go @@ -9,6 +9,8 @@ import ( "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" + cdnProfile "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" cdnfrontdoorsecurityparams "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/frontdoorsecurityparams" @@ -148,6 +150,12 @@ func resourceCdnFrontdoorSecurityPolicyCreate(d *pluginsdk.ResourceData, meta in return err } + profileId := cdnProfile.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) @@ -163,16 +171,26 @@ func resourceCdnFrontdoorSecurityPolicyCreate(d *pluginsdk.ResourceData, meta in } profileClient := meta.(*clients.Client).Cdn.FrontDoorProfileClient - resp, err := profileClient.Get(ctx, profile.ResourceGroup, profile.ProfileName) + resp, err := profileClient.Get(ctx, profileId) if err != nil { return fmt.Errorf("unable to retrieve the 'sku_name' from the CDN FrontDoor Profile(Name: %q)': %+v", profile.ProfileName, err) } - if resp.Sku == nil { - return fmt.Errorf("the CDN FrontDoor Profile(Name: %q) 'sku' was nil", profile.ProfileName) + profileModel := resp.Model + + if profileModel == nil { + return fmt.Errorf("profileModel is 'nil'") + } + + if profileModel.Properties == nil { + return fmt.Errorf("profileModel.Properties is 'nil'") + } + + if profileModel.Sku.Name == nil { + return fmt.Errorf("profileModel.Sku.Name is 'nil'") } - isStandardSku := strings.HasPrefix(strings.ToLower(string(resp.Sku.Name)), "standard") + isStandardSku := strings.HasPrefix(strings.ToLower(string(pointer.From(profileModel.Sku.Name))), "standard") params, err := cdnfrontdoorsecurityparams.ExpandCdnFrontdoorFirewallPolicyParameters(d.Get("security_policies").([]interface{}), isStandardSku) if err != nil { diff --git a/internal/services/cdn/client/client.go b/internal/services/cdn/client/client.go index fa144b1b2c3f..86d69d31ee27 100644 --- a/internal/services/cdn/client/client.go +++ b/internal/services/cdn/client/client.go @@ -4,9 +4,12 @@ package client import ( + "fmt" + cdnSdk "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2020-09-01/cdn" // nolint: staticcheck 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 + cdnProfile "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -18,7 +21,7 @@ type Client struct { FrontDoorSecurityPoliciesClient *cdnFrontDoorSdk.SecurityPoliciesClient FrontDoorRoutesClient *cdnFrontDoorSdk.RoutesClient FrontDoorRulesClient *cdnFrontDoorSdk.RulesClient - FrontDoorProfileClient *cdnFrontDoorSdk.ProfilesClient + FrontDoorProfileClient *cdnProfile.ProfilesClient FrontDoorSecretsClient *cdnFrontDoorSdk.SecretsClient FrontDoorRuleSetsClient *cdnFrontDoorSdk.RuleSetsClient FrontDoorLegacyFirewallPoliciesClient *frontdoor.PoliciesClient @@ -27,7 +30,13 @@ type Client struct { ProfilesClient *cdnSdk.ProfilesClient } -func NewClient(o *common.ClientOptions) *Client { +func NewClient(o *common.ClientOptions) (*Client, error) { + frontDoorProfilesClient, err := cdnProfile.NewProfilesClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building ProfilesClient: %+v", err) + } + o.Configure(frontDoorProfilesClient.Client, o.Authorizers.ResourceManager) + frontDoorEndpointsClient := cdnFrontDoorSdk.NewAFDEndpointsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&frontDoorEndpointsClient.Client, o.ResourceManagerAuthorizer) @@ -52,9 +61,6 @@ func NewClient(o *common.ClientOptions) *Client { frontDoorRulesClient := cdnFrontDoorSdk.NewRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&frontDoorRulesClient.Client, o.ResourceManagerAuthorizer) - frontDoorProfilesClient := cdnFrontDoorSdk.NewProfilesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) - o.ConfigureClient(&frontDoorProfilesClient.Client, o.ResourceManagerAuthorizer) - frontDoorPolicySecretsClient := cdnFrontDoorSdk.NewSecretsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&frontDoorPolicySecretsClient.Client, o.ResourceManagerAuthorizer) @@ -70,7 +76,7 @@ func NewClient(o *common.ClientOptions) *Client { profilesClient := cdnSdk.NewProfilesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) o.ConfigureClient(&profilesClient.Client, o.ResourceManagerAuthorizer) - return &Client{ + client := Client{ FrontDoorEndpointsClient: &frontDoorEndpointsClient, FrontDoorOriginGroupsClient: &frontDoorOriginGroupsClient, FrontDoorOriginsClient: &frontDoorOriginsClient, @@ -78,7 +84,7 @@ func NewClient(o *common.ClientOptions) *Client { FrontDoorSecurityPoliciesClient: &frontDoorPolicySecurityPoliciesClient, FrontDoorRoutesClient: &frontDoorRoutesClient, FrontDoorRulesClient: &frontDoorRulesClient, - FrontDoorProfileClient: &frontDoorProfilesClient, + FrontDoorProfileClient: frontDoorProfilesClient, FrontDoorSecretsClient: &frontDoorPolicySecretsClient, FrontDoorRuleSetsClient: &frontDoorRuleSetsClient, FrontDoorLegacyFirewallPoliciesClient: &frontDoorLegacyFirewallPoliciesClient, @@ -86,4 +92,6 @@ func NewClient(o *common.ClientOptions) *Client { EndpointsClient: &endpointsClient, ProfilesClient: &profilesClient, } + + return &client, nil } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/README.md new file mode 100644 index 000000000000..6e26cdff2d8d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/README.md @@ -0,0 +1,212 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles` Documentation + +The `profiles` 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-helpers/resourcemanager/commonids" +import "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" +``` + + +### Client Initialization + +```go +client := profiles.NewProfilesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ProfilesClient.CanMigrate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := profiles.CanMigrateParameters{ + // ... +} + + +if err := client.CanMigrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.Create` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +payload := profiles.Profile{ + // ... +} + + +if err := client.CreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.Delete` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.GenerateSsoUri` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +read, err := client.GenerateSsoUri(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProfilesClient.Get` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +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: `ProfilesClient.List` + +```go +ctx := context.TODO() +id := commonids.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProfilesClient.ListByResourceGroup` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProfilesClient.ListResourceUsage` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +// alternatively `client.ListResourceUsage(ctx, id)` can be used to do batched pagination +items, err := client.ListResourceUsageComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ProfilesClient.ListSupportedOptimizationTypes` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +read, err := client.ListSupportedOptimizationTypes(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ProfilesClient.Migrate` + +```go +ctx := context.TODO() +id := commonids.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +payload := profiles.MigrationParameters{ + // ... +} + + +if err := client.MigrateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.MigrationCommit` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +if err := client.MigrationCommitThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ProfilesClient.Update` + +```go +ctx := context.TODO() +id := profiles.NewProfileID("12345678-1234-9876-4563-123456789012", "example-resource-group", "profileName") + +payload := profiles.ProfileUpdateParameters{ + // ... +} + + +if err := client.UpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/client.go new file mode 100644 index 000000000000..16eaef711947 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/client.go @@ -0,0 +1,26 @@ +package profiles + +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 ProfilesClient struct { + Client *resourcemanager.Client +} + +func NewProfilesClientWithBaseURI(sdkApi sdkEnv.Api) (*ProfilesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "profiles", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating ProfilesClient: %+v", err) + } + + return &ProfilesClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/constants.go new file mode 100644 index 000000000000..7c46f402b9a2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/constants.go @@ -0,0 +1,489 @@ +package profiles + +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 CanMigrateDefaultSku string + +const ( + CanMigrateDefaultSkuPremiumAzureFrontDoor CanMigrateDefaultSku = "Premium_AzureFrontDoor" + CanMigrateDefaultSkuStandardAzureFrontDoor CanMigrateDefaultSku = "Standard_AzureFrontDoor" +) + +func PossibleValuesForCanMigrateDefaultSku() []string { + return []string{ + string(CanMigrateDefaultSkuPremiumAzureFrontDoor), + string(CanMigrateDefaultSkuStandardAzureFrontDoor), + } +} + +func (s *CanMigrateDefaultSku) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseCanMigrateDefaultSku(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseCanMigrateDefaultSku(input string) (*CanMigrateDefaultSku, error) { + vals := map[string]CanMigrateDefaultSku{ + "premium_azurefrontdoor": CanMigrateDefaultSkuPremiumAzureFrontDoor, + "standard_azurefrontdoor": CanMigrateDefaultSkuStandardAzureFrontDoor, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CanMigrateDefaultSku(input) + return &out, nil +} + +type OptimizationType string + +const ( + OptimizationTypeDynamicSiteAcceleration OptimizationType = "DynamicSiteAcceleration" + OptimizationTypeGeneralMediaStreaming OptimizationType = "GeneralMediaStreaming" + OptimizationTypeGeneralWebDelivery OptimizationType = "GeneralWebDelivery" + OptimizationTypeLargeFileDownload OptimizationType = "LargeFileDownload" + OptimizationTypeVideoOnDemandMediaStreaming OptimizationType = "VideoOnDemandMediaStreaming" +) + +func PossibleValuesForOptimizationType() []string { + return []string{ + string(OptimizationTypeDynamicSiteAcceleration), + string(OptimizationTypeGeneralMediaStreaming), + string(OptimizationTypeGeneralWebDelivery), + string(OptimizationTypeLargeFileDownload), + string(OptimizationTypeVideoOnDemandMediaStreaming), + } +} + +func (s *OptimizationType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseOptimizationType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseOptimizationType(input string) (*OptimizationType, error) { + vals := map[string]OptimizationType{ + "dynamicsiteacceleration": OptimizationTypeDynamicSiteAcceleration, + "generalmediastreaming": OptimizationTypeGeneralMediaStreaming, + "generalwebdelivery": OptimizationTypeGeneralWebDelivery, + "largefiledownload": OptimizationTypeLargeFileDownload, + "videoondemandmediastreaming": OptimizationTypeVideoOnDemandMediaStreaming, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := OptimizationType(input) + return &out, nil +} + +type ProfileProvisioningState string + +const ( + ProfileProvisioningStateCreating ProfileProvisioningState = "Creating" + ProfileProvisioningStateDeleting ProfileProvisioningState = "Deleting" + ProfileProvisioningStateFailed ProfileProvisioningState = "Failed" + ProfileProvisioningStateSucceeded ProfileProvisioningState = "Succeeded" + ProfileProvisioningStateUpdating ProfileProvisioningState = "Updating" +) + +func PossibleValuesForProfileProvisioningState() []string { + return []string{ + string(ProfileProvisioningStateCreating), + string(ProfileProvisioningStateDeleting), + string(ProfileProvisioningStateFailed), + string(ProfileProvisioningStateSucceeded), + string(ProfileProvisioningStateUpdating), + } +} + +func (s *ProfileProvisioningState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileProvisioningState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileProvisioningState(input string) (*ProfileProvisioningState, error) { + vals := map[string]ProfileProvisioningState{ + "creating": ProfileProvisioningStateCreating, + "deleting": ProfileProvisioningStateDeleting, + "failed": ProfileProvisioningStateFailed, + "succeeded": ProfileProvisioningStateSucceeded, + "updating": ProfileProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileProvisioningState(input) + return &out, nil +} + +type ProfileResourceState string + +const ( + ProfileResourceStateAbortingMigration ProfileResourceState = "AbortingMigration" + ProfileResourceStateActive ProfileResourceState = "Active" + ProfileResourceStateCommittingMigration ProfileResourceState = "CommittingMigration" + ProfileResourceStateCreating ProfileResourceState = "Creating" + ProfileResourceStateDeleting ProfileResourceState = "Deleting" + ProfileResourceStateDisabled ProfileResourceState = "Disabled" + ProfileResourceStateMigrated ProfileResourceState = "Migrated" + ProfileResourceStateMigrating ProfileResourceState = "Migrating" + ProfileResourceStatePendingMigrationCommit ProfileResourceState = "PendingMigrationCommit" +) + +func PossibleValuesForProfileResourceState() []string { + return []string{ + string(ProfileResourceStateAbortingMigration), + string(ProfileResourceStateActive), + string(ProfileResourceStateCommittingMigration), + string(ProfileResourceStateCreating), + string(ProfileResourceStateDeleting), + string(ProfileResourceStateDisabled), + string(ProfileResourceStateMigrated), + string(ProfileResourceStateMigrating), + string(ProfileResourceStatePendingMigrationCommit), + } +} + +func (s *ProfileResourceState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileResourceState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileResourceState(input string) (*ProfileResourceState, error) { + vals := map[string]ProfileResourceState{ + "abortingmigration": ProfileResourceStateAbortingMigration, + "active": ProfileResourceStateActive, + "committingmigration": ProfileResourceStateCommittingMigration, + "creating": ProfileResourceStateCreating, + "deleting": ProfileResourceStateDeleting, + "disabled": ProfileResourceStateDisabled, + "migrated": ProfileResourceStateMigrated, + "migrating": ProfileResourceStateMigrating, + "pendingmigrationcommit": ProfileResourceStatePendingMigrationCommit, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileResourceState(input) + return &out, nil +} + +type ProfileScrubbingState string + +const ( + ProfileScrubbingStateDisabled ProfileScrubbingState = "Disabled" + ProfileScrubbingStateEnabled ProfileScrubbingState = "Enabled" +) + +func PossibleValuesForProfileScrubbingState() []string { + return []string{ + string(ProfileScrubbingStateDisabled), + string(ProfileScrubbingStateEnabled), + } +} + +func (s *ProfileScrubbingState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseProfileScrubbingState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseProfileScrubbingState(input string) (*ProfileScrubbingState, error) { + vals := map[string]ProfileScrubbingState{ + "disabled": ProfileScrubbingStateDisabled, + "enabled": ProfileScrubbingStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProfileScrubbingState(input) + return &out, nil +} + +type ResourceUsageUnit string + +const ( + ResourceUsageUnitCount ResourceUsageUnit = "count" +) + +func PossibleValuesForResourceUsageUnit() []string { + return []string{ + string(ResourceUsageUnitCount), + } +} + +func (s *ResourceUsageUnit) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseResourceUsageUnit(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseResourceUsageUnit(input string) (*ResourceUsageUnit, error) { + vals := map[string]ResourceUsageUnit{ + "count": ResourceUsageUnitCount, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ResourceUsageUnit(input) + return &out, nil +} + +type ScrubbingRuleEntryMatchOperator string + +const ( + ScrubbingRuleEntryMatchOperatorEqualsAny ScrubbingRuleEntryMatchOperator = "EqualsAny" +) + +func PossibleValuesForScrubbingRuleEntryMatchOperator() []string { + return []string{ + string(ScrubbingRuleEntryMatchOperatorEqualsAny), + } +} + +func (s *ScrubbingRuleEntryMatchOperator) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryMatchOperator(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryMatchOperator(input string) (*ScrubbingRuleEntryMatchOperator, error) { + vals := map[string]ScrubbingRuleEntryMatchOperator{ + "equalsany": ScrubbingRuleEntryMatchOperatorEqualsAny, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryMatchOperator(input) + return &out, nil +} + +type ScrubbingRuleEntryMatchVariable string + +const ( + ScrubbingRuleEntryMatchVariableQueryStringArgNames ScrubbingRuleEntryMatchVariable = "QueryStringArgNames" + ScrubbingRuleEntryMatchVariableRequestIPAddress ScrubbingRuleEntryMatchVariable = "RequestIPAddress" + ScrubbingRuleEntryMatchVariableRequestUri ScrubbingRuleEntryMatchVariable = "RequestUri" +) + +func PossibleValuesForScrubbingRuleEntryMatchVariable() []string { + return []string{ + string(ScrubbingRuleEntryMatchVariableQueryStringArgNames), + string(ScrubbingRuleEntryMatchVariableRequestIPAddress), + string(ScrubbingRuleEntryMatchVariableRequestUri), + } +} + +func (s *ScrubbingRuleEntryMatchVariable) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryMatchVariable(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryMatchVariable(input string) (*ScrubbingRuleEntryMatchVariable, error) { + vals := map[string]ScrubbingRuleEntryMatchVariable{ + "querystringargnames": ScrubbingRuleEntryMatchVariableQueryStringArgNames, + "requestipaddress": ScrubbingRuleEntryMatchVariableRequestIPAddress, + "requesturi": ScrubbingRuleEntryMatchVariableRequestUri, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryMatchVariable(input) + return &out, nil +} + +type ScrubbingRuleEntryState string + +const ( + ScrubbingRuleEntryStateDisabled ScrubbingRuleEntryState = "Disabled" + ScrubbingRuleEntryStateEnabled ScrubbingRuleEntryState = "Enabled" +) + +func PossibleValuesForScrubbingRuleEntryState() []string { + return []string{ + string(ScrubbingRuleEntryStateDisabled), + string(ScrubbingRuleEntryStateEnabled), + } +} + +func (s *ScrubbingRuleEntryState) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseScrubbingRuleEntryState(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseScrubbingRuleEntryState(input string) (*ScrubbingRuleEntryState, error) { + vals := map[string]ScrubbingRuleEntryState{ + "disabled": ScrubbingRuleEntryStateDisabled, + "enabled": ScrubbingRuleEntryStateEnabled, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ScrubbingRuleEntryState(input) + return &out, nil +} + +type SkuName string + +const ( + SkuNameCustomVerizon SkuName = "Custom_Verizon" + SkuNamePremiumAzureFrontDoor SkuName = "Premium_AzureFrontDoor" + SkuNamePremiumVerizon SkuName = "Premium_Verizon" + SkuNameStandardAkamai SkuName = "Standard_Akamai" + SkuNameStandardAvgBandWidthChinaCdn SkuName = "Standard_AvgBandWidth_ChinaCdn" + SkuNameStandardAzureFrontDoor SkuName = "Standard_AzureFrontDoor" + SkuNameStandardChinaCdn SkuName = "Standard_ChinaCdn" + SkuNameStandardMicrosoft SkuName = "Standard_Microsoft" + SkuNameStandardNineFiveFiveBandWidthChinaCdn SkuName = "Standard_955BandWidth_ChinaCdn" + SkuNameStandardPlusAvgBandWidthChinaCdn SkuName = "StandardPlus_AvgBandWidth_ChinaCdn" + SkuNameStandardPlusChinaCdn SkuName = "StandardPlus_ChinaCdn" + SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn SkuName = "StandardPlus_955BandWidth_ChinaCdn" + SkuNameStandardVerizon SkuName = "Standard_Verizon" +) + +func PossibleValuesForSkuName() []string { + return []string{ + string(SkuNameCustomVerizon), + string(SkuNamePremiumAzureFrontDoor), + string(SkuNamePremiumVerizon), + string(SkuNameStandardAkamai), + string(SkuNameStandardAvgBandWidthChinaCdn), + string(SkuNameStandardAzureFrontDoor), + string(SkuNameStandardChinaCdn), + string(SkuNameStandardMicrosoft), + string(SkuNameStandardNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardPlusAvgBandWidthChinaCdn), + string(SkuNameStandardPlusChinaCdn), + string(SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn), + string(SkuNameStandardVerizon), + } +} + +func (s *SkuName) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseSkuName(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseSkuName(input string) (*SkuName, error) { + vals := map[string]SkuName{ + "custom_verizon": SkuNameCustomVerizon, + "premium_azurefrontdoor": SkuNamePremiumAzureFrontDoor, + "premium_verizon": SkuNamePremiumVerizon, + "standard_akamai": SkuNameStandardAkamai, + "standard_avgbandwidth_chinacdn": SkuNameStandardAvgBandWidthChinaCdn, + "standard_azurefrontdoor": SkuNameStandardAzureFrontDoor, + "standard_chinacdn": SkuNameStandardChinaCdn, + "standard_microsoft": SkuNameStandardMicrosoft, + "standard_955bandwidth_chinacdn": SkuNameStandardNineFiveFiveBandWidthChinaCdn, + "standardplus_avgbandwidth_chinacdn": SkuNameStandardPlusAvgBandWidthChinaCdn, + "standardplus_chinacdn": SkuNameStandardPlusChinaCdn, + "standardplus_955bandwidth_chinacdn": SkuNameStandardPlusNineFiveFiveBandWidthChinaCdn, + "standard_verizon": SkuNameStandardVerizon, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := SkuName(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/id_profile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/id_profile.go new file mode 100644 index 000000000000..41542427251f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/id_profile.go @@ -0,0 +1,130 @@ +package profiles + +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/profiles/method_canmigrate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_canmigrate.go new file mode 100644 index 000000000000..edda06382194 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_canmigrate.go @@ -0,0 +1,76 @@ +package profiles + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "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 CanMigrateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *CanMigrateResult +} + +// CanMigrate ... +func (c ProfilesClient) CanMigrate(ctx context.Context, id commonids.ResourceGroupId, input CanMigrateParameters) (result CanMigrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/canMigrate", 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 +} + +// CanMigrateThenPoll performs CanMigrate then polls until it's completed +func (c ProfilesClient) CanMigrateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input CanMigrateParameters) error { + result, err := c.CanMigrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CanMigrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CanMigrate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_create.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_create.go new file mode 100644 index 000000000000..fdde9d737ec6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_create.go @@ -0,0 +1,76 @@ +package profiles + +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 *Profile +} + +// Create ... +func (c ProfilesClient) Create(ctx context.Context, id ProfileId, input Profile) (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 ProfilesClient) CreateThenPoll(ctx context.Context, id ProfileId, input Profile) 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/profiles/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_delete.go new file mode 100644 index 000000000000..8d46fe3a4ffc --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_delete.go @@ -0,0 +1,71 @@ +package profiles + +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 ProfilesClient) Delete(ctx context.Context, id ProfileId) (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 ProfilesClient) DeleteThenPoll(ctx context.Context, id ProfileId) 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/profiles/method_generatessouri.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_generatessouri.go new file mode 100644 index 000000000000..763f54f9cc51 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_generatessouri.go @@ -0,0 +1,54 @@ +package profiles + +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 GenerateSsoUriOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SsoUri +} + +// GenerateSsoUri ... +func (c ProfilesClient) GenerateSsoUri(ctx context.Context, id ProfileId) (result GenerateSsoUriOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/generateSsoUri", 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 SsoUri + 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/profiles/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_get.go new file mode 100644 index 000000000000..d26affa96a58 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_get.go @@ -0,0 +1,53 @@ +package profiles + +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 *Profile +} + +// Get ... +func (c ProfilesClient) Get(ctx context.Context, id ProfileId) (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 Profile + 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/profiles/method_list.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_list.go new file mode 100644 index 000000000000..3a6e95d2b42e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_list.go @@ -0,0 +1,106 @@ +package profiles + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Profile +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []Profile +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c ProfilesClient) List(ctx context.Context, id commonids.SubscriptionId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/profiles", 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 *[]Profile `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c ProfilesClient) ListComplete(ctx context.Context, id commonids.SubscriptionId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, ProfileOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProfilesClient) ListCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ProfileOperationPredicate) (result ListCompleteResult, err error) { + items := make([]Profile, 0) + + resp, err := c.List(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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go new file mode 100644 index 000000000000..da005d4d92c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listbyresourcegroup.go @@ -0,0 +1,106 @@ +package profiles + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "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 ListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Profile +} + +type ListByResourceGroupCompleteResult struct { + LatestHttpResponse *http.Response + Items []Profile +} + +type ListByResourceGroupCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByResourceGroupCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByResourceGroup ... +func (c ProfilesClient) ListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (result ListByResourceGroupOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListByResourceGroupCustomPager{}, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/profiles", 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 *[]Profile `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByResourceGroupComplete retrieves all the results into a single object +func (c ProfilesClient) ListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ListByResourceGroupCompleteResult, error) { + return c.ListByResourceGroupCompleteMatchingPredicate(ctx, id, ProfileOperationPredicate{}) +} + +// ListByResourceGroupCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProfilesClient) ListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ProfileOperationPredicate) (result ListByResourceGroupCompleteResult, err error) { + items := make([]Profile, 0) + + resp, err := c.ListByResourceGroup(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 = ListByResourceGroupCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go new file mode 100644 index 000000000000..1f51a1643fd5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listresourceusage.go @@ -0,0 +1,105 @@ +package profiles + +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 ListResourceUsageOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ResourceUsage +} + +type ListResourceUsageCompleteResult struct { + LatestHttpResponse *http.Response + Items []ResourceUsage +} + +type ListResourceUsageCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListResourceUsageCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListResourceUsage ... +func (c ProfilesClient) ListResourceUsage(ctx context.Context, id ProfileId) (result ListResourceUsageOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Pager: &ListResourceUsageCustomPager{}, + Path: fmt.Sprintf("%s/checkResourceUsage", 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 *[]ResourceUsage `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListResourceUsageComplete retrieves all the results into a single object +func (c ProfilesClient) ListResourceUsageComplete(ctx context.Context, id ProfileId) (ListResourceUsageCompleteResult, error) { + return c.ListResourceUsageCompleteMatchingPredicate(ctx, id, ResourceUsageOperationPredicate{}) +} + +// ListResourceUsageCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c ProfilesClient) ListResourceUsageCompleteMatchingPredicate(ctx context.Context, id ProfileId, predicate ResourceUsageOperationPredicate) (result ListResourceUsageCompleteResult, err error) { + items := make([]ResourceUsage, 0) + + resp, err := c.ListResourceUsage(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 = ListResourceUsageCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go new file mode 100644 index 000000000000..e743655689a2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_listsupportedoptimizationtypes.go @@ -0,0 +1,54 @@ +package profiles + +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 ListSupportedOptimizationTypesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *SupportedOptimizationTypesListResult +} + +// ListSupportedOptimizationTypes ... +func (c ProfilesClient) ListSupportedOptimizationTypes(ctx context.Context, id ProfileId) (result ListSupportedOptimizationTypesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/getSupportedOptimizationTypes", 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 SupportedOptimizationTypesListResult + 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/profiles/method_migrate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrate.go new file mode 100644 index 000000000000..cb3ea6cce657 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrate.go @@ -0,0 +1,76 @@ +package profiles + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "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 MigrateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *MigrateResult +} + +// Migrate ... +func (c ProfilesClient) Migrate(ctx context.Context, id commonids.ResourceGroupId, input MigrationParameters) (result MigrateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/providers/Microsoft.CDN/migrate", 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 +} + +// MigrateThenPoll performs Migrate then polls until it's completed +func (c ProfilesClient) MigrateThenPoll(ctx context.Context, id commonids.ResourceGroupId, input MigrationParameters) error { + result, err := c.Migrate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Migrate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Migrate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go new file mode 100644 index 000000000000..eb5e0a88a270 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_migrationcommit.go @@ -0,0 +1,70 @@ +package profiles + +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 MigrationCommitOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// MigrationCommit ... +func (c ProfilesClient) MigrationCommit(ctx context.Context, id ProfileId) (result MigrationCommitOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusOK, + }, + HttpMethod: http.MethodPost, + Path: fmt.Sprintf("%s/migrationCommit", 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 +} + +// MigrationCommitThenPoll performs MigrationCommit then polls until it's completed +func (c ProfilesClient) MigrationCommitThenPoll(ctx context.Context, id ProfileId) error { + result, err := c.MigrationCommit(ctx, id) + if err != nil { + return fmt.Errorf("performing MigrationCommit: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after MigrationCommit: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_update.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_update.go new file mode 100644 index 000000000000..5694b5666a69 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/method_update.go @@ -0,0 +1,75 @@ +package profiles + +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 UpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *Profile +} + +// Update ... +func (c ProfilesClient) Update(ctx context.Context, id ProfileId, input ProfileUpdateParameters) (result UpdateOperationResponse, 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 +} + +// UpdateThenPoll performs Update then polls until it's completed +func (c ProfilesClient) UpdateThenPoll(ctx context.Context, id ProfileId, input ProfileUpdateParameters) error { + result, err := c.Update(ctx, id, input) + if err != nil { + return fmt.Errorf("performing Update: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Update: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateparameters.go new file mode 100644 index 000000000000..cba030af8d7a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateparameters.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanMigrateParameters struct { + ClassicResourceReference ResourceReference `json:"classicResourceReference"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go new file mode 100644 index 000000000000..8a79f4648c1c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateproperties.go @@ -0,0 +1,10 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanMigrateProperties struct { + CanMigrate *bool `json:"canMigrate,omitempty"` + DefaultSku *CanMigrateDefaultSku `json:"defaultSku,omitempty"` + Errors *[]MigrationErrorType `json:"errors,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go new file mode 100644 index 000000000000..500699ff7756 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_canmigrateresult.go @@ -0,0 +1,10 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CanMigrateResult struct { + Id *string `json:"id,omitempty"` + Properties *CanMigrateProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go new file mode 100644 index 000000000000..c53f7a73fc5c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresult.go @@ -0,0 +1,10 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateResult struct { + Id *string `json:"id,omitempty"` + Properties *MigrateResultProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go new file mode 100644 index 000000000000..ad533db013d4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrateresultproperties.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrateResultProperties struct { + MigratedProfileResourceId *ResourceReference `json:"migratedProfileResourceId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go new file mode 100644 index 000000000000..6155279d9c10 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationerrortype.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationErrorType struct { + Code *string `json:"code,omitempty"` + ErrorMessage *string `json:"errorMessage,omitempty"` + NextSteps *string `json:"nextSteps,omitempty"` + ResourceName *string `json:"resourceName,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go new file mode 100644 index 000000000000..37a14cc634b9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationparameters.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationParameters struct { + ClassicResourceReference ResourceReference `json:"classicResourceReference"` + MigrationWebApplicationFirewallMappings *[]MigrationWebApplicationFirewallMapping `json:"migrationWebApplicationFirewallMappings,omitempty"` + ProfileName string `json:"profileName"` + Sku Sku `json:"sku"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go new file mode 100644 index 000000000000..342be3055889 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_migrationwebapplicationfirewallmapping.go @@ -0,0 +1,9 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type MigrationWebApplicationFirewallMapping struct { + MigratedFrom *ResourceReference `json:"migratedFrom,omitempty"` + MigratedTo *ResourceReference `json:"migratedTo,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profile.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profile.go new file mode 100644 index 000000000000..2568ad9b1302 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profile.go @@ -0,0 +1,22 @@ +package profiles + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "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 Profile struct { + Id *string `json:"id,omitempty"` + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Kind *string `json:"kind,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties *ProfileProperties `json:"properties,omitempty"` + Sku Sku `json:"sku"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go new file mode 100644 index 000000000000..f897715e8c2e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilelogscrubbing.go @@ -0,0 +1,9 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileLogScrubbing struct { + ScrubbingRules *[]ProfileScrubbingRules `json:"scrubbingRules,omitempty"` + State *ProfileScrubbingState `json:"state,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go new file mode 100644 index 000000000000..6c9e4d175b42 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileproperties.go @@ -0,0 +1,13 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileProperties struct { + ExtendedProperties *map[string]string `json:"extendedProperties,omitempty"` + FrontDoorId *string `json:"frontDoorId,omitempty"` + LogScrubbing *ProfileLogScrubbing `json:"logScrubbing,omitempty"` + OriginResponseTimeoutSeconds *int64 `json:"originResponseTimeoutSeconds,omitempty"` + ProvisioningState *ProfileProvisioningState `json:"provisioningState,omitempty"` + ResourceState *ProfileResourceState `json:"resourceState,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go new file mode 100644 index 000000000000..01d3dc5ad0e2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilepropertiesupdateparameters.go @@ -0,0 +1,9 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfilePropertiesUpdateParameters struct { + LogScrubbing *ProfileLogScrubbing `json:"logScrubbing,omitempty"` + OriginResponseTimeoutSeconds *int64 `json:"originResponseTimeoutSeconds,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go new file mode 100644 index 000000000000..9ed138086f8b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profilescrubbingrules.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileScrubbingRules struct { + MatchVariable ScrubbingRuleEntryMatchVariable `json:"matchVariable"` + Selector *string `json:"selector,omitempty"` + SelectorMatchOperator ScrubbingRuleEntryMatchOperator `json:"selectorMatchOperator"` + State *ScrubbingRuleEntryState `json:"state,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go new file mode 100644 index 000000000000..01c4b9665364 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_profileupdateparameters.go @@ -0,0 +1,14 @@ +package profiles + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileUpdateParameters struct { + Identity *identity.SystemAndUserAssignedMap `json:"identity,omitempty"` + Properties *ProfilePropertiesUpdateParameters `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go new file mode 100644 index 000000000000..3e5faa3a3d77 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourcereference.go @@ -0,0 +1,8 @@ +package profiles + +// 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/profiles/model_resourceusage.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourceusage.go new file mode 100644 index 000000000000..f56db4430e27 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_resourceusage.go @@ -0,0 +1,11 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ResourceUsage struct { + CurrentValue *int64 `json:"currentValue,omitempty"` + Limit *int64 `json:"limit,omitempty"` + ResourceType *string `json:"resourceType,omitempty"` + Unit *ResourceUsageUnit `json:"unit,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_sku.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_sku.go new file mode 100644 index 000000000000..a70d546bfd69 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_sku.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Sku struct { + Name *SkuName `json:"name,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go new file mode 100644 index 000000000000..ae93b0584f8a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_ssouri.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SsoUri struct { + SsoUriValue *string `json:"ssoUriValue,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go new file mode 100644 index 000000000000..1242943b3db6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/model_supportedoptimizationtypeslistresult.go @@ -0,0 +1,8 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type SupportedOptimizationTypesListResult struct { + SupportedOptimizationTypes *[]OptimizationType `json:"supportedOptimizationTypes,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/predicates.go new file mode 100644 index 000000000000..f48c2803370e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/predicates.go @@ -0,0 +1,60 @@ +package profiles + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ProfileOperationPredicate struct { + Id *string + Kind *string + Location *string + Name *string + Type *string +} + +func (p ProfileOperationPredicate) Matches(input Profile) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Kind != nil && (input.Kind == nil || *p.Kind != *input.Kind) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + 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 +} + +type ResourceUsageOperationPredicate struct { + CurrentValue *int64 + Limit *int64 + ResourceType *string +} + +func (p ResourceUsageOperationPredicate) Matches(input ResourceUsage) bool { + + if p.CurrentValue != nil && (input.CurrentValue == nil || *p.CurrentValue != *input.CurrentValue) { + return false + } + + if p.Limit != nil && (input.Limit == nil || *p.Limit != *input.Limit) { + return false + } + + if p.ResourceType != nil && (input.ResourceType == nil || *p.ResourceType != *input.ResourceType) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/version.go new file mode 100644 index 000000000000..3a0dc8d5b917 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles/version.go @@ -0,0 +1,10 @@ +package profiles + +// 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/profiles/2024-02-01" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 17d269b35a92..a6b0c01ffff3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -309,6 +309,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/blueprint 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/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 From 2cd6448d1e1e7c2ff52f0add8220be882c3487d9 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:25:44 -0700 Subject: [PATCH 02/10] Fix lint issues... --- internal/services/cdn/cdn_frontdoor_helpers.go | 10 ++++------ .../services/cdn/cdn_frontdoor_profile_data_source.go | 2 +- .../services/cdn/cdn_frontdoor_profile_resource.go | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/services/cdn/cdn_frontdoor_helpers.go b/internal/services/cdn/cdn_frontdoor_helpers.go index 6d3d304a2297..0b069b6355f6 100644 --- a/internal/services/cdn/cdn_frontdoor_helpers.go +++ b/internal/services/cdn/cdn_frontdoor_helpers.go @@ -113,12 +113,10 @@ func flattenHttpsRedirectToBool(input cdn.HTTPSRedirect) bool { func expandNewFrontDoorTagsPointer(tagMap map[string]interface{}) *map[string]string { t := make(map[string]string) - if tagMap != nil { - for k, v := range tagMap { - tagKey := k - tagValue := v - t[tagKey] = tagValue.(string) - } + for k, v := range tagMap { + tagKey := k + tagValue := v + t[tagKey] = tagValue.(string) } return pointer.To(t) diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source.go b/internal/services/cdn/cdn_frontdoor_profile_data_source.go index f787b9e7586e..6ee275c1f34f 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source.go @@ -95,7 +95,7 @@ func dataSourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface // whilst this is returned in the API as FrontDoorID other resources refer to // this as the Resource GUID, so we will for consistency - d.Set("resource_guid", string(pointer.From(model.Properties.FrontDoorId))) + d.Set("resource_guid", pointer.From(model.Properties.FrontDoorId)) skuName := "" if model.Sku.Name != nil { diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource.go b/internal/services/cdn/cdn_frontdoor_profile_resource.go index 41f910aeb151..3ef61a469c3c 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource.go @@ -164,7 +164,7 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} // whilst this is returned in the API as FrontDoorID other resources refer to // this as the Resource GUID, so we will for consistency - d.Set("resource_guid", string(pointer.From(model.Properties.FrontDoorId))) + d.Set("resource_guid", pointer.From(model.Properties.FrontDoorId)) skuName := "" if model.Sku.Name != nil { From 4d2ee2c5983cc49e8ae99cab07f94fbd1d2b6dc6 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:05:01 -0700 Subject: [PATCH 03/10] Add tests and documentation... --- .../services/cdn/cdn_frontdoor_helpers.go | 18 +- .../cdn/cdn_frontdoor_profile_data_source.go | 8 + .../cdn_frontdoor_profile_data_source_test.go | 78 +++++ .../cdn/cdn_frontdoor_profile_resource.go | 30 ++ .../cdn_frontdoor_profile_resource_test.go | 290 +++++++++++++++++- .../d/cdn_frontdoor_profile.html.markdown | 12 + .../r/cdn_frontdoor_profile.html.markdown | 12 + 7 files changed, 436 insertions(+), 12 deletions(-) diff --git a/internal/services/cdn/cdn_frontdoor_helpers.go b/internal/services/cdn/cdn_frontdoor_helpers.go index 0b069b6355f6..61a4450d4ef4 100644 --- a/internal/services/cdn/cdn_frontdoor_helpers.go +++ b/internal/services/cdn/cdn_frontdoor_helpers.go @@ -175,10 +175,8 @@ func flattenTransformSlice(input *[]frontdoor.TransformType) []interface{} { return result } - if input != nil { - for _, item := range *input { - result = append(result, string(item)) - } + for _, item := range *input { + result = append(result, string(item)) } return result @@ -190,14 +188,12 @@ func flattenFrontendEndpointLinkSlice(input *[]frontdoor.FrontendEndpointLink) [ return result } - if input != nil { - for _, item := range *input { - if item.ID == nil { - continue - } - - result = append(result, *item.ID) + for _, item := range *input { + if item.ID == nil { + continue } + + result = append(result, *item.ID) } return result diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source.go b/internal/services/cdn/cdn_frontdoor_profile_data_source.go index 6ee275c1f34f..52b8f01321cb 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" cdn "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse" @@ -35,6 +36,8 @@ func dataSourceCdnFrontDoorProfile() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupNameForDataSource(), + "identity": commonschema.SystemAssignedUserAssignedIdentityOptional(), + "response_timeout_seconds": { Type: pluginsdk.TypeInt, Computed: true, @@ -97,6 +100,11 @@ func dataSourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface // this as the Resource GUID, so we will for consistency d.Set("resource_guid", pointer.From(model.Properties.FrontDoorId)) + identity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity) + if err == nil { + d.Set("identity", identity) + } + skuName := "" if model.Sku.Name != nil { skuName = string(pointer.From(model.Sku.Name)) diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go b/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go index 1e880d1aec3a..8c106c16a323 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go @@ -27,6 +27,51 @@ func TestAccCdnFrontDoorProfileDataSource_basic(t *testing.T) { }) } +func TestAccCdnFrontDoorProfileDataSource_basicWithSystemIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_profile", "test") + d := CdnFrontDoorProfileDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: d.basicWithSystemIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("sku_name").HasValue("Premium_AzureFrontDoor"), + check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned"), + ), + }, + }) +} + +func TestAccCdnFrontDoorProfileDataSource_basicWithUserIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_profile", "test") + d := CdnFrontDoorProfileDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: d.basicWithUserIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("sku_name").HasValue("Premium_AzureFrontDoor"), + check.That(data.ResourceName).Key("identity.0.type").HasValue("UserAssigned"), + ), + }, + }) +} + +func TestAccCdnFrontDoorProfileDataSource_basicWithSystemAndUserIdentity(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_profile", "test") + d := CdnFrontDoorProfileDataSource{} + + data.DataSourceTest(t, []acceptance.TestStep{ + { + Config: d.basicWithSystemAndUserIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).Key("sku_name").HasValue("Premium_AzureFrontDoor"), + check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned, UserAssigned"), + ), + }, + }) +} + func (CdnFrontDoorProfileDataSource) basic(data acceptance.TestData) string { return fmt.Sprintf(` %s @@ -37,3 +82,36 @@ data "azurerm_cdn_frontdoor_profile" "test" { } `, CdnFrontDoorProfileResource{}.complete(data)) } + +func (CdnFrontDoorProfileDataSource) basicWithSystemIdentity(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cdn_frontdoor_profile" "test" { + name = azurerm_cdn_frontdoor_profile.test.name + resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name +} +`, CdnFrontDoorProfileResource{}.basicWithSystemIdentity(data)) +} + +func (CdnFrontDoorProfileDataSource) basicWithUserIdentity(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cdn_frontdoor_profile" "test" { + name = azurerm_cdn_frontdoor_profile.test.name + resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name +} +`, CdnFrontDoorProfileResource{}.basicWithUserIdentity(data)) +} + +func (CdnFrontDoorProfileDataSource) basicWithSystemAndUserIdentity(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +data "azurerm_cdn_frontdoor_profile" "test" { + name = azurerm_cdn_frontdoor_profile.test.name + resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name +} +`, CdnFrontDoorProfileResource{}.basicWithSystemAndUserIdentity(data)) +} diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource.go b/internal/services/cdn/cdn_frontdoor_profile_resource.go index 3ef61a469c3c..aec70c44d3f6 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" cdn "github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -50,6 +51,8 @@ func resourceCdnFrontDoorProfile() *pluginsdk.Resource { "resource_group_name": commonschema.ResourceGroupName(), + "identity": commonschema.SystemAssignedUserAssignedIdentityOptional(), + "response_timeout_seconds": { Type: pluginsdk.TypeInt, Optional: true, @@ -113,6 +116,15 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface Tags: expandNewFrontDoorTagsPointer(d.Get("tags").(map[string]interface{})), } + if v, ok := d.GetOk("identity"); ok { + i, err := identity.ExpandSystemAndUserAssignedMap(v.([]interface{})) + if err != nil { + return fmt.Errorf("expanding `identity`: %+v", err) + } + + props.Identity = i + } + err = client.CreateThenPoll(ctx, profileId, props) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) @@ -160,6 +172,15 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} return fmt.Errorf("model.Properties is 'nil'") } + identity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity) + if err != nil { + return fmt.Errorf("flattening `identity`: %+v", err) + } + + if err := d.Set("identity", identity); err != nil { + return fmt.Errorf("setting `identity`: %+v", err) + } + d.Set("response_timeout_seconds", int(pointer.From(model.Properties.OriginResponseTimeoutSeconds))) // whilst this is returned in the API as FrontDoorID other resources refer to @@ -202,6 +223,15 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface props.Properties.OriginResponseTimeoutSeconds = pointer.To(int64(d.Get("response_timeout_seconds").(int))) } + if d.HasChange("identity") { + i, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{})) + if err != nil { + return fmt.Errorf("expanding `identity`: %+v", err) + } + + props.Identity = i + } + err = client.UpdateThenPoll(ctx, profileId, props) if err != nil { return fmt.Errorf("updating %s: %+v", *id, err) diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go index fcb479cb00e3..0d36e4bc315c 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go @@ -34,6 +34,48 @@ func TestAccCdnFrontDoorProfile_basic(t *testing.T) { }) } +func TestAccCdnFrontDoorProfileWithSystemIdentity_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") + r := CdnFrontDoorProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicWithSystemIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccCdnFrontDoorProfileWithUserIdentity_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") + r := CdnFrontDoorProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicWithUserIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccCdnFrontDoorProfileWithSystemAndUserIdentity_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") + r := CdnFrontDoorProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basicWithSystemAndUserIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + func TestAccCdnFrontDoorProfile_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") r := CdnFrontDoorProfileResource{} @@ -85,6 +127,97 @@ func TestAccCdnFrontDoorProfile_update(t *testing.T) { }) } +func TestAccCdnFrontDoorProfileWithSystemIdentity_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") + r := CdnFrontDoorProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("240"), + ), + }, + data.ImportStep(), + { + Config: r.updateWithSystemIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("120"), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("240"), + ), + }, + }) +} + +func TestAccCdnFrontDoorProfileWithUserIdentity_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") + r := CdnFrontDoorProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("240"), + ), + }, + data.ImportStep(), + { + Config: r.updateWithUserIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("120"), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("240"), + ), + }, + }) +} + +func TestAccCdnFrontDoorProfileWithSystemAndUserIdentity_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_profile", "test") + r := CdnFrontDoorProfileResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("240"), + ), + }, + data.ImportStep(), + { + Config: r.updateWithSystemAndUserIdentity(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("120"), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("response_timeout_seconds").HasValue("240"), + ), + }, + data.ImportStep(), + }) +} + func (r CdnFrontDoorProfileResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := parse.FrontDoorProfileID(state.ID) if err != nil { @@ -125,6 +258,71 @@ resource "azurerm_cdn_frontdoor_profile" "test" { `, template, data.RandomInteger) } +func (r CdnFrontDoorProfileResource) basicWithSystemIdentity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_cdn_frontdoor_profile" "test" { + name = "acctestprofile-%d" + resource_group_name = azurerm_resource_group.test.name + sku_name = "Standard_AzureFrontDoor" + + identity { + type = "SystemAssigned" + } +} +`, template, data.RandomInteger) +} + +func (r CdnFrontDoorProfileResource) basicWithUserIdentity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_cdn_frontdoor_profile" "test" { + name = "acctestprofile-%d" + resource_group_name = azurerm_resource_group.test.name + sku_name = "Standard_AzureFrontDoor" + + identity { + type = "UserAssigned" + identity_ids = [azurerm_user_assigned_identity.test.id] + } +} +`, template, data.RandomInteger) +} + +func (r CdnFrontDoorProfileResource) basicWithSystemAndUserIdentity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_cdn_frontdoor_profile" "test" { + name = "acctestprofile-%d" + resource_group_name = azurerm_resource_group.test.name + sku_name = "Standard_AzureFrontDoor" + + identity { + type = "SystemAssigned, UserAssigned" + identity_ids = [azurerm_user_assigned_identity.test.id] + } +} +`, template, data.RandomInteger) +} + func (r CdnFrontDoorProfileResource) requiresImport(data acceptance.TestData) string { config := r.basic(data) return fmt.Sprintf(` @@ -183,11 +381,101 @@ resource "azurerm_cdn_frontdoor_profile" "test" { `, template, data.RandomInteger) } +func (r CdnFrontDoorProfileResource) updateWithSystemIdentity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_cdn_frontdoor_profile" "test" { + name = "acctestprofile-%d" + resource_group_name = azurerm_resource_group.test.name + sku_name = "Premium_AzureFrontDoor" + + response_timeout_seconds = 120 + + identity { + type = "SystemAssigned" + } + + tags = { + ENV = "Production" + } +} +`, template, data.RandomInteger) +} + +func (r CdnFrontDoorProfileResource) updateWithUserIdentity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_cdn_frontdoor_profile" "test" { + name = "acctestprofile-%d" + resource_group_name = azurerm_resource_group.test.name + sku_name = "Premium_AzureFrontDoor" + + response_timeout_seconds = 120 + + identity { + type = "UserAssigned" + identity_ids = [azurerm_user_assigned_identity.test.id] + } + + tags = { + ENV = "Production" + } +} +`, template, data.RandomInteger) +} + +func (r CdnFrontDoorProfileResource) updateWithSystemAndUserIdentity(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_cdn_frontdoor_profile" "test" { + name = "acctestprofile-%d" + resource_group_name = azurerm_resource_group.test.name + sku_name = "Premium_AzureFrontDoor" + + response_timeout_seconds = 120 + + identity { + type = "SystemAssigned, UserAssigned" + identity_ids = [azurerm_user_assigned_identity.test.id] + } + + tags = { + ENV = "Production" + } +} +`, template, data.RandomInteger) +} + func (CdnFrontDoorProfileResource) template(data acceptance.TestData) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG-cdn-afdx-%d" location = "%s" } -`, data.RandomInteger, data.Locations.Primary) + +resource "azurerm_user_assigned_identity" "test" { + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + + name = "acctestAFD-%d" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/website/docs/d/cdn_frontdoor_profile.html.markdown b/website/docs/d/cdn_frontdoor_profile.html.markdown index f9b5bb49bd82..653d135ba8c2 100644 --- a/website/docs/d/cdn_frontdoor_profile.html.markdown +++ b/website/docs/d/cdn_frontdoor_profile.html.markdown @@ -27,6 +27,18 @@ The following arguments are supported: * `resource_group_name` - (Required) The name of the Resource Group where this Front Door Profile exists. +* `identity` - (Optional) An `identity` block as defined below. + +--- + +An `identity` block exports the following: + +* `type` - The type of Managed Service Identity that is configured on this Front Door Profile. + +* `identity_ids` - The list of User Assigned Managed Identity IDs assigned to this Front Door Profile. + +--- + ## Attributes Reference The following attributes are exported: diff --git a/website/docs/r/cdn_frontdoor_profile.html.markdown b/website/docs/r/cdn_frontdoor_profile.html.markdown index e7b6835e4b46..38c9776fe370 100644 --- a/website/docs/r/cdn_frontdoor_profile.html.markdown +++ b/website/docs/r/cdn_frontdoor_profile.html.markdown @@ -39,10 +39,22 @@ The following arguments are supported: * `sku_name` - (Required) Specifies the SKU for this Front Door Profile. Possible values include `Standard_AzureFrontDoor` and `Premium_AzureFrontDoor`. Changing this forces a new resource to be created. +* `identity` - (Optional) An `identity` block as defined below. + * `response_timeout_seconds` - (Optional) Specifies the maximum response timeout in seconds. Possible values are between `16` and `240` seconds (inclusive). Defaults to `120` seconds. * `tags` - (Optional) Specifies a mapping of tags to assign to the resource. +--- + +An `identity` block supports the following: + +* `type` - (Required) The type of managed identity to assign. Possible values are `SystemAssigned`, `UserAssigned` or `SystemAssigned, UserAssigned`. + +* `identity_ids` - (Optional) - A list of one or more Resource IDs for User Assigned Managed identities to assign. Required when `type` is set to `UserAssigned` or `SystemAssigned, UserAssigned`. + +--- + ## Attributes Reference In addition to the Arguments listed above - the following Attributes are exported: From e5be1bf66a59110533b805657339311d861013b3 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 20 Nov 2024 12:32:52 -0700 Subject: [PATCH 04/10] Fix sku check in datasource test cases... --- .../services/cdn/cdn_frontdoor_profile_data_source_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go b/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go index 8c106c16a323..15224731c003 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source_test.go @@ -35,7 +35,7 @@ func TestAccCdnFrontDoorProfileDataSource_basicWithSystemIdentity(t *testing.T) { Config: d.basicWithSystemIdentity(data), Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("sku_name").HasValue("Premium_AzureFrontDoor"), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_AzureFrontDoor"), check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned"), ), }, @@ -50,7 +50,7 @@ func TestAccCdnFrontDoorProfileDataSource_basicWithUserIdentity(t *testing.T) { { Config: d.basicWithUserIdentity(data), Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("sku_name").HasValue("Premium_AzureFrontDoor"), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_AzureFrontDoor"), check.That(data.ResourceName).Key("identity.0.type").HasValue("UserAssigned"), ), }, @@ -65,7 +65,7 @@ func TestAccCdnFrontDoorProfileDataSource_basicWithSystemAndUserIdentity(t *test { Config: d.basicWithSystemAndUserIdentity(data), Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).Key("sku_name").HasValue("Premium_AzureFrontDoor"), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_AzureFrontDoor"), check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned, UserAssigned"), ), }, From fe66dc517cb72d39faff082476edf68d5de7960a Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:05:37 -0700 Subject: [PATCH 05/10] Fix failing rule test cases... --- .../services/cdn/cdn_frontdoor_rule_resource_test.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/services/cdn/cdn_frontdoor_rule_resource_test.go b/internal/services/cdn/cdn_frontdoor_rule_resource_test.go index 425f1a75c6b1..5275a133641e 100644 --- a/internal/services/cdn/cdn_frontdoor_rule_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_rule_resource_test.go @@ -994,13 +994,10 @@ resource "azurerm_cdn_frontdoor_rule" "test" { cache_duration = "365.23:59:59" } - url_redirect_action { - redirect_type = "PermanentRedirect" - redirect_protocol = "MatchRequest" - query_string = "clientIp={client_ip}" - destination_path = "/exampleredirection" - destination_hostname = "contoso.com" - destination_fragment = "UrlRedirect" + response_header_action { + header_action = "Appened" + header_name = "Set-Cookie" + value = "sessionId=12345678" } } From c75fbb482046f61fd03ed2fdd721b37f029487af Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:13:46 -0700 Subject: [PATCH 06/10] Fix header_action... --- internal/services/cdn/cdn_frontdoor_rule_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/cdn/cdn_frontdoor_rule_resource_test.go b/internal/services/cdn/cdn_frontdoor_rule_resource_test.go index 5275a133641e..2690c51a6e92 100644 --- a/internal/services/cdn/cdn_frontdoor_rule_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_rule_resource_test.go @@ -995,7 +995,7 @@ resource "azurerm_cdn_frontdoor_rule" "test" { } response_header_action { - header_action = "Appened" + header_action = "Append" header_name = "Set-Cookie" value = "sessionId=12345678" } From c5a1f6f3b6194f0ac61f28b5245f13339888d628 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:42:34 -0700 Subject: [PATCH 07/10] Remove alias from import section for 2024-02-01 API... --- .../cdn/cdn_frontdoor_origin_resource.go | 6 ++--- .../cdn/cdn_frontdoor_profile_data_source.go | 4 +-- .../cdn/cdn_frontdoor_profile_resource.go | 26 +++++++++---------- .../cdn_frontdoor_profile_resource_test.go | 4 +-- .../cdn_frontdoor_security_policy_resource.go | 4 +-- internal/services/cdn/client/client.go | 6 ++--- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/internal/services/cdn/cdn_frontdoor_origin_resource.go b/internal/services/cdn/cdn_frontdoor_origin_resource.go index 592f3420042d..fc11c0383741 100644 --- a/internal/services/cdn/cdn_frontdoor_origin_resource.go +++ b/internal/services/cdn/cdn_frontdoor_origin_resource.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - cdnProfile "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/profiles" "github.com/hashicorp/go-azure-sdk/resource-manager/network/2023-11-01/privatelinkservices" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" @@ -207,7 +207,7 @@ func resourceCdnFrontDoorOriginCreate(d *pluginsdk.ResourceData, meta interface{ // private links are only allowed in the premium sku... profile := parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName) - profileId := cdnProfile.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: profile.SubscriptionId, ResourceGroupName: profile.ResourceGroup, ProfileName: profile.ProfileName, @@ -378,7 +378,7 @@ func resourceCdnFrontDoorOriginUpdate(d *pluginsdk.ResourceData, meta interface{ // private links are only allowed in the premium sku... profile := parse.NewFrontDoorProfileID(id.SubscriptionId, id.ResourceGroup, id.ProfileName) - profileId := cdnProfile.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: profile.SubscriptionId, ResourceGroupName: profile.ResourceGroup, ProfileName: profile.ProfileName, diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source.go b/internal/services/cdn/cdn_frontdoor_profile_data_source.go index 52b8f01321cb..a4a9fa06c334 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" - cdn "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/profiles" "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" @@ -66,7 +66,7 @@ func dataSourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface id := parse.NewFrontDoorProfileID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - profileId := cdn.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: id.SubscriptionId, ResourceGroupName: id.ResourceGroup, ProfileName: id.ProfileName, diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource.go b/internal/services/cdn/cdn_frontdoor_profile_resource.go index aec70c44d3f6..1601753180ab 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource.go @@ -12,7 +12,7 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" - cdn "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/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" @@ -65,8 +65,8 @@ func resourceCdnFrontDoorProfile() *pluginsdk.Resource { Required: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(cdn.SkuNamePremiumAzureFrontDoor), - string(cdn.SkuNameStandardAzureFrontDoor), + string(profiles.SkuNamePremiumAzureFrontDoor), + string(profiles.SkuNameStandardAzureFrontDoor), }, false), }, @@ -88,7 +88,7 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface id := parse.NewFrontDoorProfileID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - profileId := cdn.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: id.SubscriptionId, ResourceGroupName: id.ResourceGroup, ProfileName: id.ProfileName, @@ -105,13 +105,13 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface return tf.ImportAsExistsError("azurerm_cdn_frontdoor_profile", id.ID()) } - props := cdn.Profile{ + props := profiles.Profile{ Location: location.Normalize("global"), - Properties: &cdn.ProfileProperties{ + Properties: &profiles.ProfileProperties{ OriginResponseTimeoutSeconds: pointer.To(int64(d.Get("response_timeout_seconds").(int))), }, - Sku: cdn.Sku{ - Name: pointer.To(cdn.SkuName(d.Get("sku_name").(string))), + Sku: profiles.Sku{ + Name: pointer.To(profiles.SkuName(d.Get("sku_name").(string))), }, Tags: expandNewFrontDoorTagsPointer(d.Get("tags").(map[string]interface{})), } @@ -144,7 +144,7 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} return err } - profileId := cdn.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: id.SubscriptionId, ResourceGroupName: id.ResourceGroup, ProfileName: id.ProfileName, @@ -208,15 +208,15 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface return err } - profileId := cdn.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: id.SubscriptionId, ResourceGroupName: id.ResourceGroup, ProfileName: id.ProfileName, } - props := cdn.ProfileUpdateParameters{ + props := profiles.ProfileUpdateParameters{ Tags: expandNewFrontDoorTagsPointer(d.Get("tags").(map[string]interface{})), - Properties: &cdn.ProfilePropertiesUpdateParameters{}, + Properties: &profiles.ProfilePropertiesUpdateParameters{}, } if d.HasChange("response_timeout_seconds") { @@ -250,7 +250,7 @@ func resourceCdnFrontDoorProfileDelete(d *pluginsdk.ResourceData, meta interface return err } - profileId := cdn.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: id.SubscriptionId, ResourceGroupName: id.ResourceGroup, ProfileName: id.ProfileName, diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go index 0d36e4bc315c..bd8692316b2f 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/hashicorp/go-azure-helpers/lang/response" - cdn "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/profiles" "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" @@ -224,7 +224,7 @@ func (r CdnFrontDoorProfileResource) Exists(ctx context.Context, clients *client return nil, err } - profileId := cdn.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: id.SubscriptionId, ResourceGroupName: id.ResourceGroup, ProfileName: id.ProfileName, diff --git a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go index 8cfb2fba4def..d17e364857ee 100644 --- a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go +++ b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go @@ -10,7 +10,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck "github.com/hashicorp/go-azure-helpers/lang/pointer" - cdnProfile "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/profiles" "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" @@ -150,7 +150,7 @@ func resourceCdnFrontdoorSecurityPolicyCreate(d *pluginsdk.ResourceData, meta in return err } - profileId := cdnProfile.ProfileId{ + profileId := profiles.ProfileId{ SubscriptionId: profile.SubscriptionId, ResourceGroupName: profile.ResourceGroup, ProfileName: profile.ProfileName, diff --git a/internal/services/cdn/client/client.go b/internal/services/cdn/client/client.go index 86d69d31ee27..2ec0cde07464 100644 --- a/internal/services/cdn/client/client.go +++ b/internal/services/cdn/client/client.go @@ -9,7 +9,7 @@ import ( cdnSdk "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2020-09-01/cdn" // nolint: staticcheck 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 - cdnProfile "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/profiles" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -21,7 +21,7 @@ type Client struct { FrontDoorSecurityPoliciesClient *cdnFrontDoorSdk.SecurityPoliciesClient FrontDoorRoutesClient *cdnFrontDoorSdk.RoutesClient FrontDoorRulesClient *cdnFrontDoorSdk.RulesClient - FrontDoorProfileClient *cdnProfile.ProfilesClient + FrontDoorProfileClient *profiles.ProfilesClient FrontDoorSecretsClient *cdnFrontDoorSdk.SecretsClient FrontDoorRuleSetsClient *cdnFrontDoorSdk.RuleSetsClient FrontDoorLegacyFirewallPoliciesClient *frontdoor.PoliciesClient @@ -31,7 +31,7 @@ type Client struct { } func NewClient(o *common.ClientOptions) (*Client, error) { - frontDoorProfilesClient, err := cdnProfile.NewProfilesClientWithBaseURI(o.Environment.ResourceManager) + frontDoorProfilesClient, err := profiles.NewProfilesClientWithBaseURI(o.Environment.ResourceManager) if err != nil { return nil, fmt.Errorf("building ProfilesClient: %+v", err) } From a21e62abf759c38c4ed9f8e02cb5ae3d92cdaa77 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:51:50 -0700 Subject: [PATCH 08/10] Fix name of new API client... --- internal/services/cdn/cdn_frontdoor_origin_resource.go | 4 ++-- .../services/cdn/cdn_frontdoor_profile_data_source.go | 2 +- internal/services/cdn/cdn_frontdoor_profile_resource.go | 8 ++++---- .../services/cdn/cdn_frontdoor_profile_resource_test.go | 2 +- .../cdn/cdn_frontdoor_security_policy_resource.go | 2 +- internal/services/cdn/client/client.go | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/services/cdn/cdn_frontdoor_origin_resource.go b/internal/services/cdn/cdn_frontdoor_origin_resource.go index fc11c0383741..9a1f6f89055e 100644 --- a/internal/services/cdn/cdn_frontdoor_origin_resource.go +++ b/internal/services/cdn/cdn_frontdoor_origin_resource.go @@ -180,7 +180,7 @@ func resourceCdnFrontDoorOrigin() *pluginsdk.Resource { func resourceCdnFrontDoorOriginCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Cdn.FrontDoorOriginsClient - profileClient := meta.(*clients.Client).Cdn.FrontDoorProfileClient + profileClient := meta.(*clients.Client).Cdn.FrontDoorProfilesClient ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -329,7 +329,7 @@ func resourceCdnFrontDoorOriginRead(d *pluginsdk.ResourceData, meta interface{}) func resourceCdnFrontDoorOriginUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Cdn.FrontDoorOriginsClient workaroundClient := azuresdkhacks.NewCdnFrontDoorOriginsWorkaroundClient(client) - profileClient := meta.(*clients.Client).Cdn.FrontDoorProfileClient + profileClient := meta.(*clients.Client).Cdn.FrontDoorProfilesClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/internal/services/cdn/cdn_frontdoor_profile_data_source.go b/internal/services/cdn/cdn_frontdoor_profile_data_source.go index a4a9fa06c334..8bb055e767e5 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_data_source.go +++ b/internal/services/cdn/cdn_frontdoor_profile_data_source.go @@ -59,7 +59,7 @@ func dataSourceCdnFrontDoorProfile() *pluginsdk.Resource { } func dataSourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cdn.FrontDoorProfileClient + client := meta.(*clients.Client).Cdn.FrontDoorProfilesClient subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource.go b/internal/services/cdn/cdn_frontdoor_profile_resource.go index 1601753180ab..0d130adc2636 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource.go @@ -81,7 +81,7 @@ func resourceCdnFrontDoorProfile() *pluginsdk.Resource { } func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cdn.FrontDoorProfileClient + client := meta.(*clients.Client).Cdn.FrontDoorProfilesClient subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -135,7 +135,7 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface } func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cdn.FrontDoorProfileClient + client := meta.(*clients.Client).Cdn.FrontDoorProfilesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() @@ -199,7 +199,7 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{} } func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cdn.FrontDoorProfileClient + client := meta.(*clients.Client).Cdn.FrontDoorProfilesClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() @@ -241,7 +241,7 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface } func resourceCdnFrontDoorProfileDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cdn.FrontDoorProfileClient + client := meta.(*clients.Client).Cdn.FrontDoorProfilesClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() diff --git a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go index bd8692316b2f..9a6462f7c514 100644 --- a/internal/services/cdn/cdn_frontdoor_profile_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_profile_resource_test.go @@ -230,7 +230,7 @@ func (r CdnFrontDoorProfileResource) Exists(ctx context.Context, clients *client ProfileName: id.ProfileName, } - client := clients.Cdn.FrontDoorProfileClient + client := clients.Cdn.FrontDoorProfilesClient resp, err := client.Get(ctx, profileId) if err != nil { if response.WasNotFound(resp.HttpResponse) { diff --git a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go index d17e364857ee..5f8103e1582e 100644 --- a/internal/services/cdn/cdn_frontdoor_security_policy_resource.go +++ b/internal/services/cdn/cdn_frontdoor_security_policy_resource.go @@ -170,7 +170,7 @@ func resourceCdnFrontdoorSecurityPolicyCreate(d *pluginsdk.ResourceData, meta in return tf.ImportAsExistsError("azurerm_cdn_frontdoor_security_policy", id.ID()) } - profileClient := meta.(*clients.Client).Cdn.FrontDoorProfileClient + profileClient := meta.(*clients.Client).Cdn.FrontDoorProfilesClient resp, err := profileClient.Get(ctx, profileId) if err != nil { return fmt.Errorf("unable to retrieve the 'sku_name' from the CDN FrontDoor Profile(Name: %q)': %+v", profile.ProfileName, err) diff --git a/internal/services/cdn/client/client.go b/internal/services/cdn/client/client.go index 2ec0cde07464..fb8823fe4c82 100644 --- a/internal/services/cdn/client/client.go +++ b/internal/services/cdn/client/client.go @@ -21,7 +21,7 @@ type Client struct { FrontDoorSecurityPoliciesClient *cdnFrontDoorSdk.SecurityPoliciesClient FrontDoorRoutesClient *cdnFrontDoorSdk.RoutesClient FrontDoorRulesClient *cdnFrontDoorSdk.RulesClient - FrontDoorProfileClient *profiles.ProfilesClient + FrontDoorProfilesClient *profiles.ProfilesClient FrontDoorSecretsClient *cdnFrontDoorSdk.SecretsClient FrontDoorRuleSetsClient *cdnFrontDoorSdk.RuleSetsClient FrontDoorLegacyFirewallPoliciesClient *frontdoor.PoliciesClient @@ -84,7 +84,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { FrontDoorSecurityPoliciesClient: &frontDoorPolicySecurityPoliciesClient, FrontDoorRoutesClient: &frontDoorRoutesClient, FrontDoorRulesClient: &frontDoorRulesClient, - FrontDoorProfileClient: frontDoorProfilesClient, + FrontDoorProfilesClient: frontDoorProfilesClient, FrontDoorSecretsClient: &frontDoorPolicySecretsClient, FrontDoorRuleSetsClient: &frontDoorRuleSetsClient, FrontDoorLegacyFirewallPoliciesClient: &frontDoorLegacyFirewallPoliciesClient, 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 09/10] 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 From fef79d81aaf22f2d420a4ff7311f9983ca511c33 Mon Sep 17 00:00:00 2001 From: Jeffrey Cline <20408400+WodansSon@users.noreply.github.com> Date: Thu, 5 Dec 2024 01:55:52 -0700 Subject: [PATCH 10/10] Fix lint error... --- .../cdn/cdn_frontdoor_security_policy_resource_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 613d7ece54b2..722ed3b9c64a 100644 --- a/internal/services/cdn/cdn_frontdoor_security_policy_resource_test.go +++ b/internal/services/cdn/cdn_frontdoor_security_policy_resource_test.go @@ -8,9 +8,9 @@ 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/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" @@ -116,7 +116,7 @@ func (r CdnFrontDoorSecurityPolicyResource) Exists(ctx context.Context, clients 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