Skip to content

Commit

Permalink
First pass at deprecating legacy 2021-06-01 API from touched resource…
Browse files Browse the repository at this point in the history
…s...
  • Loading branch information
WodansSon committed Dec 5, 2024
1 parent a21e62a commit d7673cd
Show file tree
Hide file tree
Showing 27 changed files with 1,403 additions and 234 deletions.
47 changes: 11 additions & 36 deletions internal/services/cdn/cdn_frontdoor_profile_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}),

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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("")
Expand All @@ -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

Expand Down Expand Up @@ -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{},
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
Loading

0 comments on commit d7673cd

Please sign in to comment.