Skip to content

Commit

Permalink
update the migrated azapi_resource label
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Oct 10, 2024
1 parent 655ac88 commit 0e93aad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions types/azurerm_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"fmt"
"log"
"math/rand"
"net/url"
"strconv"
"strings"
Expand Down Expand Up @@ -210,11 +209,11 @@ func (r *AzurermResource) IsForEach() bool {

var pluralizeClient = pluralize.NewClient()

func NewLabel(id string) string {
func NewLabel(id string, oldLabel string) string {
resourceType := ResourceTypeOfResourceId(id)
lastSegment := LastSegment(resourceType)
// #nosec G404
return fmt.Sprintf("%s_%d", pluralizeClient.Singular(lastSegment), rand.Intn(100))
return fmt.Sprintf("%s_%s", pluralizeClient.Singular(lastSegment), oldLabel)
}

func LastSegment(input string) string {
Expand Down
2 changes: 1 addition & 1 deletion types/from_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ListResourcesFromPlan(p *tfjson.Plan) []AzureResource {
OldResourceType: resourceChange.Type,
OldLabel: resourceChange.Name,
NewResourceType: "azapi_resource",
NewLabel: NewLabel(id),
NewLabel: NewLabel(id, resourceChange.Name),
Instances: make([]Instance, 0),
}
}
Expand Down

0 comments on commit 0e93aad

Please sign in to comment.