Skip to content

Commit

Permalink
fix: restrict to roles
Browse files Browse the repository at this point in the history
  • Loading branch information
lechnerc77 committed Nov 29, 2024
1 parent ee872fa commit df42d01
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
8 changes: 6 additions & 2 deletions pkg/output/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ package output
import "strings"

func FormatResourceNameGeneric(name string) string {
nameNoSpaces := strings.ToLower(strings.Replace(name, " ", "_", -1))
return strings.Replace(nameNoSpaces, ".", "_", -1)
return strings.ToLower(strings.Replace(name, " ", "_", -1))
}

func FormatRoleResourceName(name string) string {
nameGeneric := FormatResourceNameGeneric(name)
return strings.Replace(nameGeneric, ".", "_", -1)
}

func FormatDirEntitlementResourceName(appName string, planName string) string {
Expand Down
8 changes: 4 additions & 4 deletions pkg/output/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ func TestFormatResourceNameGeneric(t *testing.T) {
}
}

func TestFormatResourceNameGenericWithDots(t *testing.T) {
func TestFormatResourceNameRoleWithDots(t *testing.T) {

input := "ApiManagement.SelfService.Administrator"
expected := "apimanagement_selfservice_administrator"

result := FormatResourceNameGeneric(input)
result := FormatRoleResourceName(input)

if result != expected {
t.Errorf("got %q, wanted %q", result, expected)
}
}

func TestFormatResourceNameGenericMisc(t *testing.T) {
func TestFormatResourceNameRoleMisc(t *testing.T) {

input := "SomeResource withSpaces.AndDots"
expected := "someresource_withspaces_anddots"

result := FormatResourceNameGeneric(input)
result := FormatRoleResourceName(input)

if result != expected {
t.Errorf("got %q, wanted %q", result, expected)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tfimportprovider/directoryRoleImportProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func createDirectoryRoleImportBlock(data map[string]interface{}, directoryId str

for x, value := range roles {
role := value.(map[string]interface{})
resourceName := output.FormatResourceNameGeneric(fmt.Sprintf("%v", role["name"]))
resourceName := output.FormatRoleResourceName(fmt.Sprintf("%v", role["name"]))
directoryAllRoles = append(directoryAllRoles, resourceName)
if slices.Contains(filterValues, resourceName) {
importBlock += templateDirectoryRoleImport(x, role, directoryId, resourceDoc)
Expand Down
2 changes: 1 addition & 1 deletion pkg/tfimportprovider/subaccountRoleImportProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func createRoleImportBlock(data map[string]interface{}, subaccountId string, fil

for x, value := range roles {
role := value.(map[string]interface{})
resourceName := output.FormatResourceNameGeneric(fmt.Sprintf("%v", role["name"]))
resourceName := output.FormatRoleResourceName(fmt.Sprintf("%v", role["name"]))
subaccountAllRoles = append(subaccountAllRoles, resourceName)
if slices.Contains(filterValues, resourceName) {
importBlock += templateRoleImport(x, role, subaccountId, resourceDoc)
Expand Down

0 comments on commit df42d01

Please sign in to comment.