Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/connector/exportable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type ExportableResource interface {
func (b *ImportBlock) Sanitize() {
// Replace spaces with underscores
b.ResourceName = strings.ReplaceAll(b.ResourceName, " ", "_")
// Replace dashes with underscores
b.ResourceName = strings.ReplaceAll(b.ResourceName, "-", "_")
// Remove all non-Alphanumeric characters/non-underscores
b.ResourceName = regexp.MustCompile(`[^a-zA-Z0-9_]+`).ReplaceAllString(b.ResourceName, "")
// Make everything lowercase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,26 @@ func (r *PingOneGatewayRoleAssignmentResource) ExportAll() (*[]connector.ImportB
if roleAssignmentIdOk && roleAssignmentRoleOk {
roleAssignmentRoleId, roleAssignmentRoleIdOk := roleAssignmentRole.GetIdOk()
if roleAssignmentRoleIdOk {
apiRole, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, *roleAssignmentRoleId).Execute()
role, resp, err := r.clientInfo.ApiClient.ManagementAPIClient.RolesApi.ReadOneRole(r.clientInfo.Context, *roleAssignmentRoleId).Execute()
err = common.HandleClientResponse(resp, err, "ReadOneRole", r.ResourceType())
if err != nil {
return nil, err
}
if apiRole != nil {
apiRoleName, apiRoleNameOk := apiRole.GetNameOk()
if apiRoleNameOk {
if role != nil {
roleName, roleNameOk := role.GetNameOk()
if roleNameOk {
commentData := map[string]string{
"Resource Type": r.ResourceType(),
"Gateway Name": *gatewayName,
"Role Name": string(*apiRoleName),
"Role Name": string(*roleName),
"Export Environment ID": r.clientInfo.ExportEnvironmentID,
"Gateway ID": *gatewayId,
"Role Assignment ID": *roleAssignmentId,
}

importBlocks = append(importBlocks, connector.ImportBlock{
ResourceType: r.ResourceType(),
ResourceName: fmt.Sprintf("%s_%s", *gatewayName, *apiRoleName),
ResourceName: fmt.Sprintf("%s_%s_%s", *gatewayName, *roleName, *roleAssignmentId),
ResourceID: fmt.Sprintf("%s/%s/%s", r.clientInfo.ExportEnvironmentID, *gatewayId, *roleAssignmentId),
CommentInformation: common.GenerateCommentInformation(commentData),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ func TestGatewayRoleAssignmentExport(t *testing.T) {
expectedImportBlocks := []connector.ImportBlock{
{
ResourceType: "pingone_gateway_role_assignment",
ResourceName: "PF TF Provider_Identity Data Admin",
ResourceName: "PF TF Provider_Identity Data Admin_1c5549f9-95f5-4380-b975-d0165aadd9d2",
ResourceID: fmt.Sprintf("%s/554257ac-76ca-447a-a210-722343328312/1c5549f9-95f5-4380-b975-d0165aadd9d2", testutils.GetEnvironmentID()),
},
{
ResourceType: "pingone_gateway_role_assignment",
ResourceName: "PF TF Provider_Environment Admin",
ResourceName: "PF TF Provider_Environment Admin_1cf8fca5-f14f-4a64-a521-60efc7891e7e",
ResourceID: fmt.Sprintf("%s/554257ac-76ca-447a-a210-722343328312/1cf8fca5-f14f-4a64-a521-60efc7891e7e", testutils.GetEnvironmentID()),
},
{
ResourceType: "pingone_gateway_role_assignment",
ResourceName: "Local Test_Identity Data Admin",
ResourceName: "Local Test_Identity Data Admin_e424fff4-a8ca-4a75-a169-3376dd2aad96",
ResourceID: fmt.Sprintf("%s/5cd3f6b7-35f0-4873-ac64-f32118bf3102/e424fff4-a8ca-4a75-a169-3376dd2aad96", testutils.GetEnvironmentID()),
},
{
ResourceType: "pingone_gateway_role_assignment",
ResourceName: "Local Test_Environment Admin",
ResourceName: "Local Test_Environment Admin_393d4c4e-6642-432d-bc11-1638948d6dd2",
ResourceID: fmt.Sprintf("%s/5cd3f6b7-35f0-4873-ac64-f32118bf3102/393d4c4e-6642-432d-bc11-1638948d6dd2", testutils.GetEnvironmentID()),
},
{
ResourceType: "pingone_gateway_role_assignment",
ResourceName: "another connection for testing_Identity Data Admin",
ResourceName: "another connection for testing_Identity Data Admin_239579d0-fc0b-4b50-ba03-dfe80e2bb6d0",
ResourceID: fmt.Sprintf("%s/8773b833-ade0-4883-9cad-05fe82b23135/239579d0-fc0b-4b50-ba03-dfe80e2bb6d0", testutils.GetEnvironmentID()),
},
{
ResourceType: "pingone_gateway_role_assignment",
ResourceName: "another connection for testing_Environment Admin",
ResourceName: "another connection for testing_Environment Admin_07ed5801-4d44-4578-9d2f-c6ef6d537e83",
ResourceID: fmt.Sprintf("%s/8773b833-ade0-4883-9cad-05fe82b23135/07ed5801-4d44-4578-9d2f-c6ef6d537e83", testutils.GetEnvironmentID()),
},
}
Expand Down