Skip to content

Commit

Permalink
Merge pull request #67 from akhilmhdh/feat/project-role-fix
Browse files Browse the repository at this point in the history
feat: fixed permission upgrade breaking change in tf
  • Loading branch information
maidul98 authored Oct 30, 2024
2 parents 28756d6 + 3b23230 commit 52b34be
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions internal/provider/resource/project_role_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,26 @@ func (r *projectRoleResource) Read(ctx context.Context, req resource.ReadRequest
for _, el := range projectRole.Role.Permissions {
action, isValid := el["action"].(string)
if el["action"] != nil && !isValid {
action, isValid = el["action"].([]any)[0].(string)
actions, isValid := el["action"].([]any)
if !isValid {
resp.Diagnostics.AddError(
"Error reading project role",
"Couldn't read project role from Infiscial, invalid action field in permission",
)
return
}

if len(actions) > 1 {
resp.Diagnostics.AddWarning(
"Drift detected",
"Multiple actions are not supported on 'infisical_project_role', use 'infisical_project_role_v2'.",
)
state.Permissions = nil
resp.State.Set(ctx, state)
return
}

action, isValid = actions[0].(string)
if !isValid {
resp.Diagnostics.AddError(
"Error reading project role",
Expand All @@ -274,6 +293,7 @@ func (r *projectRoleResource) Read(ctx context.Context, req resource.ReadRequest
return
}
}

var secretPath, environment string
if el["conditions"] != nil {
conditions, isValid := el["conditions"].(map[string]any)
Expand All @@ -287,21 +307,30 @@ func (r *projectRoleResource) Read(ctx context.Context, req resource.ReadRequest

environment, isValid = conditions["environment"].(string)
if !isValid {
resp.Diagnostics.AddError(
"Error reading project role",
"Couldn't read project role from Infiscial, invalid environment field in permission",
)
return
if permissionV2Environment, isValid := conditions["environment"].(map[string]any); isValid {
environment, isValid = permissionV2Environment["$eq"].(string)
if !isValid {
resp.Diagnostics.AddWarning(
"Drift detected",
"Environment condition provided are not compatible on 'infisical_project_role', use 'infisical_project_role_v2'.",
)
state.Permissions = nil
resp.State.Set(ctx, state)
return
}
}
}

// secret path parsing.
if val, isValid := conditions["secretPath"].(map[string]any); isValid {
secretPath, isValid = val["$glob"].(string)
if !isValid {
resp.Diagnostics.AddError(
"Error reading project role",
"Couldn't read project role from Infiscial, invalid secret path field in permission",
resp.Diagnostics.AddWarning(
"Drift detected",
"Secret path condition provided are not compatible on 'infisical_project_role', use 'infisical_project_role_v2'.",
)
state.Permissions = nil
resp.State.Set(ctx, state)
return
}
}
Expand Down

0 comments on commit 52b34be

Please sign in to comment.